Skip to content

Commit ec9ddba

Browse files
committed
Update readme with some backwards compatibility docs
1 parent 1905604 commit ec9ddba

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

README.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Node.js with JavaScript:
7777
node --enable-source-maps
7878
```
7979

80-
Node.js with TypeScript (with ESM support):
80+
Node.js with TypeScript and `ts-node` (with ESM support):
8181
```bash
8282
node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm
8383
```
@@ -140,6 +140,9 @@ logger.fatal(new Error("I am a pretty Error with a stacktrace."));
140140

141141
## API documentation
142142

143+
> **`tslog >= v4` is a major rewrite and introduces breaking changes.** <br>
144+
> Please, follow this documentation when migrating.
145+
143146
### <a name="life_cycle"></a>Lifecycle of a log message
144147

145148
Every incoming log message runs through a number of steps before being displayed or handed over to a "transport". Every step can be overwritten and adjusted.
@@ -162,7 +165,7 @@ Every incoming log message runs through a number of steps before being displayed
162165
```typescript
163166
import { Logger } from "tslog";
164167

165-
const log: Logger = new Logger();
168+
const log = new Logger();
166169
log.silly("I am a silly log.");
167170
log.trace("I am a trace log.");
168171
log.debug("I am a debug log.");
@@ -547,8 +550,27 @@ const logMsg = logger.info("Test");
547550
//}
548551
```
549552

553+
## Backwards compatibility
554+
555+
> **`tslog` follows a semantic release policy.** A major version change indicates breaking changes.<br><br>
556+
> `tslog >=4` is less limiting when it comes to configuration. There are many use cases (especially when it comes to integration with 3rd party services) that now can be achieved elegantly and were not possible before.
557+
558+
### Name and other constructor parameters
559+
560+
`tslog` < 4 had a name parameter on the constructor. v4 removed all preconfigured parameters and allows you to create your own log object (s. "Defining and accessing `logObj`").
561+
562+
**OLD:** `tslog` < 4
563+
```typescript
564+
const log: Logger = new Logger({ name: "myLogger" });
565+
```
566+
567+
**NEW:** `tslog` >= 4
568+
```typescript
569+
const log = new Logger({ type: "json" }, { name: "DefaultLogger" });
570+
```
571+
550572

551-
### Tip: RequestID: Mark a request (e.g. HTTP) call with AsyncLocalStorage and `tslog`
573+
### RequestID: Mark a request (e.g. HTTP) call with AsyncLocalStorage and `tslog`
552574
>**Node.js 13.10 introduced a new feature called <a href="https://nodejs.org/api/async_hooks.html#async_hooks_class_asynclocalstorage" target="_blank">AsyncLocalStorage.</a>**<br>
553575
554576
**❗ Keep track of all subsequent calls and promises originated from a single request (e.g. HTTP).**

docs/README.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Node.js with JavaScript:
7777
node --enable-source-maps
7878
```
7979

80-
Node.js with TypeScript (with ESM support):
80+
Node.js with TypeScript and `ts-node` (with ESM support):
8181
```bash
8282
node --enable-source-maps --experimental-specifier-resolution=node --no-warnings --loader ts-node/esm
8383
```
@@ -108,7 +108,7 @@ Browser:
108108
```typescript
109109
import { Logger } from "tslog";
110110

111-
const logger = new Logger({ name: "myLogger" });
111+
const logger = new Logger();
112112
logger.silly("I am a silly log.");
113113
logger.trace("I am a trace log.");
114114
logger.debug("I am a debug log.");
@@ -140,6 +140,9 @@ logger.fatal(new Error("I am a pretty Error with a stacktrace."));
140140

141141
## API documentation
142142

143+
> **`tslog >= v4` is a major rewrite and introduces breaking changes.** <br>
144+
> Please, follow this documentation when migrating.
145+
143146
### <a name="life_cycle"></a>Lifecycle of a log message
144147

145148
Every incoming log message runs through a number of steps before being displayed or handed over to a "transport". Every step can be overwritten and adjusted.
@@ -148,7 +151,7 @@ Every incoming log message runs through a number of steps before being displayed
148151

149152
- **log message** Log message comes in through the `BaseLogger.log()` method
150153
- **mask** If masking is configured, log message gets recursively masked
151-
- **toLogObj** Log message gets transformed into a log object: A default typed log object can be passed to constructor as a second parameter and will be cloned and enriched with the incoming log parameters. Error properties will be handled accordingly. If there is only one log property, and it's an object, both objects (cloned default `logObj` as well as the log property object will be merged.) If there are more than one, they will be put into properties called "0", "1", ... and so on. Alternatively, log message properties can be put into a property with a name configured with the `argumentsArrayName` setting.
154+
- **toLogObj** Log message gets transformed into a log object: A default typed log object can be passed to constructor as a second parameter and will be cloned and enriched with the incoming log parameters. Error properties will be handled accordingly. If there is only one log property, and it's an object, both objects (cloned default `logObj` as well as the log property object) will be merged. If there are more than one, they will be put into properties called "0", "1", ... and so on. Alternatively, log message properties can be put into a property with a name configured with the `argumentsArrayName` setting.
152155
- **addMetaToLogObj** Additional meta information, like the source code position of the log will be gathered and added to the `_meta` property or any other one configured with the setting `metaProperty`.
153156
- **format** In case of "pretty" configuration, a log object will be formatted based on the templates configured in settings. Meta will be formatted by the method `_prettyFormatLogObjMeta` and the actual log payload will be formatted by `prettyFormatLogObj`. Both steps can be overwritten with the settings `formatMeta` and `formatMeta`.
154157
- **transport** Last step is to "transport" a log message to every attached transport from the setting `attachedTransports`. Last step is the actual transport, either JSON (`transportJSON`), formatted (`transportFormatted`) or omitted, if its set to "hidden". Both default transports can also be overwritten by the corresponding setting.
@@ -157,12 +160,12 @@ Every incoming log message runs through a number of steps before being displayed
157160

158161
`tslog` comes with default log level `0: silly`, `1: trace`, `2: debug`, `3: info`, `4: warn`, `5: error`, `6: fatal`.
159162

160-
> **Tip:** Each logging method has a return type, which is a _JSON_ representation of the log message (`ILogObject`).
163+
> **Tip:** Each logging method has a return type, which is a _JSON_ representation of the log message (`ILogObj`).
161164
162165
```typescript
163166
import { Logger } from "tslog";
164167

165-
const log: Logger = new Logger();
168+
const log = new Logger();
166169
log.silly("I am a silly log.");
167170
log.trace("I am a trace log.");
168171
log.debug("I am a debug log.");
@@ -477,7 +480,7 @@ For every log:
477480
});
478481
```
479482

480-
For `pretty` logs log:
483+
For `pretty` logs:
481484
```typescript
482485
const logger = new Logger({
483486
type: "pretty",
@@ -495,7 +498,7 @@ For `pretty` logs log:
495498
});
496499
```
497500

498-
For `JSON` logs log (no formatting happens here):
501+
For `JSON` logs (no formatting happens here):
499502
```typescript
500503
const logger = new Logger({
501504
type: "pretty",
@@ -547,8 +550,27 @@ const logMsg = logger.info("Test");
547550
//}
548551
```
549552

553+
## Backwards compatibility
554+
555+
> **`tslog` follows a semantic release policy.** A major version change indicates breaking changes.<br><br>
556+
> `tslog >=4` is less limiting when it comes to configuration. There are many use cases (especially when it comes to integration with 3rd party services) that now can be achieved elegantly and were not possible before.
557+
558+
### Name and other constructor parameters
559+
560+
`tslog` < 4 had a name parameter on the constructor. v4 removed all preconfigured parameters and allows you to create your own log object (s. "Defining and accessing `logObj`").
561+
562+
**OLD:** `tslog` < 4
563+
```typescript
564+
const log: Logger = new Logger({ name: "myLogger" });
565+
```
566+
567+
**NEW:** `tslog` >= 4
568+
```typescript
569+
const log = new Logger({ type: "json" }, { name: "DefaultLogger" });
570+
```
571+
550572

551-
### Tip: RequestID: Mark a request (e.g. HTTP) call with AsyncLocalStorage and `tslog`
573+
### RequestID: Mark a request (e.g. HTTP) call with AsyncLocalStorage and `tslog`
552574
>**Node.js 13.10 introduced a new feature called <a href="https://nodejs.org/api/async_hooks.html#async_hooks_class_asynclocalstorage" target="_blank">AsyncLocalStorage.</a>**<br>
553575
554576
**❗ Keep track of all subsequent calls and promises originated from a single request (e.g. HTTP).**

examples/nodejs/index2.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,7 @@ jsonLoggerArgumentsArray.silly("test");
4646
jsonLoggerArgumentsArray.silly("test1", "test2");
4747

4848
////////////////////////////
49+
50+
const log = new Logger({ type: "json" }, { name: "DefaultLogger" });
51+
52+
log.silly("foo bar");

0 commit comments

Comments
 (0)