Skip to content

Commit

Permalink
feat: add option to disable file logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mytlogos committed Oct 26, 2022
1 parent 3517326 commit ef2360c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions packages/core/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ interface Config {
development: boolean;
stopScrapeEvents: boolean;
lokiUrl?: string;
disableFileLogging: boolean;
}

/**
Expand All @@ -55,6 +56,8 @@ const appConfig: Config = {
development: (process.env.NODE_ENV || config.parsed.NODE_ENV) !== "production",
stopScrapeEvents: !!Number(process.env.stopScrapeEvents || config.parsed.stopScrapeEvents),
lokiUrl: process.env.lokiUrl || config.parsed.lokiUrl,
disableFileLogging:
((process.env.disableFileLogging || config.parsed.disableFileLogging) ?? "").toLocaleLowerCase() === "true",
};

const optionalVars = new Set(["lokiUrl"] as Array<keyof Config>);
Expand Down
29 changes: 18 additions & 11 deletions packages/core/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,6 @@ const logger = winston.createLogger({
new winston.transports.Console(),
],
transports: [
//
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
//
new DailyRotateFile({
filename: `${filePrefix}combined.log-%DATE%`,
}),
new DailyRotateFile({
filename: `${filePrefix}error.log-%DATE%`,
level: "error",
}),
new winston.transports.Console({
format: format.combine(
format.colorize(),
Expand All @@ -95,6 +84,24 @@ const logger = winston.createLogger({
],
});

if (!env.disableFileLogging) {
//
// - Write to all logs with level `info` and below to `combined.log`
// - Write all logs error (and below) to `error.log`.
//
logger.add(
new DailyRotateFile({
filename: `${filePrefix}combined.log-%DATE%`,
}),
);
logger.add(
new DailyRotateFile({
filename: `${filePrefix}error.log-%DATE%`,
level: "error",
}),
);
}

if (env.lokiUrl) {
logger.add(
new LokiTransport({
Expand Down

0 comments on commit ef2360c

Please sign in to comment.