diff options
author | Nassim Bounouas <NassimBounouas@users.noreply.github.com> | 2019-06-11 14:30:44 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-06-11 14:30:44 +0200 |
commit | fcf4569f2da9ebcdc43caf8276f82098c89e5677 (patch) | |
tree | 93a5657ecf71bddeffe78ba6cce03292692d45ab | |
parent | dd2c2a52ccd07bcb2317dcc6ce45a2291e6bad62 (diff) | |
download | PeerTube-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
-rw-r--r-- | config/default.yaml | 2 | ||||
-rw-r--r-- | config/production.yaml.example | 2 | ||||
-rw-r--r-- | server/helpers/logger.ts | 27 | ||||
-rw-r--r-- | server/initializers/config.ts | 3 |
4 files changed, 23 insertions, 11 deletions
diff --git a/config/default.yaml b/config/default.yaml index e4e2d2273..a213d5b0a 100644 --- a/config/default.yaml +++ b/config/default.yaml | |||
@@ -75,6 +75,8 @@ storage: | |||
75 | 75 | ||
76 | log: | 76 | log: |
77 | level: 'info' # debug/info/warning/error | 77 | level: 'info' # debug/info/warning/error |
78 | rotation: | ||
79 | enabled : true # Enabled by default, if disabled make sure that 'storage.logs' is pointing to a folder handled by logrotate | ||
78 | 80 | ||
79 | search: | 81 | search: |
80 | # Add ability to fetch remote videos/actors by their URI, that may not be federated with your instance | 82 | # Add ability to fetch remote videos/actors by their URI, that may not be federated with your instance |
diff --git a/config/production.yaml.example b/config/production.yaml.example index bd0d956bd..cdf6136d8 100644 --- a/config/production.yaml.example +++ b/config/production.yaml.example | |||
@@ -76,6 +76,8 @@ storage: | |||
76 | 76 | ||
77 | log: | 77 | log: |
78 | level: 'info' # debug/info/warning/error | 78 | level: 'info' # debug/info/warning/error |
79 | rotation: | ||
80 | enabled : true | ||
79 | 81 | ||
80 | search: | 82 | search: |
81 | # Add ability to fetch remote videos/actors by their URI, that may not be federated with your instance | 83 | # Add ability to fetch remote videos/actors by their URI, that may not be federated with your instance |
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 @@ | |||
2 | import { mkdirpSync } from 'fs-extra' | 2 | 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 { FileTransportOptions } from 'winston/lib/winston/transports' | ||
5 | import { CONFIG } from '../initializers/config' | 6 | import { CONFIG } from '../initializers/config' |
6 | import { omit } from 'lodash' | 7 | import { omit } from 'lodash' |
7 | 8 | ||
@@ -45,6 +46,21 @@ const labelFormatter = winston.format.label({ | |||
45 | label | 46 | label |
46 | }) | 47 | }) |
47 | 48 | ||
49 | const 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 | |||
59 | if (CONFIG.LOG.ROTATION) { | ||
60 | fileLoggerOptions.maxsize = 1024 * 1024 * 12 | ||
61 | fileLoggerOptions.maxFiles = 20 | ||
62 | } | ||
63 | |||
48 | const logger = winston.createLogger({ | 64 | const 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( |
diff --git a/server/initializers/config.ts b/server/initializers/config.ts index 2be300a57..50653b0a0 100644 --- a/server/initializers/config.ts +++ b/server/initializers/config.ts | |||
@@ -83,7 +83,8 @@ const CONFIG = { | |||
83 | }, | 83 | }, |
84 | TRUST_PROXY: config.get<string[]>('trust_proxy'), | 84 | TRUST_PROXY: config.get<string[]>('trust_proxy'), |
85 | LOG: { | 85 | LOG: { |
86 | LEVEL: config.get<string>('log.level') | 86 | LEVEL: config.get<string>('log.level'), |
87 | ROTATION: config.get<boolean>('log.rotation.enabled') | ||
87 | }, | 88 | }, |
88 | SEARCH: { | 89 | SEARCH: { |
89 | REMOTE_URI: { | 90 | REMOTE_URI: { |