@thi.ng/logger
Advanced tools
Comparing version 1.3.1 to 1.4.0
# Change Log | ||
- **Last updated**: 2022-10-03T16:07:55Z | ||
- **Last updated**: 2022-10-04T10:33:14Z | ||
- **Generator**: [thi.ng/monopub](https://thi.ng/monopub) | ||
@@ -12,2 +12,10 @@ | ||
## [1.4.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/logger@1.4.0) (2022-10-04) | ||
#### 🚀 Features | ||
- add lazy arg evaluation ([21ead9c](https://github.com/thi-ng/umbrella/commit/21ead9c)) | ||
- add internal expandArgs() helper to expand any fn message args | ||
- update ConsoleLogger & MemoryLogger | ||
## [1.3.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/logger@1.3.0) (2022-09-21) | ||
@@ -14,0 +22,0 @@ |
import { ALogger } from "./alogger.js"; | ||
import { LogLevel } from "./api.js"; | ||
import { expandArgs } from "./utils.js"; | ||
/** | ||
@@ -8,4 +9,4 @@ * {@link ILogger} implementation writing messages via `console.log`. | ||
log(level, args) { | ||
console.log(`[${LogLevel[level]}] ${this.id}:`, ...args); | ||
console.log(`[${LogLevel[level]}] ${this.id}:`, ...expandArgs(args)); | ||
} | ||
} |
import { ALogger } from "./alogger.js"; | ||
import { expandArgs } from "./utils.js"; | ||
export class MemoryLogger extends ALogger { | ||
@@ -28,4 +29,4 @@ constructor(id, level, limit = 1e3) { | ||
this.journal.shift(); | ||
this.journal.push([level, this.id, Date.now(), ...args]); | ||
this.journal.push([level, this.id, Date.now(), ...expandArgs(args)]); | ||
} | ||
} |
{ | ||
"name": "@thi.ng/logger", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Types & basis infrastructure for arbitrary logging (w/ default impls)", | ||
@@ -89,3 +89,3 @@ "type": "module", | ||
}, | ||
"gitHead": "8600007d81a7dc92634a1d54e2c32b14ab30ba80\n" | ||
"gitHead": "6f14e9de72c701f9c3c12d2e1bbd34a5dc86197a\n" | ||
} |
@@ -13,2 +13,5 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
- [About](#about) | ||
- [Log levels](#log-levels) | ||
- [Supplied implementations](#supplied-implementations) | ||
- [Lazy evaluation](#lazy-evaluation) | ||
- [Status](#status) | ||
@@ -27,2 +30,54 @@ - [Related packages](#related-packages) | ||
The types & implementations provided by this package are used in various places | ||
throughout the thi.ng/umbrella ecosystem and can be swapped out on demand to | ||
customize users' needs. | ||
### Log levels | ||
All loggers based on this basic framework provided by this package support the | ||
following [`LogLevel`](https://docs.thi.ng/umbrella/logger/enums/LogLevel.html)s | ||
(in order of importance): | ||
- `FINE` | ||
- `DEBUG` | ||
- `INFO` | ||
- `WARN` | ||
- `SEVERE` | ||
Logging calls targetting lower levels than configured in the logger will be | ||
ignored. | ||
### Supplied implementations | ||
The following logger implementations are provided: | ||
- [`ConsoleLogger`](https://docs.thi.ng/umbrella/logger/classes/ConsoleLogger.html): writes output to `console` | ||
- [`MemoryLogger`](https://docs.thi.ng/umbrella/logger/classes/MemoryLogger.html): writes output to in-memory journal | ||
- [`NULL_LOGGER`](https://docs.thi.ng/umbrella/logger/modules.html#NULL_LOGGER): no-op logger, suppresses all output | ||
### Lazy evaluation | ||
Log messages can contain any number & types of arguments. No-arg functions can | ||
be provided as message arg to avoid evaluation of potentially costly message | ||
formatting for suppressed log levels. For example: | ||
```ts | ||
import { ConsoleLogger, LogLevel } from "@thi.ng/logger"; | ||
const logger = new ConsoleLogger("app", LogLevel.INFO); | ||
const name = "thi.ng"; | ||
// eager (standard) arg evaluation | ||
logger.info(`hello, ${name}`); | ||
// [INFO] app: hello, thi.ng | ||
// eager (standard) arg evaluation, but suppressed output | ||
logger.debug("result is", 23 + 42); | ||
// lazy arg evaluation | ||
logger.info("result is", () => 23 + 42); | ||
// [INFO] app: result is 65 | ||
``` | ||
## Status | ||
@@ -61,3 +116,3 @@ | ||
Package sizes (gzipped, pre-treeshake): ESM: 529 bytes | ||
Package sizes (gzipped, pre-treeshake): ESM: 553 bytes | ||
@@ -64,0 +119,0 @@ ## Dependencies |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27046
18
193
157