Skip to content

Commit

Permalink
πŸ”€ Merge pull request #1119 from TF2Autobot/options-disable-log-files
Browse files Browse the repository at this point in the history
βœ¨πŸ”‡ an option to disable saving log files
  • Loading branch information
idinium96 authored May 26, 2022
2 parents 1dcbb42 + 3a2a6b7 commit 35dbdad
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,7 @@ export default interface Options extends JsonOptions {

debug?: boolean;
debugFile?: boolean;
enableSaveLogFile?: boolean;

folderName?: string;
filePrefix?: string;
Expand Down Expand Up @@ -2260,6 +2261,7 @@ export function loadOptions(options?: Options): Options {

debug: getOption('debug', true, jsonParseBoolean, incomingOptions),
debugFile: getOption('debugFile', true, jsonParseBoolean, incomingOptions),
enableSaveLogFile: getOption('enableSaveLogFile', true, jsonParseBoolean, incomingOptions),

enableHttpApi: getOption('enableHttpApi', false, jsonParseBoolean, incomingOptions),
httpApiPort: getOption('httpApiPort', 3001, jsonParseNumber, incomingOptions)
Expand Down
62 changes: 35 additions & 27 deletions src/lib/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,33 +103,41 @@ export function init(paths: Paths, options: Options): void {
const debugConsole = options.debug;
// Debug to file is enabled by default
const debugFile = options.debugFile;

const transports = [
{
type: 'DailyRotateFile',
filename: paths.logs.log,
level: debugFile ? 'debug' : 'verbose',
filter: 'private',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxFiles: '14d'
},
{
type: 'File',
filename: paths.logs.trade,
level: 'trade',
filter: 'trade'
},
{
type: 'File',
filename: paths.logs.error,
level: 'error'
},
{
type: 'Console',
level: debugConsole ? 'debug' : 'verbose'
}
];
const enableSaveLogs = options.enableSaveLogFile;

const transports = enableSaveLogs
? [
{
type: 'DailyRotateFile',
filename: paths.logs.log,
level: debugFile ? 'debug' : 'verbose',
filter: 'private',
datePattern: 'YYYY-MM-DD',
zippedArchive: true,
maxFiles: '14d'
},
{
type: 'File',
filename: paths.logs.trade,
level: 'trade',
filter: 'trade'
},
{
type: 'File',
filename: paths.logs.error,
level: 'error'
},
{
type: 'Console',
level: debugConsole ? 'debug' : 'verbose'
}
]
: [
{
type: 'Console',
level: debugConsole ? 'debug' : 'verbose'
}
];

transports.forEach(transport => {
const type = transport.type;
Expand Down
1 change: 1 addition & 0 deletions template.ecosystem.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

"DEBUG": true,
"DEBUG_FILE": true,
"ENABLE_SAVE_LOG_FILE": true,

"ENABLE_HTTP_API": false,
"HTTP_API_PORT": 3001
Expand Down
1 change: 1 addition & 0 deletions template.env
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TIME_ADDITIONAL_NOTES=""

DEBUG=true
DEBUG_FILE=true
ENABLE_SAVE_LOG_FILE=true

ENABLE_HTTP_API=false
HTTP_API_PORT=3001

0 comments on commit 35dbdad

Please sign in to comment.