-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Customizable log format #183
Comments
+1. And model from where the log line was generated would be useful. |
json? bunyan? not sure it's a right way, just a wild thought |
+1. Can't wait for this feature. |
Maybe you can try my small module graceful-logger. |
👍 for timestamped logs. |
2 similar comments
👍 for timestamped logs. |
👍 for timestamped logs. |
👍 for timestamped logs. |
^^' DraftIf using graceful-logger:
Formating logs via JSON: {
"apps" : [{
"script" : "hello.js",
"name" : "hello",
"log_format" : ":date.color :level.blue :msg"
}]
} |
It would be great having a I don't think you need to implement
Everyone would be able to choose what he like most (:. |
Thx @soyuka , momentjs is also a great module, if the need is only focused on having timestamped logs, this is the right solution. I will do that. Just an idea, is it possible to print the file and the line where the log has been generated ? (by overriding, a clean way, the console.log and console.error) ? |
I think |
momentjs is not that heavy, it doesnt require any dependencies and is only about 28k minified. |
Thus moment would be a good choice ~
|
Wut ! I found something very interesting. https://gist.github.com/Unitech/5a7e099d8c99b1b16d7c Some other interesting methods: https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi#Customizing_stack_traces Extract:
Would you be interested by that ? |
var stream = process.stdout; //could be a fs.createWriteStream(path)
var log = function() {
if(process.argv.indexOf('-q') === -1 && process.argv.indexOf('-quiet') === -1) {
stream.write(util.format.apply(this, arguments) + EOL);
}
} We could improve this by adding some time and an optional var t = !date_log_format || date_log_format === 'X' ? Date.now() : moment().format(date_log_format);
stream.write(t + util.format.apply(this, arguments) + EOL); @Unitech: if we want to implement stack traces here we should not do it by default, it could be a huge performance break. |
Hello Unitech, question, i have tried to customize the format for timestamp in my logs however that doesn't work, i used the following: pm2 start tao-app-rest --merge-logs --log-date-format="YYYY-MM-DD HH:mm Z" However the logs after restart seems the same format, is it because it was an already started app? may i need to stop and kill the app to get the expected result? |
Hmm, when you start an app the first time, pm2 will hold those parameters in-memory. They should be replaced when you issue a
May you test this? It would be kind to have reproducible steps if this still doesn't work for you, thanks! |
I didn't issue a restart with params, the app's where up and i just used the start command like up there, so if i did use start with format but then input a restart those options dissapear? |
If i input the start command 2 times both with log format params, the second one should output logs with the date and time but it only shows that for PM2 logs, app logs don't show neither of them: $ pm2 flush && pm2 start tao-app-rest --merge-logs --log-date-format="YYYY-MM-DD HH:mm Z" && pm2 start tao-app-rest --merge-logs --log-date-format="YYYY-MM-DD HH:mm Z"
[PM2] Flushing
[PM2] /root/.pm2/logs/tao-app-rest-out-1.log
[PM2] /root/.pm2/logs/tao-app-rest-error-1.log
[PM2] restartProcessId process id 1
[PM2] Process successfully started
...
[PM2] restartProcessId process id 1
[PM2] Process successfully started
...
$ pm2 logs
[PM2] Tailing last 20 lines for [all] processes
PM2: 2016-04-26 11:24:03: Stopping app:tao-app-rest id:1
PM2: 2016-04-26 11:24:03: App [tao-app-rest] with id [1] and pid [5645], exited with code [0] via signal [null]
PM2: 2016-04-26 11:24:03: Starting execution sequence in -fork mode- for app name:tao-app-rest id:1
PM2: 2016-04-26 11:24:03: App name:tao-app-rest id:1 online
PM2: 2016-04-26 11:24:15: Stopping app:tao-app-rest id:1
PM2: 2016-04-26 11:24:15: App [tao-app-rest] with id [1] and pid [5694], exited with code [0] via signal [null]
PM2: 2016-04-26 11:24:15: Starting execution sequence in -fork mode- for app name:tao-app-rest id:1
PM2: 2016-04-26 11:24:15: App name:tao-app-rest id:1 online
PM2: 2016-04-26 11:24:24: Stopping app:tao-app-rest id:1
PM2: 2016-04-26 11:24:24: App [tao-app-rest] with id [1] and pid [5723], exited with code [0] via signal [null]
PM2: 2016-04-26 11:24:24: Starting execution sequence in -fork mode- for app name:tao-app-rest id:1
PM2: 2016-04-26 11:24:24: App name:tao-app-rest id:1 online
tao-app-rest-1 (out): Servidor corriendo en el puerto 50003 // }
tao-app-rest-1 (out): Servidor corriendo en el puerto 50003 // } } Here's no date/time logging
tao-app-rest-1 (out): Servidor corriendo en el puerto 50003 // }
[PM2] Streaming realtime logs for [all] processes |
I have the same issue, --log-date-format doesn't work at all |
It would be great to be able to specify the log format. For example, I would like to display a timestamp with each log line.
The text was updated successfully, but these errors were encountered: