Logger
Module | ejs |
Definition | class Logger |
Inheritance | Logger Object |
Specified | ejscript-2.5 |
Stability | Prototype. |
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
Qualifiers | Property | Type | Description |
static const | All | Number | Logging level to output all messages. |
static const | Config | Number | Logging level for configuration output. |
static const | Error | Number | Logging level for most serious errors. (. |
static const | Info | Number | Logging level for informational messages. |
static const | Off | Number | Logging level for no logging. |
static const | Warn | Number | Logging level for warnings. |
get set | filter | Function | Filter 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 | level | Number | The 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 | match | RegExp | Matching expression to filter log messages. The match regular expression is used to match
against the Logger names. |
get set | name | String | The name of this logger. |
get set | outStream | Stream | The output stream used by the logger. |
Inherited Properties
Logger Class Methods
Qualifiers | Method |
(No own class methods defined)
Inherited Methods
Logger Instance Methods
Inherited Methods
Method Detail
- 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")
- Description
- Close the logger.
- Description
- Emit a configuration message.
- Parameters
- 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. |
- Description
- Emit an error message.
- Parameters
- Description
- Emit an informational message.
- Parameters
- 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] |
- Description
- Emit a warning message.
- Parameters
msgs: Array | The data to log. |
- 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
readable | Issued when data is written and a consumer can read without blocking. |
writable | Issued 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.