Wednesday 24 May 2017

s3-streamlogger is not working (Winston logs are not shipped to bucket)

I am trying to use this module (s3-streamlogger) to ship logs directly to S3 Bucket

Code

 ` var winston = require('winston');
 var S3StreamLogger = require('s3-streamlogger').S3StreamLogger;
 var s3_stream = new S3StreamLogger({
             bucket: "bucket_name",
      access_key_id: "key_id",
  secret_access_key: "access_key"
});
const tsFormat = (new Date()).toLocaleTimeString();
var path = require('path');
var jsonPath = path.join(__dirname, '..', 'logs_directory');
console.log(jsonPath);
var fs = require('fs');
if (!fs.existsSync(jsonPath)) {
  fs.mkdirSync(jsonPath);
}; 
const logger = new (winston.Logger)({
  transports: [
    // colorize the output to the console
    new (winston.transports.Console)({
      stream: s3_stream,
      timestamp: tsFormat,
      colorize: true,
      level: 'info'
    })
  ]
});
s3_stream.on('error', function(err){
    // there was an error! 
    some_other_logging_transport.log('error', 'logging transport error', err)
});
logger.info('Hello Winston!');
  module.exports=logger;`

Neither any error is printed on console nor the file is created in the bucket. There is no debug mode that can probably ease things.

Previously I was trying to use this along with daily rotate function of winston but I think that wont work together

const logger = new (winston.Logger)({
  transports: [
    // colorize the output to the console
    new (winston.transports.Console)({
      stream: s3_stream,
      timestamp: tsFormat,
      colorize: true,
      level: 'info'
    }),
    new (require('winston-daily-rotate-file'))({
      stream: s3_stream,
      filename: jsonPath + '/logfile.log',
      timestamp: tsFormat,
      datePattern: 'yyyy-MM-dd',
      prepend: true
    })
  ]
});

Question 1 - Why is this not working? Question 2 - Can I use daily-log-rotate along with stream?



via Gandalf the White

No comments:

Post a Comment