diff options
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/logs.ts | 14 | ||||
-rw-r--r-- | server/helpers/logger.ts | 11 |
2 files changed, 19 insertions, 6 deletions
diff --git a/server/helpers/custom-validators/logs.ts b/server/helpers/custom-validators/logs.ts new file mode 100644 index 000000000..30d0ce262 --- /dev/null +++ b/server/helpers/custom-validators/logs.ts | |||
@@ -0,0 +1,14 @@ | |||
1 | import { exists } from './misc' | ||
2 | import { LogLevel } from '../../../shared/models/server/log-level.type' | ||
3 | |||
4 | const logLevels: LogLevel[] = [ 'debug', 'info', 'warn', 'error' ] | ||
5 | |||
6 | function isValidLogLevel (value: any) { | ||
7 | return exists(value) && logLevels.indexOf(value) !== -1 | ||
8 | } | ||
9 | |||
10 | // --------------------------------------------------------------------------- | ||
11 | |||
12 | export { | ||
13 | isValidLogLevel | ||
14 | } | ||
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index 203e637a8..f8a142718 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts | |||
@@ -3,10 +3,12 @@ import { mkdirpSync } from 'fs-extra' | |||
3 | import * as path from 'path' | 3 | import * as path from 'path' |
4 | import * as winston from 'winston' | 4 | import * as winston from 'winston' |
5 | import { CONFIG } from '../initializers' | 5 | import { CONFIG } from '../initializers' |
6 | import { omit } from 'lodash' | ||
6 | 7 | ||
7 | const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | 8 | const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT |
8 | 9 | ||
9 | // Create the directory if it does not exist | 10 | // Create the directory if it does not exist |
11 | // FIXME: use async | ||
10 | mkdirpSync(CONFIG.STORAGE.LOG_DIR) | 12 | mkdirpSync(CONFIG.STORAGE.LOG_DIR) |
11 | 13 | ||
12 | function loggerReplacer (key: string, value: any) { | 14 | function loggerReplacer (key: string, value: any) { |
@@ -22,13 +24,10 @@ function loggerReplacer (key: string, value: any) { | |||
22 | } | 24 | } |
23 | 25 | ||
24 | const consoleLoggerFormat = winston.format.printf(info => { | 26 | const consoleLoggerFormat = winston.format.printf(info => { |
25 | const obj = { | 27 | const obj = omit(info, 'label', 'timestamp', 'level', 'message') |
26 | meta: info.meta, | ||
27 | err: info.err, | ||
28 | sql: info.sql | ||
29 | } | ||
30 | 28 | ||
31 | let additionalInfos = JSON.stringify(obj, loggerReplacer, 2) | 29 | let additionalInfos = JSON.stringify(obj, loggerReplacer, 2) |
30 | |||
32 | if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' | 31 | if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' |
33 | else additionalInfos = ' ' + additionalInfos | 32 | else additionalInfos = ' ' + additionalInfos |
34 | 33 | ||
@@ -57,7 +56,7 @@ const logger = winston.createLogger({ | |||
57 | filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'), | 56 | filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'), |
58 | handleExceptions: true, | 57 | handleExceptions: true, |
59 | maxsize: 1024 * 1024 * 12, | 58 | maxsize: 1024 * 1024 * 12, |
60 | maxFiles: 5, | 59 | maxFiles: 20, |
61 | format: winston.format.combine( | 60 | format: winston.format.combine( |
62 | winston.format.timestamp(), | 61 | winston.format.timestamp(), |
63 | jsonLoggerFormat | 62 | jsonLoggerFormat |