diff options
Diffstat (limited to 'server/helpers/logger.ts')
-rw-r--r-- | server/helpers/logger.ts | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts index a4bd41427..f1808849e 100644 --- a/server/helpers/logger.ts +++ b/server/helpers/logger.ts | |||
@@ -1,10 +1,11 @@ | |||
1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ | 1 | // Thanks http://tostring.it/2014/06/23/advanced-logging-with-nodejs/ |
2 | import { mkdirpSync } from 'fs-extra' | 2 | import { mkdirpSync } from 'fs-extra' |
3 | import { omit } from 'lodash' | ||
3 | import * as path from 'path' | 4 | import * as path from 'path' |
5 | import { format as sqlFormat } from 'sql-formatter' | ||
4 | import * as winston from 'winston' | 6 | import * as winston from 'winston' |
5 | import { FileTransportOptions } from 'winston/lib/winston/transports' | 7 | import { FileTransportOptions } from 'winston/lib/winston/transports' |
6 | import { CONFIG } from '../initializers/config' | 8 | import { CONFIG } from '../initializers/config' |
7 | import { omit } from 'lodash' | ||
8 | import { LOG_FILENAME } from '../initializers/constants' | 9 | import { LOG_FILENAME } from '../initializers/constants' |
9 | 10 | ||
10 | const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT | 11 | const label = CONFIG.WEBSERVER.HOSTNAME + ':' + CONFIG.WEBSERVER.PORT |
@@ -39,13 +40,20 @@ function getLoggerReplacer () { | |||
39 | } | 40 | } |
40 | 41 | ||
41 | const consoleLoggerFormat = winston.format.printf(info => { | 42 | const consoleLoggerFormat = winston.format.printf(info => { |
42 | const obj = omit(info, 'label', 'timestamp', 'level', 'message') | 43 | const obj = omit(info, 'label', 'timestamp', 'level', 'message', 'sql') |
43 | 44 | ||
44 | let additionalInfos = JSON.stringify(obj, getLoggerReplacer(), 2) | 45 | let additionalInfos = JSON.stringify(obj, getLoggerReplacer(), 2) |
45 | 46 | ||
46 | if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' | 47 | if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = '' |
47 | else additionalInfos = ' ' + additionalInfos | 48 | else additionalInfos = ' ' + additionalInfos |
48 | 49 | ||
50 | if (info.sql) { | ||
51 | additionalInfos += '\n' + sqlFormat(info.sql, { | ||
52 | language: 'sql', | ||
53 | ident: ' ' | ||
54 | }) | ||
55 | } | ||
56 | |||
49 | return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` | 57 | return `[${info.label}] ${info.timestamp} ${info.level}: ${info.message}${additionalInfos}` |
50 | }) | 58 | }) |
51 | 59 | ||