Skip to content

Commit f144125

Browse files
committed
Add an option to force a filename to the final log file
1 parent 1060e3e commit f144125

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface WriterWrite {
1313

1414
export interface fileLoggerOptions extends WriterConstructor {
1515
rotate?: boolean;
16+
filename?: string;
1617
}
1718

1819
export interface LoggerWriteOptions {

logger.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default class Logger {
2121
private writer?: Writer;
2222
private rotate = false;
2323
private dir?: string;
24+
private filename?: string;
2425

2526
#debug = this.debug;
2627
#info = this.info;
@@ -123,7 +124,8 @@ export default class Logger {
123124

124125
private write({ dir, type, args }: LoggerWriteOptions): Promise<void> {
125126
const date = this.getDate();
126-
const filename = this.rotate === true ? `${date}_${type}` : type;
127+
const filename = this.filename ||
128+
(this.rotate === true ? `${date}_${type}` : type);
127129
const path = `${dir}/${filename}.log`;
128130
const msg = this.format(...args);
129131
return this.writer!.write({ path, msg, type });
@@ -151,6 +153,7 @@ export default class Logger {
151153
const { rotate, maxBytes, maxBackupCount } = options;
152154
if (rotate === true) this.rotate = true;
153155
this.dir = dir;
156+
this.filename = options?.filename;
154157
this.writer = new Writer({
155158
maxBytes,
156159
maxBackupCount,

0 commit comments

Comments
 (0)