Skip to content

Commit 2d45617

Browse files
committed
Add fileNameWithLine, Fix #182
1 parent 2a5af1b commit 2d45617

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

docs/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,14 @@ Following settings are available for styling:
426426
- `{{nameWithDelimiterSuffix}}`: optional name of the current logger (s. above) with a delimiter at the end
427427
- `{{fullFilePath}}`: a full path starting from `/` root
428428
- `{{filePathWithLine}}`: a full path below the project path with line number
429+
- `{{fileNameWithLine}}`: file name with line number
429430
- `prettyErrorTemplate`: template string for error message. Possible placeholders:
430431
- `{{errorName}}`: name of the error
431432
- `{{errorMessage}}`: error message
432433
- `{{errorStack}}`: Placeholder for all stack lines defined by `prettyErrorStackTemplate`
433434
- `prettyErrorStackTemplate`: template string for error stack trace lines. Possible placeholders:
434435
- `{{fileName}}`: name of the file
436+
- `{{fileNameWithLine}}`: file name with line number
435437
- `{{filePathWithLine}}`: a full path below the project path with a line number
436438
- `{{method}}`: _optional_ name of the invoking method
437439
- `prettyErrorParentNamesSeparator`: separator to be used when joining names ot the parent logger, and the current one (default: `:`)
@@ -483,6 +485,7 @@ const logger = new Logger({
483485
nameWithDelimiterSuffix: ["white", "bold"],
484486
errorName: ["bold", "bgRedBright", "whiteBright"],
485487
fileName: ["yellow"],
488+
fileNameWithLine: "white",
486489
},
487490
});
488491

src/BaseLogger.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ export class BaseLogger<LogObj> {
118118
}
119119

120120
if (this.settings.type === "pretty") {
121-
logMetaMarkup = this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
122-
logArgsAndErrorsMarkup = prettyFormatLogObj(maskedArgs, this.settings);
121+
logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
122+
logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? prettyFormatLogObj(maskedArgs, this.settings);
123123
}
124124

125125
if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {

src/runtime/browser/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export function getCallerStackFrame(stackDepthLevel: number): IStackFrame {
6464
const filePath = pathArray?.pop()?.split("?")?.[0];
6565
const fileName = filePath?.split("/").pop();
6666
const fileNameWithLine = `${fileName}:${fileLine}`;
67-
const filePathWithLine = `${filePath}:${fileLine}`;
67+
const filePathWithLine = `${href}${filePath}:${fileLine}`;
6868
const errorStackLine = fullFilePath?.split(" (");
6969
return {
7070
fullFilePath,
@@ -118,7 +118,7 @@ export function getErrorTrace(error: Error): IStackFrame[] {
118118
const filePath = pathArray?.pop()?.split("?")[0];
119119
const fileName = filePath?.split("/")?.pop()?.split("?")[0];
120120
const fileNameWithLine = `${fileName}:${fileLine}`;
121-
const filePathWithLine = `${filePath}:${fileLine}`;
121+
const filePathWithLine = `${href}${filePath}:${fileLine}`;
122122

123123
if (filePath != null && filePath.length > 0) {
124124
result.push({

0 commit comments

Comments
 (0)