- LoggerFactory
- Logger
- LEVELS
- NullHandler
- MultiHandler
- BaseHandler
- ConsoleHandler
- RawConsoleHandler
- StreamHandler
Handler logger and its settings manipulation.
Default factory returned when you call require("huzzah")
.
Parameters
opts
{handlerConstructor: function}? Options (optional, default{handlerConstructor:MultiHandler}
)
Returns logger with given name
Parameters
name
string Name of logger
Returns Logger
Returns settings for logger with given name
Parameters
name
string logger name
Returns Handler
Meta
- deprecated: This is deprecated.
Returns hander for logger with given name
Parameters
name
string logger name
Returns Handler
Produce log records. It could not be created manually, always use LoggerFactory instance to create loggers.
Parameters
onLogCallback
function factory, holding this loggername
string name of this loggercontext
Object Set of keys, which will be auto-added to each record
Creates new Logger with the same name, factory but with given context. Every property and value of context will be added to log record. This can be usefull for json logging
Parameters
context
Object
Returns Logger new logger with given context
Create log record with level TRACE. If first argument is string, it is used as message format, like console.log do. Supported modifiers %s, %d, %j, %%. If you want to output error, it must be one among all arguments and be last.
Parameters
args
...any Any arguments. Error must be one and last.
Examples
logger.trace('User entered %s', userInput);
logger.error('Error happen while sending email', err);
Create log record with level DEBUG. If first argument is string, it is used as message format, like console.log do. Supported modifiers %s, %d, %j, %%. If you want to output error, it must be one among all arguments and be last.
Parameters
args
...any Any arguments. Error must be one and last.
Examples
logger.trace('User entered %s', userInput);
logger.error('Error happen while sending email', err);
Create log record with level INFO. If first argument is string, it is used as message format, like console.log do. Supported modifiers %s, %d, %j, %%. If you want to output error, it must be one among all arguments and be last.
Parameters
args
...any Any arguments. Error must be one and last.
Examples
logger.trace('User entered %s', userInput);
logger.error('Error happen while sending email', err);
Create log record with level WARN. If first argument is string, it is used as message format, like console.log do. Supported modifiers %s, %d, %j, %%. If you want to output error, it must be one among all arguments and be last.
Parameters
args
...any Any arguments. Error must be one and last.
Examples
logger.trace('User entered %s', userInput);
logger.error('Error happen while sending email', err);
Create log record with level ERROR. If first argument is string, it is used as message format, like console.log do. Supported modifiers %s, %d, %j, %%. If you want to output error, it must be one among all arguments and be last.
Parameters
args
...any Any arguments. Error must be one and last.
Examples
logger.trace('User entered %s', userInput);
logger.error('Error happen while sending email', err);
Log levels. Log levels have a priority. ALL < TRACE < DEBUG < INFO < WARN < ERROR < OFF
Basic handler. Does not actually handle anything. Usefull for extensions and stubs. All implementors must implement _handle(record) method. record instance shared among all handlers, do not modify it.
Set max accepted log level for this handler
Parameters
level
string
Returns this
Extends NullHandler
Holds settings of one logger. It is max accepted log level and handlers
Adds handler to logger
Parameters
handler
NullHandler instance
Returns this
Extends NullHandler
Used as base class for most handlers
All extensions should implement method _handle(record)
Set log record format for this handler.
Default record format is [%date] %-5level %logger - %message%n%error
Possible parameters:
%d{FORMAT}
or%date{FORMAT}
- how to format record timestamp.{FORMAT}
is optional stftime string, by default it is%Y/%m/%d %H:%M:%S,%L
%level
or%le
or%p
- output record level name like ERROR or WARN%logger
or%lo
or%c
- output logger name%%
- output %%n
- output EOL%err
or%error
- output stack trace of passed error%x
or%x{field}
- output JSON.stringified value of context field
Also available text decorators (now only colors):
%highlight(text)
- will decorate passed text with record level decorator%cyan(text)
- other colors
%cyan.bold(text)
- other bold colors
Example: %date000 %highlight(%5level) %cyan(%logger) - %message%n%error
Also it is possible to set it to function. One of possible examples jsonFormat (require('huzzah/json-format')
).
It can accept the same serializers bunyan can accept and you will have json output at the end.
Parameters
format
(string | function) It is either formatted string as described, or function returning string and accepts just one argument log record
Examples
var f = new LoggerFactory();
var logger = f.get('a.b');
f.settings('a.b')
.addHandler(new ConsoleHandler().setFormat(jsonFormat({
timestamp: strftimeCompile('%Y/%m/%d %H:%M:%S,%L000')
})));
Returns this
Extends BaseHandler
Just simple console handler
Extends BaseHandler
Like ConsoleHandler but output whole record to console. This can be usefull in browser to see inspections.
Extends BaseHandler
Allow to pass records to stream
Should we format record before passing to stream? By default it is true
Parameters
value
boolean
Returns this
Stream to pass records
Parameters
stream
WritableStream
Returns this