tsedio / logger

📄 A multi channel logger written in TypeScript.
https://logger.tsed.io
MIT License
64 stars 24 forks source link

Logger doesn't allow to rotate the file via both Size/Date at same time. #146

Closed panbhatt closed 2 years ago

panbhatt commented 2 years ago

TSED Logger 6.1.1

Description

TSED logger 6.1.1 doesn't as of now allow to rotate the file by both SIZE and Date. i.e. either of one if reaches early then the log file needs to be rotated.

This seems to be implemented in StreamRoller package via using RollingFileWriteStream.js https://github.com/log4js-node/streamroller/blob/master/lib/RollingFileWriteStream.js

Changed Needed in Tsed logger: FileAppender.ts openTheStream() Needs to be changed, keeping the parameter list same and introducing a new IF if(pattern && file){ stream = new streams.RollingFileWriteStream(file,options); }

This also needs to change the maxFileSize to maxSize (as that is what being used in StreamRoller).

Should I go ahead and implement this change.

panbhatt commented 2 years ago

Here is a sample configuration what it looks like to rotate the log both by filesize and date/time pattern.

const pattern = "[%d][%p][%c] - %m";

  const loggerFileAppenderConfig = {

    type: "file",

    layout: {

      type: "pattern",

      pattern

    },

    filename: "c:/temp/hb.log",

    pattern: ".yyyy-MM-dd-hh-mm",

    keepFileExt: true,

    daysToKeep: 5,

    maxLogSize : 1035

  };