aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-01-19 13:58:13 +0100
committerChocobozzz <me@florianbigard.com>2018-01-19 13:58:13 +0100
commit23e27dd53599be65b2dc2968448ce155a00a96c9 (patch)
treecd7e5c88a345584a25c7ea03a81332b804d082d6 /server/helpers
parentc7a9f34f7229529ea726de13867f87c0a8dd3007 (diff)
downloadPeerTube-23e27dd53599be65b2dc2968448ce155a00a96c9.tar.gz
PeerTube-23e27dd53599be65b2dc2968448ce155a00a96c9.tar.zst
PeerTube-23e27dd53599be65b2dc2968448ce155a00a96c9.zip
Add ability to configure log level
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/core-utils.ts2
-rw-r--r--server/helpers/logger.ts60
2 files changed, 50 insertions, 12 deletions
diff --git a/server/helpers/core-utils.ts b/server/helpers/core-utils.ts
index 77547c528..65f18d644 100644
--- a/server/helpers/core-utils.ts
+++ b/server/helpers/core-utils.ts
@@ -50,6 +50,8 @@ function root () {
50 50
51// Thanks: https://stackoverflow.com/a/12034334 51// Thanks: https://stackoverflow.com/a/12034334
52function escapeHTML (stringParam) { 52function escapeHTML (stringParam) {
53 if (!stringParam) return ''
54
53 const entityMap = { 55 const entityMap = {
54 '&': '&amp;', 56 '&': '&amp;',
55 '<': '&lt;', 57 '<': '&lt;',
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts
index 2676133db..6a02f680a 100644
--- a/server/helpers/logger.ts
+++ b/server/helpers/logger.ts
@@ -9,26 +9,57 @@ const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT
9// Create the directory if it does not exist 9// Create the directory if it does not exist
10mkdirp.sync(CONFIG.STORAGE.LOG_DIR) 10mkdirp.sync(CONFIG.STORAGE.LOG_DIR)
11 11
12const logger = new winston.Logger({ 12// Use object for better performances (~ O(1))
13const excludedKeys = {
14 level: true,
15 message: true,
16 splat: true,
17 timestamp: true,
18 label: true
19}
20function keysExcluder (key, value) {
21 return excludedKeys[key] === true ? undefined : value
22}
23
24const loggerFormat = winston.format.printf((info) => {
25 let additionalInfos = JSON.stringify(info, keysExcluder, 2)
26 if (additionalInfos === '{}') additionalInfos = ''
27
28 return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message} ${additionalInfos}`
29})
30
31const timestampFormatter = winston.format.timestamp({
32 format: 'YYYY-MM-dd HH:mm:ss.SSS'
33})
34const labelFormatter = winston.format.label({
35 label
36})
37
38const logger = new winston.createLogger({
39 level: CONFIG.LOG.LEVEL,
13 transports: [ 40 transports: [
14 new winston.transports.File({ 41 new winston.transports.File({
15 level: 'debug', 42 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
16 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'all-logs.log'),
17 handleExceptions: true, 43 handleExceptions: true,
18 json: true,
19 maxsize: 5242880, 44 maxsize: 5242880,
20 maxFiles: 5, 45 maxFiles: 5,
21 colorize: false, 46 format: winston.format.combine(
22 prettyPrint: true 47 timestampFormatter,
48 labelFormatter,
49 winston.format.splat(),
50 winston.format.json()
51 )
23 }), 52 }),
24 new winston.transports.Console({ 53 new winston.transports.Console({
25 level: 'debug',
26 label: label,
27 handleExceptions: true, 54 handleExceptions: true,
28 humanReadableUnhandledException: true, 55 humanReadableUnhandledException: true,
29 json: false, 56 format: winston.format.combine(
30 colorize: true, 57 timestampFormatter,
31 prettyPrint: true 58 winston.format.splat(),
59 labelFormatter,
60 winston.format.colorize(),
61 loggerFormat
62 )
32 }) 63 })
33 ], 64 ],
34 exitOnError: true 65 exitOnError: true
@@ -36,4 +67,9 @@ const logger = new winston.Logger({
36 67
37// --------------------------------------------------------------------------- 68// ---------------------------------------------------------------------------
38 69
39export { logger } 70export {
71 timestampFormatter,
72 labelFormatter,
73 loggerFormat,
74 logger
75}