ASP.NET Core MVC / Razor Pages UI: JavaScript Logging API
vcp.log
API is used to write simple logs in the client side.
The logs are written to console, using the
console.log
, by default.
This document is for simple client side logging. See the Logging document for server side logging system.
Basic Usage
Use one of the vcp.log.xxx(...)
methods based on the severity of your log message.
vcp.log.debug("Some debug log here..."); //Logging a simple debug message
vcp.log.info({ name: "john", age: 42 }); //Logging an object as an information log
vcp.log.warn("A warning message"); //Logging a warning message
vcp.log.error('An error happens...'); //Error message
vcp.log.fatal('Network connection has gone away!'); //Fatal error
Log Levels
There are 5 levels for a log message:
- DEBUG = 1
- INFO = 2
- WARN = 3
- ERROR = 4
- FATAL = 5
These are defined in the vcp.log.levels
object (like vcp.log.levels.WARN
).
Changing the Current Log Level
You can control the log level as shown below:
vcp.log.level = vcp.log.levels.WARN;
Default log level is DEBUG
.
Logging with Specifying the Level
Instead of calling vcp.log.info(...)
function, you can use the vcp.log.log
by specifying the log level as a parameter:
vcp.log.log("log message...", vcp.log.levels.INFO);