Skip to content

Commit

Permalink
Set TIMESTAMP to PM2 log by default
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Dec 1, 2014
1 parent 4a44f89 commit 9b35504
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ var default_conf = {
WEB_INTERFACE : parseInt(process.env.PM2_API_PORT) || 9615,
MODIFY_REQUIRE : process.env.PM2_MODIFY_REQUIRE || false,

PM2_LOG_DATE_FORMAT : process.env.PM2_LOG_DATE_FORMAT !== undefined ? process.env.PM2_LOG_DATE_FORMAT : 'YYYY-MM-DD HH:mm:ss Z',

INTERACTOR_LOG_FILE_PATH : p.join(PM2_ROOT_PATH, 'agent.log'),
INTERACTOR_PID_PATH : p.join(PM2_ROOT_PATH, 'agent.pid'),
INTERACTION_CONF : p.join(PM2_ROOT_PATH, 'agent.json5')
Expand Down
4 changes: 4 additions & 0 deletions examples/axm/throw.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

var axm = require('axm');

axm.catchAll();

setTimeout(function() {
console.log('log message from echo auto kill');
throw new Error('Exitasdsadasdsda unacepted 222222 !!');
Expand Down
4 changes: 2 additions & 2 deletions lib/God.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ var God = module.exports = {
* Hack Global Console Of PM2
*/
(function hackConsole(){
if(process.env.PM2_LOG_DATE_FORMAT && typeof process.env.PM2_LOG_DATE_FORMAT == 'string'){
if (cst.PM2_LOG_DATE_FORMAT && typeof cst.PM2_LOG_DATE_FORMAT == 'string'){
var moment = require('moment');

// Generate timestamp prefix
function timestamp(){
return moment().format(process.env.log_date_format) + ': ';
return moment().format(cst.PM2_LOG_DATE_FORMAT) + ': ';
}

var hacks = ['info', 'log', 'error', 'warn'], consoled = {};
Expand Down
2 changes: 2 additions & 0 deletions lib/samples/sample-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ module.exports = function(DEFAULT_HOME) {
WEB_INTERFACE : parseInt(process.env.PM2_API_PORT) || 9615,
MODIFY_REQUIRE : process.env.PM2_MODIFY_REQUIRE || false,

PM2_LOG_DATE_FORMAT : process.env.PM2_LOG_DATE_FORMAT || 'YYYY-MM-DD HH:mm Z',

INTERACTOR_LOG_FILE_PATH : p.join(PM2_HOME, 'agent.log'),
INTERACTOR_PID_PATH : p.join(PM2_HOME, 'agent.pid'),
INTERACTION_CONF : p.join(PM2_HOME, 'agent.json5')
Expand Down
3 changes: 2 additions & 1 deletion test/bash/log-timestamp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function grep_log {
function no_prefix {
eval "grep_log \"$1\""
echo "line count: $OUT"
cat ~/.pm2/pm2.log
[ $OUT -eq 0 ] || fail "expect no timestamp prefix in pm2.log, but currently existing."
success "have no timestamp prefix"
rm_pm2log "$2"
Expand All @@ -51,7 +52,7 @@ then
rm -rf ~/.pm2/pm2.log
fi

unset PM2_LOG_DATE_FORMAT
export PM2_LOG_DATE_FORMAT=""

head ">> LIST (NO PREFIX)"
no_prefix "ls" 0
Expand Down
5 changes: 4 additions & 1 deletion test/fixtures/ecosystem.json5
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@
ref : "origin/master",
repo : "[email protected]:repo.git",
path : "/var/www/development",
"post-deploy" : "pm2 startOrRestart ecosystem.json --env dev"
"post-deploy" : "pm2 startOrRestart ecosystem.json --env dev",
env : {
NODE_ENV: "dev"
}
}
}
}

0 comments on commit 9b35504

Please sign in to comment.