Skip to content

Commit 7155753

Browse files
authored
Merge branch 'development' into dependabot/npm_and_yarn/word-wrap-1.2.4
2 parents ee39184 + 7db607e commit 7155753

31 files changed

+483
-167
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,22 @@ Following settings are available for styling:
453453
- `prettyErrorLoggerNameDelimiter`: if a logger name is set this delimiter will be added afterwards
454454
- `prettyInspectOptions`: <a href="https://nodejs.org/api/util.html#utilinspectobject-options" target="_blank">Available options</a>
455455

456+
### Customizing template tokens
457+
It's possible to add user defined tokes, by overwriting the `addPlaceholders` in the `settings.overwrite`. this callback allows to add or overwrite tokens in the `placeholderValues`.
458+
for example, to add the token: `{{custom}}`;
459+
```javascript
460+
const logger = new Logger({
461+
type: "pretty",
462+
prettyLogTemplate: "{{custom}} ",
463+
overwrite: {
464+
addPlaceholders: (logObjMeta: IMeta, placeholderValues: Record<string, string>) => {
465+
placeholderValues["custom"] = "test";
466+
},
467+
},
468+
});
469+
```
470+
this would yield in the token `{{custom}}` being replaced with `"test"`
471+
456472
- **Styling:**
457473
- `stylePrettyLogs`: defines whether logs should be styled and colorized
458474
- `prettyLogStyles`: provides colors and styles for different placeholders and can also be dependent on the value (e.g. log level)

build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { build } from "esbuild";
22

33
build({
4-
entryPoints: ["src/index.ts"],
4+
entryPoints: ["src/index.browser.ts"],
55
outfile: "dist/browser/index.js",
66
platform: "browser",
77
bundle: true,

docs/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,22 @@ Following settings are available for styling:
453453
- `prettyErrorLoggerNameDelimiter`: if a logger name is set this delimiter will be added afterwards
454454
- `prettyInspectOptions`: <a href="https://nodejs.org/api/util.html#utilinspectobject-options" target="_blank">Available options</a>
455455

456+
### Customizing template tokens
457+
It's possible to add user defined tokes, by overwriting the `addPlaceholders` in the `settings.overwrite`. this callback allows to add or overwrite tokens in the `placeholderValues`.
458+
for example, to add the token: `{{custom}}`;
459+
```javascript
460+
const logger = new Logger({
461+
type: "pretty",
462+
prettyLogTemplate: "{{custom}} ",
463+
overwrite: {
464+
addPlaceholders: (logObjMeta: IMeta, placeholderValues: Record<string, string>) => {
465+
placeholderValues["custom"] = "test";
466+
},
467+
},
468+
});
469+
```
470+
this would yield in the token `{{custom}}` being replaced with `"test"`
471+
456472
- **Styling:**
457473
- `stylePrettyLogs`: defines whether logs should be styled and colorized
458474
- `prettyLogStyles`: provides colors and styles for different placeholders and can also be dependent on the value (e.g. log level)

examples/nodejs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Logger, ILogObj } from "../../src";
1+
import { Logger, ILogObj } from "../../src/index.node";
22

33
class MyClass {
44
private readonly _logger: Logger<ILogObj> = new Logger({

examples/nodejs/index2.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { Logger, BaseLogger, IMeta } from "../../src/index.js";
1+
import { BaseLogger } from "../../src/index.js";
2+
import { Logger } from "../../src/index.node.js";
3+
import NodeRuntime from "../../src/runtime/nodejs/index";
24

35
const defaultLogObject: {
46
name: string;
@@ -22,7 +24,7 @@ logger.fatal("test1 %s test3", "test2");
2224

2325
console.log("###############");
2426

25-
const baseLogger = new BaseLogger({}, defaultLogObject);
27+
const baseLogger = new BaseLogger(NodeRuntime, {}, defaultLogObject);
2628

2729
baseLogger.log(0, "test", "test base logger", { haha: true, password: "123456" }, ["SECRET"]);
2830

package-lock.json

Lines changed: 72 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)