Logger

Moduleejs
Definition class Logger
InheritanceLogger inherit Object
Specifiedejscript-2.5
StabilityPrototype.

Logger objects provide a convenient and consistent method to capture and store logging information.

Loggers can direct output to Streams and may be aggregated in a hierarchical manner. The verbosity of logging can be managed and messages can be filtered.

Hierarchies of loggers can be constructed by specifying a parent logger when creating a logger instance. For example, a logger can be created for each class in a package with all such loggers having a single parent. Loggers can send log messages to their parent and inherit their parent's log level. The top level logger for an application is defined by App.log.

Each logger may define a filter function that returns true or false depending on whether a specific message should be logged or not. A matching pattern can alternatively be used to filter messages.

An Application will have a default Logger instance created and stored in App.log at startup. This Logger uses the LogFile class to communicate with the Application's native log file. This is typically initialized by the "--log" command line switch and otherwise defaults to send messages to the standard error console.


Properties

QualifiersPropertyTypeDescription
static const AllNumberLogging level to output all messages.
static const ConfigNumberLogging level for configuration output.
static const ErrorNumberLogging level for most serious errors. (.
static const InfoNumberLogging level for informational messages.
static const OffNumberLogging level for no logging.
static const WarnNumberLogging level for warnings.
get set filterFunctionFilter function for this logger. The filter function is called with the following signature: with "this" set to the Logger instance. The log parameter is set to the original logger that created the message. function filter(log: Logger, name: String, level: Number, kind: String, msg: String): Boolean.
get set levelNumberThe numeric verbosity setting (0-9) of this logger. Zero is least verbose, nine is the most verbose. Messages with a lower (or equal) verbosity level than the logger's level are emitted. (.
get location The logging location parameter specified when constructing or redirecting the logger.
get set matchRegExpMatching expression to filter log messages. The match regular expression is used to match against the Logger names.
get set nameStringThe name of this logger.
get set outStreamStreamThe output stream used by the logger.

Logger Class Methods

(No own class methods defined)

QualifiersMethod

Logger Instance Methods

QualifiersMethod
Logger(name: String, location, level: Number = 0)
 Logger constructor.
close(): Void
 Close the logger.
config(msgs: Array): Void
 Emit a configuration message.
debug(level: Number, msgs: Array): Void
 Emit a debug message.
error(msgs: Array): Void
 Emit an error message.
info(msgs: Array): Void
 Emit an informational message.
redirect(location, level: Number = null): Void
 Redirect log output.
warn(msgs: Array): Void
 Emit a warning message.
write(data: Array): Number
 Write data to the stream.Write messages to the logger stream.

Method Detail

Logger(name: String, location, level: Number = 0)
Description
Logger constructor. The Logger constructor can create different types of loggers based on the three (optional) arguments.
Parameters
name: String Unique name of the logger. Loggers are typically named after the module, class or subsystem they are associated with.
location Optional output stream or Logger to send messages to. If a parent Logger instance is provided for the output parameter, messages are sent to the parent for rendering.
level: Number Optional integer verbosity level. Messages with a message level less than or equal to the defined logger level will be emitted. Range is 0 (least verbose) to 9. [default: 0]
Example
var file = File("progress.log", "w")
var log = new Logger("name", file, 5)
log.debug(2, "message")

close(): Void
Description
Close the logger.

config(msgs: Array): Void
Description
Emit a configuration message.
Parameters
msgs: Array Data to log.

debug(level: Number, msgs: Array): Void
Description
Emit a debug message. The message level will be compared to the logger setting to determine whether it will be output to the devices or not. Also, if the logger has a filter function set that may filter the message out before logging.
Parameters
level: Number The level of the message.
msgs: Array The string message to log.

error(msgs: Array): Void
Description
Emit an error message.
Parameters
msgs: Array Data to log.

info(msgs: Array): Void
Description
Emit an informational message.
Parameters
msgs: Array Data to log.

redirect(location, level: Number = null): Void
Description
Redirect log output.
Parameters
location Optional output stream, Logger or location specification to send messages to. If a parent Logger instance is provided, messages are sent to the parent for rendering. A location specification is of the form: file:level.
level: Number Optional integer verbosity level. Messages with a message level less than or equal to the defined logger level will be emitted. Range is 0 (least verbose) to 9. H. [default: null]

warn(msgs: Array): Void
Description
Emit a warning message.
Parameters
msgs: Array The data to log.

write(data: Array): Number
Description
Write data to the stream.Write messages to the logger stream. If the stream can accept all the write data, the call returns immediately with the number of bytes written. If writing more data than the stream can absorb in sync mode, the call will block until the data is written. If writing more data than the stream can absorb in async mode, the call will not block and will buffer the data and return immediately. Some streams will require a flush() call to actually send the data. A "writable" event will be issued when the stream can again absorb more data.NOTE: for the Logger class, I/O errors will not throw exceptions.
Parameters
data: Array Data to write.
Events
readableIssued when data is written and a consumer can read without blocking.
writableIssued when the stream becomes empty and it is ready to be written to.
Returns
A count of the bytes actually written.
Throws
IOError: if there is an I/O error.