Skip to content

Commit

Permalink
Remove winston-daily-rotate-file side effects if you're not using log…
Browse files Browse the repository at this point in the history
…ging

Context: https://gitlab.com/gitlab-org/gitter/webapp/-/merge_requests/2040#note_438055746

Without this change, I was seeing `TypeError: Cannot set property DailyRotateFile of #<Object> which has only a getter`
errors when using with Gitter which also has `winston@2` installed.
  • Loading branch information
MadLittleMods committed Oct 30, 2020
1 parent 5574b29 commit 7bb0462
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/components/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ limitations under the License.
*/
import * as util from "util";
import winston, { Logger, format, Logform } from "winston";
import "winston-daily-rotate-file";
import chalk from "chalk";
import * as Transport from 'winston-transport';
import { DailyRotateFile } from "winston/lib/winston/transports";

type LogLevel = "debug"|"info"|"warn"|"error";

Expand Down Expand Up @@ -155,6 +153,12 @@ class Logging {
}

if (config.files !== undefined) {
// `winston-daily-rotate-file` has side-effects so we don't want to mess anyone up
// unless they want to use logging
require("winston-daily-rotate-file");
// eslint-disable-next-line @typescript-eslint/no-var-requires
const { DailyRotateFile } = require("winston/lib/winston/transports");

for (const filename of Object.keys(config.files)) {
const level = config.files[filename];
this.transports.push(new DailyRotateFile({
Expand Down

0 comments on commit 7bb0462

Please sign in to comment.