You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expose `$logger` for using when CLI is required as a library. Also introduce `initialize` method in it, that allows full configuration of the log4js instance.
Implement a new `emit-appender` logger, that emits `logData` event with information for the logging instead of printing it to the stdout. This emitter can be used with the following code:
```JavaScript
const tns = require("nativescript");
const { LoggerAppenders } = tns.constants;
const { EventEmitter } = require("events");
const emitter = new EventEmitter();
// IMPORTANT: Due to current log4js behavior, you must set the event handler BEFORE calling initialize of the logger.
emitter.on("logData", logData => {
// logData contains two properties: loggingEvent and formattedMessage
// loggingEvent contains information about the level of the message and the raw message itself
// formattedMessage is the message with specified layout (i.e. it is string). Default layout is `messagePassThrough`.
});
tns.logger.initialize({ appenderOptions: { type: LoggerAppenders.emitAppender, emitter });
```
This is the easiest way to use the new appender. You can also use LoggerLevel from constants and specify different logging levels. You can pass whatever layout you need for the message.
0 commit comments