Closed sunny1974 closed 6 years ago
log4j? That's a Java logging library.
My question is i want to write mosca server logs like info,debug and error to a file path. How can i do it?Using bunyan or anything else?
Mosca uses pino: http://getpino.io/#/.
You can pass all the options of tipo to the logger
options when creating a Mosca instance
I'm very new to nodejs and mosca may be my question is wrong:
Question: Mosca is not using bunyan?
logger, the options for Bunyan. (Example: {level: 'debug'} ) logger.childOf, the parent Bunyan logger.
Based on above lines i thought mosca used bunyan to write logs.
And can you please share me working example of logger implementation for mosca
Mosca is currently using pino: https://github.com/mcollina/mosca/blob/master/package.json#L91.
Pino is API compatible with Bunyan.
https://github.com/mcollina/mosca/blob/master/examples/Server_With_All_Interfaces-Settings.js#L24
If i use below setting, Where logs should be logged(log folder path)?
logger: { name: 'MoscaServer', level: 'debug' },
you can pass down logger: { stream: fs.createWriteStream('dest') }
to store the log in a file.
Thanks @mcollina
I tried same thing but no success. log file is created with 0kb and not writing any logs. i tried with below configurations.
1) logger:{ name: "SunilServer", level: "debug",stream: fs.createWriteStream("/apps/mosca/logs/server.log") },
2) logger:{stream: fs.createWriteStream("/apps/mosca/logs/server.log") }
3) var pinoms = require('pino-multi-stream'); var streams = [ {stream: fs.createWriteStream('/apps/logs/rtmott/mosca/mosca.log')}, {level: 'debug', stream: fs.createWriteStream('/apps/mosca/logs/mosca.log')} ] var log = pinoms({streams: streams})
logger:log,
@mcollina please suggest me a way to do this.
@mcollina Thanks for the support
I have changed this line https://github.com/mcollina/mosca/blob/master/lib/server.js#L152 to below. So logs are writing to specified file path
this.logger = pino(this.modernOpts.logger,this.modernOpts.logger.stream);
One more question:
Is there any way to rotate log files daily?
we have to go in this way ? https://github.com/pinojs/pino/blob/master/docs/howtos.md#rotate
or can you suggest me a better way pls?
@sunny1974 can you send a PR?
I want know how to enable log4j logs for mosca server.