This is a logger setup using winston and loggly which makes it easier for an application to maintain log files. There are separate log files for warn logs, debug logs, error logs and info logs. Cloud log to www.loggly.com can also be added with correct settings and there is also the plain old console log for console view only.
npm install winston-logger-setupORnpm install winston-logger-setup --save
The package looks for a config-log.js file in the config folder inside root of the application for configuration settings. If found and if it contains the specified properties that are required for the package, it will use those values, else the default configurations values that are bundled with the package will be used instead. An example of config-log.js file:
moduleexports =logLevels:levels:error: 0warn: 0info: 0debug: 0cnsl: 0colors:error: 'red'warn: 'yellow'info: 'blue'debug: 'white'cnsl: 'green'cloud:inputToken: 'j88m3-sjjhj33-dsfjj33'subdomain: 'LogglySubDomain'logFolder: '/log/';
contains two properties - levels and colors
levels refers to the importance of the log, 0 being the most important and 5 being the least. If the importance of log is less, only the log file is updated while the console does not show the log. The level values in the above config example are also the default values bound with the package.
colors refers to the color of the log shown in the console. Only standard console colors are available. The color values in the above config example are also the default values bound with the package.
contains configuration for loggly based cloud log setup. It contains two properties - inputToken and subdomain. The default configuration bound with the package does not contain any setting for cloud based log. The setting is obtained from user config file only.
inputToken is the token provided by loggly associated with an account.
subdomain is the name of the subdomain used to register an account.
contains path to the log folder respective from the root folder. The logFolder value in the above config example is also the default value bound with the package.
Basically, it just needs to be imported in order to be used.
let log = ;log;log;log;log;log;log;
log.cnsl is just the plain old log for console and doesn't get recorded to any file. log.cloud is for the cloud based log. The rest are for their obvious respective log files.
By default, all logs are of their respective levels i.e. log.error logs as an error level to the error.log file. But, in case we need to register an info level to the error.log file, we can use the following statement.
let log = ;logerrorLog;
It will be outputted as info log in console but will be recorded in the error.log file.
Similar for the other log levels. Cloud log has info level by default.