YUKI Hiroshi
null+****@clear*****
Mon Nov 5 13:23:24 JST 2012
YUKI Hiroshi 2012-11-05 13:23:24 +0900 (Mon, 05 Nov 2012) New Revision: e3f257871fb3f886fdc1d160309952ec781735c1 https://github.com/groonga/gcs/commit/e3f257871fb3f886fdc1d160309952ec781735c1 Log: Output log with local timestamp correctly Modified files: lib/logger.js lib/server.js Modified: lib/logger.js (+27 -5) =================================================================== --- lib/logger.js 2012-11-05 12:17:54 +0900 (969109c) +++ lib/logger.js 2012-11-05 13:23:24 +0900 (ee8da74) @@ -34,9 +34,31 @@ function logQuery(selectQuery, elapsedTime) { } exports.query = logQuery; -function setLogFilePath(context, path) { - var logger = getLogger(context); - logger.add(winston.transports.File, { filename: path }); - logger.add(winston.transports.File, { filename: path, handleExceptions: true }); +function getLocalISOTimestamp() { + var date = new Date(); + var offsetMinutes = date.getTimezoneOffset(); + var timezoneOffset = ('0' + (Math.abs(offsetMinutes) / 60)).slice(-2) + ':' + + ('0' + (Math.abs(offsetMinutes) % 60)).slice(-2); + if (offsetMinutes > 0) { + timezoneOffset = '-' + timezoneOffset; + } else { + timezoneOffset = '+' + timezoneOffset; + } + return date.getFullYear() + '-' + + ('0' + (date.getMonth() + 1)).slice(-2) + '-' + + ('0' + (date.getDate())).slice(-2) + 'T' + + ('0' + (date.getHours())).slice(-2) + ':' + + ('0' + (date.getMinutes())).slice(-2) + ':' + + ('0' + (date.getSeconds())).slice(-2) + '.' + + date.getMilliseconds() + + timezoneOffset; +} + +function addFileTransport(context, filename, options) { + options = options || {}; + options.filename = filename; + options.json = false; + options.timestamp = getLocalISOTimestamp; + getLogger(context).add(winston.transports.File, options); } -exports.setLogFilePath = setLogFilePath; +exports.addFileTransport = addFileTransport; Modified: lib/server.js (+4 -2) =================================================================== --- lib/server.js 2012-11-05 12:17:54 +0900 (e88b708) +++ lib/server.js 2012-11-05 13:23:24 +0900 (3bb3e11) @@ -33,10 +33,12 @@ function prepareLoggers(application, config) { application.use(express.logger({ stream: accessLogStream })); } if (config.queryLogPath) { - logger.setLogFilePath('query', CLI.resolve(config.queryLogPath)); + logger.addFileTransport('query', CLI.resolve(config.queryLogPath)); } if (config.errorLogPath) { - logger.setLogFilePath('error', CLI.resolve(config.errorLogPath)); + logger.addFileTransport('error', + filename: CLI.resolve(config.errorLogPath), + { handleExceptions: true }); } } -------------- next part -------------- HTML����������������������������... Download