Class: Logger

arpen/services/logger~ Logger

Logger service

Provides logging services via .info(), .warn(), .error() and .debug().

First argument might contain util.format() formatting (%[sdj]) as accepted by console.log(). If the last argument is a function it is used as completion callback with the first argument being a flag indicating if the data was actually written to the file.

Logs are always echoed to stdout/stderr if DEBUG environment variable is defined and are written to the file or emailed if configured

new Logger(app, config, util [, streams])

Create the service
Parameters:
Name Type Argument Description
app App The application
config object Config service
util Util Util service
streams object <optional>
Stream container

Members


<static> provides :string

Service name is 'logger'
Type:
  • string

<static> requires :Array.<string>

Dependencies as constructor arguments
Type:
  • Array.<string>

<static> maxFileBufferLines

Max lines of log waiting to written to the file

Methods


<static> formatString(string)

Format a log string
Parameters:
Name Type Description
string string String to log
Returns:
Returns the string with date
Type
string

createLogStream(name, filename, level, isDefault, options)

Create log stream
Parameters:
Name Type Description
name string Stream name
filename string | function File name
level string Log level: debug, warn, info, error
isDefault boolean This stream is the default one
options object Stream options

setLogStream(name)

Switch log stream
Parameters:
Name Type Description
name string Stream name

error(messages)

Log error
Parameters:
Name Type Argument Description
messages * <repeatable>
Messages

info(messages)

Log info
Parameters:
Name Type Argument Description
messages * <repeatable>
Messages

warn(messages)

Log warning
Parameters:
Name Type Argument Description
messages * <repeatable>
Messages

debug(issuer, messages)

Log debug
Parameters:
Name Type Argument Description
issuer string Issuer
messages * <repeatable>
Messages

dump(messages)

Log messages without prepending the date (equivalent of .info())
Parameters:
Name Type Argument Description
messages * <repeatable>
Messages

log(type, messages, issuer, logDate [, cb])

Actually log the error
Parameters:
Name Type Argument Description
type string Type of the error message
messages Array Array of messages
issuer string | undefined Issuer if used
logDate boolean Prepend current date
cb function | undefined <optional>
File write callback: first parameter whether file was actually written

_startLog(log)

Start log stream
Parameters:
Name Type Description
log object