cycle-logger
Provides logging capabilities to cycle.js applications.
Installation
npm i cycle-logger2 --save
Scripts
NOTE: Make sure you've installed all dependencies using npm install
first.
To generate documentation: npm run doc
. This will create documentation in the
build/docs
folder.
To run unit tests: npm test
API
Loggers
Create new Logger instances or filter logging events by Logger name or logging level.
Kind: global class
- Loggers
- static
- .Levels :
enum
- .get(name) ⇒
Logger
- .asObservable() ⇒
LoggerObservable
- .Levels :
- inner
- ~Levels :
Object
- ~Levels :
- static
enum
Loggers.Levels : An enumeration of logging levels that users can subscribe to. In order: ALL < TRACE < DEBUG < INFO < WARN < ERROR < NONE
Kind: static enum property of Loggers
Example
logger;logger;
Logger
Loggers.get(name) ⇒ Retrieves the specified Logger instance, creating one if necessary.
Kind: static method of Loggers
Returns: Logger
- The Logger instance with the specified name.
Throws:
Error
A name must be specified.
Param | Type | Description |
---|---|---|
name | String |
The name of the Logger instance to create/retrieve. |
Example
Loggers;
LoggerObservable
Loggers.asObservable() ⇒ Returns a LoggerObservable instance that can be filtered by Logger name or built-in log level.
Kind: static method of Loggers
Example
Loggers ;
Object
Loggers~Levels : The available logging levels. In order: ALL < TRACE < DEBUG < INFO < WARN < ERROR < NONE
Kind: inner typedef of Loggers
Properties
Name | Type | Description |
---|---|---|
ALL | String |
|
TRACE | String |
Extremely detailed information, like object dumps. |
DEBUG | String |
Detailed information on your program's execution flow. |
INFO | String |
Interesting lifecycle events. |
WARN | String |
Use of deprecated APIs, 'almost' errors, and other undesirable or unexpected events. |
ERROR | String |
Runtime errors and unexpected conditions. |
NONE | String |
Logger
Provides methods to log information at various levels.
Kind: global class
String
logger.name : The unique name of the Logger instance.
Kind: instance property of Logger
Read only: true
Logger
logger.trace(msg, args) ⇒ Outputs trace information to any registered listeners.
Kind: instance method of Logger
Returns: Logger
- The Logger instance, for chaining.
Param | Type | Description |
---|---|---|
msg | String |
The message string or object to log. |
args | * |
The arguments to substitute into the message string. See node's util.format method for more information on formatting. |
Logger
logger.debug(msg, args) ⇒ Outputs debug information to any registered listeners.
Kind: instance method of Logger
Returns: Logger
- The Logger instance, for chaining.
Param | Type | Description |
---|---|---|
msg | String |
The message string or object to log. |
args | * |
The arguments to substitute into the message string. See node's util.format method for more information on formatting. |
Logger
logger.info(msg, args) ⇒ Outputs non-error information to any registered listeners.
Kind: instance method of Logger
Returns: Logger
- The Logger instance, for chaining.
Param | Type | Description |
---|---|---|
msg | String |
The message string or object to log. |
args | * |
The arguments to substitute into the message string. See node's util.format method for more information on formatting. |
Logger
logger.warn(msg, args) ⇒ Outputs warnings to any registered listeners.
Kind: instance method of Logger
Returns: Logger
- The Logger instance, for chaining.
Param | Type | Description |
---|---|---|
msg | String |
The message string or object to log. |
args | * |
The arguments to substitute into the message string. See node's util.format method for more information on formatting. |
Logger
logger.error(msg, args) ⇒ Outputs error information to any registered listeners.
Kind: instance method of Logger
Returns: Logger
- The Logger instance, for chaining.
Param | Type | Description |
---|---|---|
msg | String |
The message string or object to log. |
args | * |
The arguments to substitute into the message string. See node's util.format method for more information on formatting. |
LoggerObservable
Kind: global class
Inherits: Observable
new LoggerObservable()
Provides operators for filtering logging events.
Example
Loggers ;
Observable.<LoggingEvent>
LoggerObservable.byName(name) ⇒ Kind: static method of LoggerObservable
Param | Type | Description |
---|---|---|
name | String | RegExp |
The string or regular expression to use to match against Logger names in LoggingEvents. |
Example
Loggers ;
Observable.<LoggingEvent>
LoggerObservable.byMinLevel(level) ⇒ Kind: static method of LoggerObservable
Throws:
- The specified level is invalid.
Param | Type | Description |
---|---|---|
level | Levels |
The minimum level to filter LoggingEvents. Any events at or above this level will be included in the resulting observable. |
Example
Loggers ;
Observable.<LoggingEvent>
LoggerObservable.byLevels(levels) ⇒ Kind: static method of LoggerObservable
Throws:
- The specified level is invalid.
Param | Type | Description |
---|---|---|
levels | Array.<Levels> |
One or more levels to filter LoggingEvents by. |
Example
Loggers ;
LoggingEvent
Represents a single logged entry.
Kind: global class
Levels
loggingEvent.level : The level the event was logged at.
Kind: instance property of LoggingEvent
String
loggingEvent.logger : The name of the Logger instance that recorded this event.
Kind: instance property of LoggingEvent
String
loggingEvent.message : The message logged.
Kind: instance property of LoggingEvent
Number
loggingEvent.datetime : The epoch time (number of milliseconds since 1/1/1970 UTC).
Kind: instance property of LoggingEvent
String
loggingEvent.toString([fmt]) ⇒ Converts the LoggingEvent instance to a formatted string. You can provide
Kind: instance method of LoggingEvent
Returns: String
- A formatted string.
Param | Type | Default | Description |
---|---|---|---|
[fmt] | String |
'%datetime% %level [%logger%]: %message%' |
The string containing the tokens you wish to replace with the instance values. |
Example
// using built-in formatting:Loggers ;
Example
// using custom formatting:let format = '[%datetime] %level%: %message%';Loggers ;