mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
docs: updated documentation
This commit is contained in:
parent
a8418a0c85
commit
c7b3814f0d
@ -42,7 +42,7 @@ The `Logger` object has the following properties:
|
||||
- `level` - where `level` is a log4js level or a string that matches a level (e.g. 'info', 'INFO', etc). This allows overriding the configured level for this logger. Changing this value applies to all loggers of the same category.
|
||||
- `useCallStack` - where `useCallStack` is a boolean to indicate if log events for this category use the call stack to generate line numbers and file names in the event. This allows overriding the configured useCallStack for this logger. Changing this value applies to all loggers of the same category.
|
||||
|
||||
## Shutdown - `log4js.shutdown(cb)`
|
||||
## Shutdown - `log4js.shutdown([callback])`
|
||||
|
||||
`shutdown` accepts a callback that will be called when log4js has closed all appenders and finished writing log events. Use this when your programme exits to make sure all your logs are written to files, sockets are closed, etc.
|
||||
|
||||
|
||||
@ -83,15 +83,22 @@ function recording() {
|
||||
return recordingModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* This callback type is called `shutdownCallback` and is displayed as a global symbol.
|
||||
*
|
||||
* @callback shutdownCallback
|
||||
* @param {Error} [error]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Shutdown all log appenders. This will first disable all writing to appenders
|
||||
* and then call the shutdown function each appender.
|
||||
*
|
||||
* @params {Function} cb - The callback to be invoked once all appenders have
|
||||
* @param {shutdownCallback} [callback] - The callback to be invoked once all appenders have
|
||||
* shutdown. If an error occurs, the callback will be given the error object
|
||||
* as the first argument.
|
||||
*/
|
||||
function shutdown(cb) {
|
||||
function shutdown(callback) {
|
||||
debug('Shutdown called. Disabling all log writing.');
|
||||
// First, disable all writing to appenders. This prevents appenders from
|
||||
// not being able to be drained because of run-away log writes.
|
||||
@ -104,15 +111,15 @@ function shutdown(cb) {
|
||||
appenders.init();
|
||||
categories.init();
|
||||
|
||||
// Call each of the shutdown functions in parallel
|
||||
// Count the number of shutdown functions
|
||||
const shutdownFunctions = appendersToCheck.reduceRight(
|
||||
(accum, next) => (next.shutdown ? accum + 1 : accum),
|
||||
0
|
||||
);
|
||||
if (shutdownFunctions === 0) {
|
||||
debug('No appenders with shutdown functions found.');
|
||||
if (cb) {
|
||||
cb(undefined);
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}
|
||||
|
||||
@ -125,11 +132,13 @@ function shutdown(cb) {
|
||||
debug(`Appender shutdowns complete: ${completed} / ${shutdownFunctions}`);
|
||||
if (completed >= shutdownFunctions) {
|
||||
debug('All shutdown functions completed.');
|
||||
if (cb) {
|
||||
cb(error);
|
||||
if (callback) {
|
||||
callback(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call each of the shutdown functions
|
||||
appendersToCheck
|
||||
.filter((a) => a.shutdown)
|
||||
.forEach((a) => a.shutdown(complete));
|
||||
@ -138,7 +147,7 @@ function shutdown(cb) {
|
||||
/**
|
||||
* Get a logger instance.
|
||||
* @static
|
||||
* @param loggerCategoryName
|
||||
* @param {string} [category=default]
|
||||
* @return {Logger} instance of logger for the category
|
||||
*/
|
||||
function getLogger(category) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user