writelog
Write logs and rotate every day. This is simple template for loging error or info message to file. Also transport to console when run in development environment.
Install
npm install @thesuhu/writelog --save
Variables
Logs will be split per day and will be stored in a certain size and period. This module will read three environment variables.
-
MAXSIZE: maximum file size, more than it will rotate. the units used are kilobyte, megabyte and gigabyte. Use
k
,m
org
as the suffix. (default:5m
) -
MAXFILES: maximum period the log file will be kept. This is number of days. Use
d
as the suffix. (default:30d
) -
ENV: this is environment development or not. Use
dev
to add transport to console. Other thandev
will not be transported to console. (default:dev
)
Usage
below is an example of usage.
const writelog = require('@thesuhu/writelog')
writelog.info('Hello world!')
try {
// some code
} catch(err) {
writelog.error(err.message)
}