How to use the fatal function from log4js

Find comprehensive JavaScript log4js.fatal code examples handpicked from public code repositorys.

log4js.fatal is a method in the log4js library that logs a message at the "fatal" level, indicating that a critical error has occurred.

91
92
93
94
95
96
97
98
99
100
            global.app.garbageSeller = new GarbageSeller(global.app.settings, global.app.client);

            /** On initialization complete callback */
            onInit(global.app);
        } catch (error) {
            logger.fatal(`error on application initialization: ${error}`);
            process.exit(0);
        }
    });
});
fork icon0
star icon0
watch icon1

How does log4js.fatal work?

log4js.fatal is a method in the log4js library that logs a message at the "fatal" level. The "fatal" level is typically reserved for logging messages that indicate a critical error or system failure that prevents the application from continuing. When you call log4js.fatal, you provide a message to be logged as a string or object. You can also provide additional arguments to include in the log message, such as a stack trace or error object. By default, log4js.fatal logs the message to the console using the layout and appender configured in the log4js configuration file. However, you can also configure log4js to log messages to a file, a database, or any other output source by configuring the appropriate appender. Here's an example of how you might use log4js.fatal to log a critical error in your application: javascript Copy code {{{{{{{ const log4js = require('log4js'); log4js.configure({ appenders: { console: { type: 'console' } }, categories: { default: { appenders: ['console'], level: 'error' } } }); const logger = log4js.getLogger(); try { // some code that might throw an error } catch (error) { logger.fatal('An error occurred:', error); } In this example, we first configure log4js to log messages at the "error" level or above to the console. We then create a new logger instance using log4js.getLogger(). Finally, we use a try-catch block to catch any errors that occur in our code, and log them as a "fatal" error using logger.fatal. When logger.fatal is called with an error object, log4js automatically includes the error's stack trace in the log message, along with any additional information provided in the message.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
const log4js = require("log4js");

log4js.configure({
  appenders: {
    console: { type: "console" },
  },
  categories: {
    default: { appenders: ["console"], level: "error" },
  },
});

const logger = log4js.getLogger();

try {
  // some code that might throw an error
} catch (error) {
  logger.fatal("An error occurred:", error);
}

In this example, we first configure log4js to log messages at the "error" level or above to the console. We then create a new logger instance using log4js.getLogger(). Finally, we use a try-catch block to catch any errors that occur in our code, and log them as a "fatal" error using logger.fatal. When logger.fatal is called with an error object, log4js automatically includes the error's stack trace in the log message, along with any additional information provided in the message.