Skip to content

Commit

Permalink
Add fileNameWithLine, Fix #182
Browse files Browse the repository at this point in the history
  • Loading branch information
terehov committed Dec 21, 2022
1 parent 2a5af1b commit 2d45617
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,14 @@ Following settings are available for styling:
- `{{nameWithDelimiterSuffix}}`: optional name of the current logger (s. above) with a delimiter at the end
- `{{fullFilePath}}`: a full path starting from `/` root
- `{{filePathWithLine}}`: a full path below the project path with line number
- `{{fileNameWithLine}}`: file name with line number
- `prettyErrorTemplate`: template string for error message. Possible placeholders:
- `{{errorName}}`: name of the error
- `{{errorMessage}}`: error message
- `{{errorStack}}`: Placeholder for all stack lines defined by `prettyErrorStackTemplate`
- `prettyErrorStackTemplate`: template string for error stack trace lines. Possible placeholders:
- `{{fileName}}`: name of the file
- `{{fileNameWithLine}}`: file name with line number
- `{{filePathWithLine}}`: a full path below the project path with a line number
- `{{method}}`: _optional_ name of the invoking method
- `prettyErrorParentNamesSeparator`: separator to be used when joining names ot the parent logger, and the current one (default: `:`)
Expand Down Expand Up @@ -483,6 +485,7 @@ const logger = new Logger({
nameWithDelimiterSuffix: ["white", "bold"],
errorName: ["bold", "bgRedBright", "whiteBright"],
fileName: ["yellow"],
fileNameWithLine: "white",
},
});

Expand Down
4 changes: 2 additions & 2 deletions src/BaseLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ export class BaseLogger<LogObj> {
}

if (this.settings.type === "pretty") {
logMetaMarkup = this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
logArgsAndErrorsMarkup = prettyFormatLogObj(maskedArgs, this.settings);
logMetaMarkup = logMetaMarkup ?? this._prettyFormatLogObjMeta(logObjWithMeta?.[this.settings.metaProperty]);
logArgsAndErrorsMarkup = logArgsAndErrorsMarkup ?? prettyFormatLogObj(maskedArgs, this.settings);
}

if (logMetaMarkup != null && logArgsAndErrorsMarkup != null) {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function getCallerStackFrame(stackDepthLevel: number): IStackFrame {
const filePath = pathArray?.pop()?.split("?")?.[0];
const fileName = filePath?.split("/").pop();
const fileNameWithLine = `${fileName}:${fileLine}`;
const filePathWithLine = `${filePath}:${fileLine}`;
const filePathWithLine = `${href}${filePath}:${fileLine}`;
const errorStackLine = fullFilePath?.split(" (");
return {
fullFilePath,
Expand Down Expand Up @@ -118,7 +118,7 @@ export function getErrorTrace(error: Error): IStackFrame[] {
const filePath = pathArray?.pop()?.split("?")[0];
const fileName = filePath?.split("/")?.pop()?.split("?")[0];
const fileNameWithLine = `${fileName}:${fileLine}`;
const filePathWithLine = `${filePath}:${fileLine}`;
const filePathWithLine = `${href}${filePath}:${fileLine}`;

if (filePath != null && filePath.length > 0) {
result.push({
Expand Down

0 comments on commit 2d45617

Please sign in to comment.