-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Paul S edited this page Nov 24, 2021
·
2 revisions
Here we'll show you how to use the LogEater package!
To log an info into a file and/or the console write:
const LogEater = require('logeater');
LogEater.info('My info message!');
To log an error into a file and/or the console write:
const LogEater = require('logeater');
LogEater.error('My error message!');
// or if you have an exception
try {
throw new Error()
} catch(error) {
LogEater.error(error);
}
To log a warning into a file and/or the console write:
const LogEater = require('logeater');
LogEater.warning('My warning message!');
To log a warning into a file and/or the console write:
const LogEater = require('logeater');
LogEater.debug('My debug message!');
You can modify LogEater according to your preferences like this:
LogEater.defaultConfig = {
default: {
console: false, // If the log will be printed into the console
file: true, // If the log will be printed into the log-file
path: 'logs' // The path to the directory in which the log will be saved
},
/*
* You can change only certain log levels, every setting not set will be set to the value defined in default
*/
error: {
console: true,
path: 'logs/error'
},
/*
* Date format:
*
* yyyy - replaced with the year 4 digits
* yy - replaced with the year 2 digits
* mm - replaced with the month
* dd - replaced with the day
*/
date: 'yyyy-mm-dd',
/*
* The time format:
*
* hh - replaced with the hours
* mm - replaced with the minutes
* ss - replaced with the seconds
* ms - replaced with the milliseconds
*/
time: 'hh:mm:ss:ms',
/**
* The message format:
*
* {{time}} - replaced with the time
* {{level}} - replaced with the log level
* {{caller}} - replaced with the name of the calling function
* {{message}} - replaced with the message of the log
*/
message: '[{{time}}] {{level}} ({{caller}}): {{message}}',
timezone: 'Europe/Berlin' // The timezone that will be used for the time
};