module:logger
- Description:
Logging utility Default level is
logbut it can be set via env variables even without app initialzation- BKJS_LOG_LEVEL - set to any string/number level
- BKJS_LOG_FILTER - enable debug filters
Properties:
| Name | Type | Description |
|---|---|---|
level |
int | current logging level |
levels |
object | levels sorted by priorities: ERROR, WARN, LOG, INFO, DEBUG, DEV |
filters |
object | debugging filters enabled |
Example
logger.setLevel("info")
logger.log("log") // visible
logger.info("info") // visible
logger.debug("debug") // not visible
logger.error("error") // visible
logger.setLevel("debug")
logger.debug("debug") // visible
logger.setLevel("info")
logger.setDebugFilter("custom")
logger.debug("debug") // still not visible
logger.debug("custom") // visible
Methods
(static) debug(…args)
- Description:
Log with DEBUG level, enabled debug filter will be logged if matched
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
(static) dev(…args)
- Description:
Log with DEV level
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
(static) error(…args)
- Description:
Log with ERROR level
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
(static) info(…args)
- Description:
Log with INFO level
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
(static) log(…args)
- Description:
Log with LOG level
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
(static) logger(level, …args)
- Description:
A generic logger method, safe, first arg is supposed to be a logging level, if not valid the error level is used
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
level |
string | logging level, can be one of the default levels or custom one registered with {registerLevel} |
|
args |
any |
<repeatable> |
arguments to log |
(static) none(…args)
- Description:
Log with NONE level, no-op
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |
(static) prefix(level)
- Description:
Build message prefix, depends on the options: date(1), pid(process.pid), tag(""), can be set via setOptions, by default
- date is $BKJS_LOG_DATE or datetime or iso or utc or none
- pid is $BKJS_LOG_PID or current process pid
- tag is $BKJS_LOG_TAG
- role is $BKJS_LOG_ROLE
Parameters:
| Name | Type | Description |
|---|---|---|
level |
string |
(static) registerLevel(level, callback, optionsopt)
- Description:
Register a custom level handler, must be invoked via
logger.loggeronly, if no handler registered for given level the whole message will be logger as an error. The custom hadnler is called in the context of the module which means the options are available inside the handler.
Parameters:
| Name | Type | Attributes | Description | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
level |
string | custom log level |
|||||||||
callback |
function | call it for this level |
|||||||||
options |
Object |
<optional> |
Properties
|
(static) setDebugFilter(label, {function)
- Description:
Enable debugging level for this label, if used with the same debugging level it will be printed regardless of the global level, a label is first argument to the
logger.debugmethods, it is used as is, usually the fist argument is the current function name with comma, likelogger.debug("select:", name, args)
Parameters:
| Name | Type | Description |
|---|---|---|
label |
string | label(s) to debug, can be a comma separated list |
{function |
handler - can be a function to be used instead of regular logging, this is for rerouting some output to a custom console or for
dumping the actual Javascript data without preformatting, most useful to use |
(static) setFile(file)
- Description:
Redirect logging into a file
Parameters:
| Name | Type | Description |
|---|---|---|
file |
string |
(static) setLevel(level)
- Description:
Set the output level, it can be a number or one of the supported level names, on invalid level then
WARNis set
Parameters:
| Name | Type | Description |
|---|---|---|
level |
stream |
(static) setOptions(options)
- Description:
Special options for logger to override defaults, syslog options must start with
syslog-For tag, date, pid values may refer to other env variables if start with $, like BKJS_LOG_TAG='$BKJS_TAG'
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
Properties
|
(static) setSyslog(facility)
- Description:
Enable or close syslog mode
Parameters:
| Name | Type | Description |
|---|---|---|
facility |
int | string | syslog facility as a number or remote syslog server: |
Example
unix://
udp://host?tag=app
tcp://host:514?facility=LOG_LOCAL0
(static) trace()
- Description:
Print stack backtrace as error
(static) warn(…args)
- Description:
Log with WARN level
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
args |
any |
<repeatable> |