Skip to content

Commit 2a04c4b

Browse files
authored
feat(log): Add MemoryLog class (#11)
1 parent 0123ab7 commit 2a04c4b

File tree

14 files changed

+793
-474
lines changed

14 files changed

+793
-474
lines changed

docs/modules/log/log.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ A simple console wrapper with a host of features
88
* Image logging - In Chrome console, it is possible log images
99
* Improved `assert` messages - Reformats errors from `assert` to show actual error string
1010

11+
## Logger implementations
12+
13+
`@probe.gl/log` exports a few logger classes:
14+
15+
- `ProbeLog` is the full-featured logger with log levels, persistence, and formatting controls. It is exported as `Log` and provided as the default instance export. (It was previously named `ConsoleLog`.)
16+
- `ConsoleLog` is a minimal wrapper around the runtime `console`, intended for situations where you want the `Logger` interface without configuration or persistence.
17+
- `MemoryLog` records messages in memory, typically for tests, and accepts an optional `onMessage` callback that fires when a new message is stored.
18+
- `BaseLog` is a shared base class you can extend to build new `Logger` implementations with consistent log-level handling and `once` de-duplication.
19+
1120

1221
## Installing
1322

@@ -129,6 +138,8 @@ Log a normal message, but only once, no console flooding
129138

130139
Returns: a function closure that should be called immediately.
131140

141+
Calling `once` multiple times with the same message will only log the first call for both `ProbeLog`/`Log` and the lightweight `ConsoleLog`. The `MemoryLog` implementation also mirrors this behavior by capturing a single entry.
142+
132143

133144
### probe
134145

@@ -250,4 +261,3 @@ Provides an exception safe way to run some code within a group
250261
### trace
251262

252263
Prints a stack trace
253-

docs/whats-new.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# What's New
22

3+
## v4.1 (Unreleased)
4+
5+
- **@probe.gl/log** - Renamed the feature-rich `ConsoleLog` class to `ProbeLog` (still exported as `Log` and as the default instance) and added a lightweight `ConsoleLog` wrapper around the runtime console, with shared behavior factored into a new `BaseLog`.
6+
- **@probe.gl/log** - Added per-logger `once` caching to both the lightweight `ConsoleLog` and `MemoryLog` implementations, and `MemoryLog` now supports an `onMessage` callback that fires when new messages are recorded.
7+
38
## v4.0
49

510
Release Date: Feb 10, 2023

modules/log/src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import {Log} from './log';
1+
import {ProbeLog} from './loggers/probe-log';
22

33
// DEFAULT EXPORT IS A LOG INSTANCE
4-
export default new Log({id: '@probe.gl/log'});
4+
export default new ProbeLog({id: '@probe.gl/log'});
55

66
// LOGGING
7-
export {Log} from './log';
8-
export {COLOR} from './utils/color';
7+
export type {Logger} from './loggers/logger';
8+
export {ProbeLog, ProbeLog as Log} from './loggers/probe-log';
9+
export {ConsoleLog} from './loggers/console-log';
10+
export {BaseLog} from './loggers/base-log';
11+
export type {MemoryLogMessage} from './loggers/memory-log';
12+
export {MemoryLog} from './loggers/memory-log';
913

1014
// UTILITIES
15+
export {COLOR} from './utils/color';
1116
export {addColor} from './utils/color';
1217
export {leftPad, rightPad} from './utils/formatters';
1318
export {autobind} from './utils/autobind';

0 commit comments

Comments
 (0)