Closed neilyoung closed 2 years ago
I was intending to setup a daily rotating file (or better two). Did that yesterday. As result I have zip files for each hour since yesterday.
"winston": "^3.2.1", "winston-daily-rotate-file": "^4.7.1"
My code:
let { createLogger, format, transports } = require('winston') require('winston-daily-rotate-file') // The format of our log traces let traceFormat = format.combine( format.timestamp(), format.prettyPrint(), format.splat(), format.colorize({ all: true }), format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`) ) let error_log_transport = new transports.DailyRotateFile({ filename: 'error-%DATE%.log', datePattern: 'YYYY-MM-DD-HH', zippedArchive: true, maxSize: '20m', maxFiles: '14d', level: 'error', format: traceFormat }) let combined_log_transport = new transports.DailyRotateFile({ filename: 'combined-%DATE%.log', datePattern: 'YYYY-MM-DD-HH', zippedArchive: true, maxSize: '20m', maxFiles: '14d', format: traceFormat }) // Create the logger object logger = createLogger({ level: 'info', format: format.json(), transports: [ error_log_transport, combined_log_transport ] })
The logging directory:
-rw-rw-r-- 1 ubuntu ubuntu 2604 Jun 8 18:11 combined-2022-06-08-17.log.gz -rw-rw-r-- 1 ubuntu ubuntu 1656 Jun 8 19:05 combined-2022-06-08-18.log.gz -rw-rw-r-- 1 ubuntu ubuntu 17380 Jun 8 20:01 combined-2022-06-08-19.log.gz -rw-rw-r-- 1 ubuntu ubuntu 1095 Jun 8 21:01 combined-2022-06-08-20.log.gz -rw-rw-r-- 1 ubuntu ubuntu 980 Jun 8 22:06 combined-2022-06-08-21.log.gz -rw-rw-r-- 1 ubuntu ubuntu 3050 Jun 8 23:11 combined-2022-06-08-22.log.gz -rw-rw-r-- 1 ubuntu ubuntu 574 Jun 9 00:03 combined-2022-06-08-23.log.gz -rw-rw-r-- 1 ubuntu ubuntu 26067 Jun 9 01:07 combined-2022-06-09-00.log.gz -rw-rw-r-- 1 ubuntu ubuntu 6082 Jun 9 02:00 combined-2022-06-09-01.log.gz -rw-rw-r-- 1 ubuntu ubuntu 2539 Jun 9 03:15 combined-2022-06-09-02.log.gz -rw-rw-r-- 1 ubuntu ubuntu 942 Jun 9 04:03 combined-2022-06-09-03.log.gz -rw-rw-r-- 1 ubuntu ubuntu 416 Jun 9 05:01 combined-2022-06-09-04.log.gz -rw-rw-r-- 1 ubuntu ubuntu 1330 Jun 9 06:10 combined-2022-06-09-05.log.gz -rw-rw-r-- 1 ubuntu ubuntu 162 Jun 9 11:24 combined-2022-06-09-06.log.gz -rw-rw-r-- 1 ubuntu ubuntu 1749 Jun 9 12:01 combined-2022-06-09-11.log.gz -rw-rw-r-- 1 ubuntu ubuntu 1438 Jun 9 13:00 combined-2022-06-09-12.log.gz -rw-rw-r-- 1 ubuntu ubuntu 348 Jun 9 14:25 combined-2022-06-09-13.log.gz -rw-rw-r-- 1 ubuntu ubuntu 430 Jun 9 15:10 combined-2022-06-09-14.log.gz
I was just expecting one file per day. Where is the fault?
Maybe the date pattern should be better
'YYYY-MM-DD'
I was intending to setup a daily rotating file (or better two). Did that yesterday. As result I have zip files for each hour since yesterday.
My code:
The logging directory:
I was just expecting one file per day. Where is the fault?