Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log files not closed automatically #42

Open
p-g-krish opened this issue Oct 30, 2018 · 2 comments
Open

log files not closed automatically #42

p-g-krish opened this issue Oct 30, 2018 · 2 comments

Comments

@p-g-krish
Copy link

My configuration:

        options = {
                logFilePath: filePath,
                timestampFormat: 'YYYY-MM-DD HH:mm:ss.SSS'
            },

            log = SimpleNodeLogger.createSimpleLogger(options);

When check with open file using lsof, the log file still open. if i shutdown my app the the files are closed.but if the app run forever it will open file,each time .Hence slowly it's eat my memory. Please guide me solve this issue

@darrylwest
Copy link
Owner

rolling logger is probably what you want; the active file gets closed when it rolls.

@bato3
Copy link

bato3 commented Mar 7, 2019

It seems to me that FileAppender opens new stream on every call, eg:

const  SimpleLogger = require('simple-node-logger');

for(let i = 0; i< 10; i++) {
  let manager = new SimpleLogger();
  manager.createFileAppender( { logFilePath:filename } );
  let log1 = manager.createLogger( 'CategoryOne', 'trace' );
}

Or a more frequent situation: create loger for the same log file, in different js files.

@darrylwest I think FileAppender should use the global writer instance, eg:

let writerInstances = ()
//...
    const openWriter = function() {
        if (!writer) {
            const file = path.normalize( logFilePath );
            if(writerInstances[file]) {
               writer = writerInstances[file]
            } else {
              const opts = {
                  flags:'a',
                  encoding:'utf8'
              };
              writer = writerInstances[file] =fs.createWriteStream( file, opts );
            }
          }
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants