diff --git a/.gitignore b/.gitignore index 746d8737..448b9a94 100644 --- a/.gitignore +++ b/.gitignore @@ -71,3 +71,6 @@ common/temp/ # Don't commit tsdoc meta /src/tsdoc-metadata.json + +# For now, ignore banchmarks (WIP) +/benchmarks/ diff --git a/README.md b/README.md index bd8ff871..56a2c783 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ![tslog pretty output](https://raw.githubusercontent.com/fullstack-build/tslog/master/docs/assets/tslog_pretty_output.png "tslog pretty output") ### Highlights -⚡ **Small footprint, blazing performance (native V8 integration)**
+⚡ **Batteries included, native V8 integration**
👮‍️ **Fully typed with TypeScript support (exact code position)**
🗃 **_Pretty_ or `JSON` output**
⭕️ **Supports _circular_ structures**
diff --git a/src/LoggerWithoutCallSite.ts b/src/LoggerWithoutCallSite.ts index f6af8454..356013ef 100644 --- a/src/LoggerWithoutCallSite.ts +++ b/src/LoggerWithoutCallSite.ts @@ -97,9 +97,9 @@ export class LoggerWithoutCallSite { depth: Infinity, }, delimiter: " ", - dateTimePattern: "year-month-day hour:minute:second.millisecond", + dateTimePattern: undefined, // local timezone: Intl.DateTimeFormat().resolvedOptions().timeZone - dateTimeTimezone: "utc", + dateTimeTimezone: undefined, prefix: [], maskValuesOfKeys: ["password"], @@ -366,6 +366,7 @@ export class LoggerWithoutCallSite { exposeStack: boolean = true ): ILogObject { const callSites: NodeJS.CallSite[] = LoggerHelper.getCallSites(); + const relevantCallSites: NodeJS.CallSite[] = callSites.splice( this.settings.ignoreStackLevels ); @@ -373,6 +374,7 @@ export class LoggerWithoutCallSite { relevantCallSites[0] != null ? this._callSiteWrapper(relevantCallSites[0]) : undefined; + const stackFrameObject: IStackFrame | undefined = stackFrame != null ? LoggerHelper.toStackFrameObject(stackFrame) @@ -497,29 +499,43 @@ export class LoggerWithoutCallSite { **/ public printPrettyLog(std: IStd, logObject: ILogObject): void { if (this.settings.displayDateTime === true) { - const dateTimeParts: IFullDateTimeFormatPart[] = [ - ...(new Intl.DateTimeFormat("en", { - weekday: undefined, - year: "numeric", - month: "2-digit", - day: "2-digit", - hour12: false, - hour: "2-digit", - minute: "2-digit", - second: "2-digit", - timeZone: this.settings.dateTimeTimezone, - }).formatToParts(logObject.date) as IFullDateTimeFormatPart[]), - { - type: "millisecond", - value: ("00" + logObject.date.getMilliseconds()).slice(-3), - } as IFullDateTimeFormatPart, - ]; + let nowStr: string = ""; + if ( + this.settings.dateTimePattern != null || + this.settings.dateTimeTimezone != null + ) { + const dateTimePattern = + this.settings.dateTimePattern ?? + "year-month-day hour:minute:second.millisecond"; + const dateTimeTimezone = this.settings.dateTimeTimezone ?? "utc"; + + const dateTimeParts: IFullDateTimeFormatPart[] = [ + ...(new Intl.DateTimeFormat("en", { + weekday: undefined, + year: "numeric", + month: "2-digit", + day: "2-digit", + hour12: false, + hour: "2-digit", + minute: "2-digit", + second: "2-digit", + timeZone: dateTimeTimezone, + }).formatToParts(logObject.date) as IFullDateTimeFormatPart[]), + { + type: "millisecond", + value: ("00" + logObject.date.getMilliseconds()).slice(-3), + } as IFullDateTimeFormatPart, + ]; + + nowStr = dateTimeParts.reduce( + (prevStr: string, thisStr: IFullDateTimeFormatPart) => + prevStr.replace(thisStr.type, thisStr.value), + dateTimePattern + ); + } else { + nowStr = new Date().toISOString().replace("T", " ").replace("Z", " "); + } - const nowStr: string = dateTimeParts.reduce( - (prevStr: string, thisStr: IFullDateTimeFormatPart) => - prevStr.replace(thisStr.type, thisStr.value), - this.settings.dateTimePattern - ); std.write( LoggerHelper.styleString( ["gray"], @@ -587,7 +603,7 @@ export class LoggerWithoutCallSite { fileLocation = `${logObject.filePath}:${logObject.lineNumber}`; } const concatenatedMetaLine: string = [name, fileLocation, functionName] - .join("") + .join(" ") .trim(); if (concatenatedMetaLine.length > 0) { diff --git a/src/interfaces.ts b/src/interfaces.ts index 89bad630..b77708b2 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -180,8 +180,8 @@ export interface ISettings extends ISettingsParam { prettyInspectOptions: InspectOptions; jsonInspectOptions: InspectOptions; delimiter: string; - dateTimePattern: string; - dateTimeTimezone: string; + dateTimePattern?: string; + dateTimeTimezone?: string; prefix: unknown[]; maskValuesOfKeys: (number | string)[]; maskAnyRegEx: (string | number)[];