aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/logger.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-05-15 22:22:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-05-20 09:57:40 +0200
commit65fcc3119c334b75dd13bcfdebf186afdc580a8f (patch)
tree4f2158c61a9b7c3f47cfa233d01413b946ee53c0 /server/helpers/logger.ts
parentd5f345ed4cfac4e1fa84dcb4fce1cda4d32f9c73 (diff)
downloadPeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.gz
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.tar.zst
PeerTube-65fcc3119c334b75dd13bcfdebf186afdc580a8f.zip
First typescript iteration
Diffstat (limited to 'server/helpers/logger.ts')
-rw-r--r--server/helpers/logger.ts48
1 files changed, 48 insertions, 0 deletions
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts
new file mode 100644
index 000000000..3c35e41e0
--- /dev/null
+++ b/server/helpers/logger.ts
@@ -0,0 +1,48 @@
1// Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/
2import mkdirp = require('mkdirp')
3import path = require('path')
4import winston = require('winston')
5
6// Do not use barrel (dependencies issues)
7import { CONFIG } from '../initializers/constants'
8
9const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
10
11// Create the directory if it does not exist
12mkdirp.sync(CONFIG.STORAGE.LOG_DIR)
13
14const logger = new winston.Logger({
15 transports: [
16 new winston.transports.File({
17 level: 'debug',
18 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'all-logs.log'),
19 handleExceptions: true,
20 json: true,
21 maxsize: 5242880,
22 maxFiles: 5,
23 colorize: false,
24 prettyPrint: true
25 }),
26 new winston.transports.Console({
27 level: 'debug',
28 label: label,
29 handleExceptions: true,
30 humanReadableUnhandledException: true,
31 json: false,
32 colorize: true,
33 prettyPrint: true
34 })
35 ],
36 exitOnError: true
37})
38
39// TODO: useful?
40// logger.stream = {
41// write: function (message) {
42// logger.info(message)
43// }
44// }
45
46// ---------------------------------------------------------------------------
47
48export { logger }