]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/helpers/logger.ts
Replacing the err being thrown by a gracefull exit.process(1)
[github/Chocobozzz/PeerTube.git] / server / helpers / logger.ts
index 7d1d72f29d8b1d1fae4b858304777ecf1b11a152..7968b5ec9904f30e35f53f511e1ac38234132d8e 100644 (file)
@@ -37,7 +37,7 @@ const jsonLoggerFormat = winston.format.printf(info => {
 })
 
 const timestampFormatter = winston.format.timestamp({
-  format: 'YYYY-MM-dd HH:mm:ss.SSS'
+  format: 'YYYY-MM-DD HH:mm:ss.SSS'
 })
 const labelFormatter = winston.format.label({
   label
@@ -52,14 +52,14 @@ const logger = new winston.createLogger({
       maxsize: 5242880,
       maxFiles: 5,
       format: winston.format.combine(
-        timestampFormatter,
+        winston.format.timestamp(),
         labelFormatter,
         winston.format.splat(),
         jsonLoggerFormat
       )
     }),
     new winston.transports.Console({
-      handleExcegiptions: true,
+      handleExceptions: true,
       humanReadableUnhandledException: true,
       format: winston.format.combine(
         timestampFormatter,
@@ -73,11 +73,39 @@ const logger = new winston.createLogger({
   exitOnError: true
 })
 
+function bunyanLogFactory (level: string) {
+  return function () {
+    let meta = null
+    let args = [].concat(arguments)
+
+    if (arguments[ 0 ] instanceof Error) {
+      meta = arguments[ 0 ].toString()
+      args = Array.prototype.slice.call(arguments, 1)
+      args.push(meta)
+    } else if (typeof (args[ 0 ]) !== 'string') {
+      meta = arguments[ 0 ]
+      args = Array.prototype.slice.call(arguments, 1)
+      args.push(meta)
+    }
+
+    logger[ level ].apply(logger, args)
+  }
+}
+const bunyanLogger = {
+  trace: bunyanLogFactory('debug'),
+  debug: bunyanLogFactory('debug'),
+  info: bunyanLogFactory('info'),
+  warn: bunyanLogFactory('warn'),
+  error: bunyanLogFactory('error'),
+  fatal: bunyanLogFactory('error')
+}
+
 // ---------------------------------------------------------------------------
 
 export {
   timestampFormatter,
   labelFormatter,
   consoleLoggerFormat,
-  logger
+  logger,
+  bunyanLogger
 }