diff --git a/src/FileStreamRotator.ts b/src/FileStreamRotator.ts index 4a55593..33b9fef 100644 --- a/src/FileStreamRotator.ts +++ b/src/FileStreamRotator.ts @@ -68,7 +68,7 @@ export default class FileStreamRotator extends EventEmitter { } config.auditSettings = auditSettings - config.rotationSettings = DefaultOptions.rotationSettings({filename: options.filename, extension: options.extension}) + config.rotationSettings = DefaultOptions.rotationSettings({ filename: options.filename, extension: options.extension }) if (options.date_format && !options.frequency){ config.rotationSettings.frequency = Frequency.date } else { @@ -78,6 +78,9 @@ export default class FileStreamRotator extends EventEmitter { if (options.date_format) { config.rotationSettings.format = options.date_format } + if (typeof options.getDateString === 'function') { + config.rotationSettings.getDateString = options.getDateString + } config.rotationSettings.utc = options.utc ?? false switch(options.frequency){ case "daily": diff --git a/src/Rotator.ts b/src/Rotator.ts index 5c0cbb7..7ae5727 100644 --- a/src/Rotator.ts +++ b/src/Rotator.ts @@ -183,6 +183,10 @@ export default class Rotator { getDateString(date?: Date): string { let _date: Date = date || new Date() + if (typeof this.settings.getDateString === 'function') { + return this.settings.getDateString(_date); + } + let components: DateComponents = Rotator.getDateComponents(_date, this.settings.utc) let format = this.settings.format diff --git a/src/types.d.ts b/src/types.d.ts index 16fcabd..db7a95d 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -21,6 +21,7 @@ export type RotationSettings = { format?: string utc: boolean extension?: string + getDateString(date?: Date): string } export type FileOptions = { @@ -89,6 +90,9 @@ export type FileStreamRotatorOptions = { symlink_name?: string /** Use specified hashing algorithm for audit. Defaults to 'md5'. Use 'sha256' for FIPS compliance. */ audit_hash_type?: "md5" | "sha256" + + /** use this to define your filename with date */ + getDateString?: (date?: Date) => string } export type FileStreamRotatorConfig = {