aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers
diff options
context:
space:
mode:
authorNassim Bounouas <NassimBounouas@users.noreply.github.com>2019-06-11 14:30:44 +0200
committerChocobozzz <me@florianbigard.com>2019-06-11 14:30:44 +0200
commitfcf4569f2da9ebcdc43caf8276f82098c89e5677 (patch)
tree93a5657ecf71bddeffe78ba6cce03292692d45ab /server/helpers
parentdd2c2a52ccd07bcb2317dcc6ce45a2291e6bad62 (diff)
downloadPeerTube-fcf4569f2da9ebcdc43caf8276f82098c89e5677.tar.gz
PeerTube-fcf4569f2da9ebcdc43caf8276f82098c89e5677.tar.zst
PeerTube-fcf4569f2da9ebcdc43caf8276f82098c89e5677.zip
Feature/logrotation (#1881)
* #1775 Configure the activation or deactivation of winston log rotation * Winston log rotation enabled by default #1775 * #1775 tslint correction * #1775 FileTransportOptions typed and configuration files * #1775 tslint correction * #1775 log.rotation.enabled configuration binding
Diffstat (limited to 'server/helpers')
-rw-r--r--server/helpers/logger.ts27
1 files changed, 17 insertions, 10 deletions
diff --git a/server/helpers/logger.ts b/server/helpers/logger.ts
index 734523b01..8603dd761 100644
--- a/server/helpers/logger.ts
+++ b/server/helpers/logger.ts
@@ -2,6 +2,7 @@
2import { mkdirpSync } from 'fs-extra' 2import { mkdirpSync } from 'fs-extra'
3import * as path from 'path' 3import * as path from 'path'
4import * as winston from 'winston' 4import * as winston from 'winston'
5import { FileTransportOptions } from 'winston/lib/winston/transports'
5import { CONFIG } from '../initializers/config' 6import { CONFIG } from '../initializers/config'
6import { omit } from 'lodash' 7import { omit } from 'lodash'
7 8
@@ -45,6 +46,21 @@ const labelFormatter = winston.format.label({
45 label 46 label
46}) 47})
47 48
49const fileLoggerOptions: FileTransportOptions = {
50
51 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
52 handleExceptions: true,
53 format: winston.format.combine(
54 winston.format.timestamp(),
55 jsonLoggerFormat
56 )
57}
58
59if (CONFIG.LOG.ROTATION) {
60 fileLoggerOptions.maxsize = 1024 * 1024 * 12
61 fileLoggerOptions.maxFiles = 20
62}
63
48const logger = winston.createLogger({ 64const logger = winston.createLogger({
49 level: CONFIG.LOG.LEVEL, 65 level: CONFIG.LOG.LEVEL,
50 format: winston.format.combine( 66 format: winston.format.combine(
@@ -52,16 +68,7 @@ const logger = winston.createLogger({
52 winston.format.splat() 68 winston.format.splat()
53 ), 69 ),
54 transports: [ 70 transports: [
55 new winston.transports.File({ 71 new winston.transports.File(fileLoggerOptions),
56 filename: path.join(CONFIG.STORAGE.LOG_DIR, 'peertube.log'),
57 handleExceptions: true,
58 maxsize: 1024 * 1024 * 12,
59 maxFiles: 20,
60 format: winston.format.combine(
61 winston.format.timestamp(),
62 jsonLoggerFormat
63 )
64 }),
65 new winston.transports.Console({ 72 new winston.transports.Console({
66 handleExceptions: true, 73 handleExceptions: true,
67 format: winston.format.combine( 74 format: winston.format.combine(