@webex/plugin-logger 3.12.0-next.56 → 3.12.0-next.57
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.repo-context.json +389 -0
- package/.sdd/manifest.json +334 -0
- package/AGENTS.md +175 -0
- package/dist/logger.js +1 -1
- package/docs/adr/0001-retain-product-readme.md +76 -0
- package/docs/adr/index.md +18 -0
- package/docs/architecture.md +252 -0
- package/docs/getting-started.md +88 -0
- package/docs/index.md +42 -0
- package/docs/specs/README.md +65 -0
- package/package.json +2 -2
- package/schemas/repo-context.schema.json +796 -0
- package/src/docs/README.md +320 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
---
|
|
2
|
+
type: Module Spec
|
|
3
|
+
title: 'Logger plugin specification'
|
|
4
|
+
description: Responsibilities, boundaries, design, invariants, and verification for the logger plugin module.
|
|
5
|
+
tags: [module, specification]
|
|
6
|
+
---
|
|
7
|
+
<!-- sdd-generated-metadata
|
|
8
|
+
doc_kind: module-spec
|
|
9
|
+
generated_from: module-spec@0.3.0
|
|
10
|
+
generated_by: claude-cowork
|
|
11
|
+
approved_by: akulakum@cisco.com
|
|
12
|
+
updated_at: 2026-10-08T08:51:39Z
|
|
13
|
+
validation_status: pass-with-warnings
|
|
14
|
+
-->
|
|
15
|
+
|
|
16
|
+
# Logger plugin
|
|
17
|
+
|
|
18
|
+
This source-local document at `src/docs/README.md` owns the stable specification for **the logger plugin**. Ground every claim in package evidence and link to the [package architecture](../../docs/architecture.md) instead of repeating broader facts.
|
|
19
|
+
|
|
20
|
+
Related context: [documentation index](../../docs/index.md) · [package agent instructions](../../AGENTS.md)
|
|
21
|
+
|
|
22
|
+
## Metadata
|
|
23
|
+
|
|
24
|
+
| Field | Value |
|
|
25
|
+
| ----------------- | ----- |
|
|
26
|
+
| Owner | @webex/web-client, @webex/web-sdk |
|
|
27
|
+
| Source path | `src` |
|
|
28
|
+
| Resource kind | package |
|
|
29
|
+
| Status | Draft |
|
|
30
|
+
| Last verified | 2026-10-06 at `94dd92abed` |
|
|
31
|
+
| Module id | `plugin-logger` |
|
|
32
|
+
| Parent spec | — |
|
|
33
|
+
| Doc kind | Module spec |
|
|
34
|
+
| Coverage score | 93.8% assessed 2026-10-06 — 15 of 16 mandatory fields PRESENT, critical 8 of 8; test strategy is WEAK because registration, the catch branch, group indentation, and known redaction gaps are untested |
|
|
35
|
+
| Validation status | pass-with-warnings — 2026-10-08; validator runtime `current-session` |
|
|
36
|
+
|
|
37
|
+
## Applicability
|
|
38
|
+
|
|
39
|
+
| Condition ID | Status | Evidence or reason | Owned section |
|
|
40
|
+
| ------------------------------------ | ---------- | ------------------ | ------------- |
|
|
41
|
+
| `module.has_tiers` | N/A | No tier policy in this package | Tier |
|
|
42
|
+
| `module.has_ui` | N/A | No view or screen. Output goes to `console` and an in-memory buffer. | UI use-case flow |
|
|
43
|
+
| `module.crosses_service_boundaries` | N/A | `src/` makes no network call. Upload is done by the sibling package internal-plugin-support. | Cross-boundary use-case flow |
|
|
44
|
+
| `module.holds_client_state` | Applicable | `buffer`, `sdkBuffer`, `clientBuffer`, and `groupLevel` are session properties in `src/logger.js` | Client state model |
|
|
45
|
+
| `module.enforces_domain_rules` | Applicable | Level precedence, buffer threshold, and redaction rules in `src/logger.js` | Business rules and invariants |
|
|
46
|
+
| `module.is_concurrent_async` | N/A | Every method is synchronous. No promise, timer, or event subscription in `src/`. | Concurrency and reactive flow |
|
|
47
|
+
| `module.owns_persistence` | N/A | Buffers live in memory only. Nothing is written to storage. | Data, schema, and migration discipline |
|
|
48
|
+
| `module.stateful_transitions` | N/A | Buffer cursors are covered under Client state model. There is no named state machine. | State machine |
|
|
49
|
+
| `module.exposes_wire_protocol` | Applicable | `formatLogs()` output is the log text that the sibling package internal-plugin-support uploads | Protocol and wire format |
|
|
50
|
+
| `module.ui_multi_screen` | N/A | No UI | UI flow |
|
|
51
|
+
| `module.large_data_model` | N/A | One buffer record shape and seven config keys | Data model |
|
|
52
|
+
| `module.returns_caller_errors` | N/A | Log methods catch every internal error and return `undefined`. No method throws to the caller. | Caller-visible failure modes |
|
|
53
|
+
| `module.module_specific_conventions` | Applicable | `client_` method prefix, `wx-js-sdk` name, and redaction-before-output rules | Module-specific rules |
|
|
54
|
+
| `module.published_package` | Applicable | `package.json` names the package and `deploy:npm` publishes it | Export stability |
|
|
55
|
+
| `module.embedded_in_host` | N/A | No host theme or embed API | Host integration and theming |
|
|
56
|
+
| `module.has_design_tradeoff` | Applicable | `debug` and `trace` are excluded from the buffer by default; browsers print stringified values | Key design trade-off |
|
|
57
|
+
| `module.has_submodules` | N/A | Computed false by the Repo Annotation module_tree.py script. `src/config.js` is a helper file, not a child module. | Sub-modules |
|
|
58
|
+
|
|
59
|
+
## Evidence register
|
|
60
|
+
|
|
61
|
+
| Evidence | What it establishes |
|
|
62
|
+
| -------- | ------------------- |
|
|
63
|
+
| `src/index.js` | Plugin registration with `replace: true` and the public re-exports |
|
|
64
|
+
| `src/logger.js` | Level precedence, console fallbacks, redaction, buffering, formatting, and buffer cursors |
|
|
65
|
+
| `src/config.js` | Default `logger.level` and `logger.historyLength` |
|
|
66
|
+
| `package.json` | Name, entry points, dependencies, and scripts |
|
|
67
|
+
| `test/unit/spec/logger.js` | Unit cases for printing, buffering, redaction, level resolution, formatting, and cursors |
|
|
68
|
+
| Sibling package webex-core, file src/plugins/logger.js | Fallback logger that this plugin replaces |
|
|
69
|
+
| Sibling package webex-core, file src/lib/webex-core-plugin-mixin.js | `replace` and `config` handling inside `registerPlugin` |
|
|
70
|
+
| Sibling package common, SDD module spec src/docs/README.md | Specification of the consumed `inBrowser` and `patterns` exports |
|
|
71
|
+
| Sibling package internal-plugin-support, file src/support.js | Consumer of `formatLogs`, `updateLastSubmittedIndex`, and `resetBufferToLastSuccessfulUpload` |
|
|
72
|
+
| Product README | Retained as product documentation. Not the behavioral authority. See ADR 0001. |
|
|
73
|
+
|
|
74
|
+
## Purpose and boundary
|
|
75
|
+
|
|
76
|
+
- Responsibility: give every Webex SDK plugin a `webex.logger` with leveled console output, redaction of sensitive values, and bounded in-memory buffers that can be formatted for upload.
|
|
77
|
+
- Ownership: this package owns level resolution, redaction, buffering, buffer trimming, and the formatted log text. It does not own upload, transport, or log retention on a server.
|
|
78
|
+
- In scope: the `Logger` plugin, the `levels` export, the default config in `src/config.js`, and the registration side effect in `src/index.js`.
|
|
79
|
+
- Out of scope: sending logs (owned by `@webex/internal-plugin-support`), the `WebexHttpError` redaction that this module relies on for errors (owned by `@webex/webex-core`), and the regular expressions themselves (owned by `@webex/common`).
|
|
80
|
+
- Consumers: every package that reads `webex.logger`. Fourteen workspace packages list `@webex/plugin-logger` in `package.json`, including `webex`, `webex-node`, `@webex/webex-core` (tests), and `@webex/contact-center`.
|
|
81
|
+
|
|
82
|
+
## Structure and key files
|
|
83
|
+
|
|
84
|
+
| Path | Responsibility |
|
|
85
|
+
| ---- | -------------- |
|
|
86
|
+
| `src/index.js` | Calls `registerPlugin('logger', Logger, {config, replace: true})` and re-exports `default` and `levels` from `./logger` |
|
|
87
|
+
| `src/logger.js` | `Logger` plugin definition, `levels`, private `walkAndFilter`, private `makeLoggerMethod`, and generated level methods |
|
|
88
|
+
| `src/config.js` | Default `logger` config merged into webex config at registration |
|
|
89
|
+
| `test/unit/spec/logger.js` | Single unit spec, run by jest (`test:unit`) and karma (`test:browser`) |
|
|
90
|
+
|
|
91
|
+
## Public surface
|
|
92
|
+
|
|
93
|
+
Declarations live in `src/index.js` and `src/logger.js`. This section summarises them and does not restate signatures.
|
|
94
|
+
|
|
95
|
+
| Surface | Consumer | Compatibility commitment | Source |
|
|
96
|
+
| ------- | -------- | ------------------------ | ------ |
|
|
97
|
+
| default export `Logger` | `webex`, `webex-node`, and tests that build a `MockWebex` with `children: {logger: Logger}` | Constructor registered as the `logger` child plugin | `src/logger.js` |
|
|
98
|
+
| `levels` | tests and callers that iterate levels | `['group', 'groupEnd', 'error', 'warn', 'log', 'info', 'debug', 'trace']`. `silent` is not included. | `src/logger.js` |
|
|
99
|
+
| `webex.logger.<level>(...args)` for each entry in `levels` | all SDK plugins | Prints and buffers as SDK type with name `wx-js-sdk` | `src/logger.js` |
|
|
100
|
+
| `webex.logger.client_<level>(...args)` for each entry in `levels` | client applications | Prints and buffers as client type with name `config.clientName`, or `client` when unset | `src/logger.js` |
|
|
101
|
+
| `logToBuffer(...args)`, `client_logToBuffer(...args)` | callers that must buffer without printing | Never print. Always buffer. | `src/logger.js` |
|
|
102
|
+
| `formatLogs({diff})` | `@webex/internal-plugin-support` | Returns buffered entries joined by newlines. See Protocol and wire format. | `src/logger.js` |
|
|
103
|
+
| `updateLastSubmittedIndex()` | `@webex/internal-plugin-support` after a successful upload | Copies `nextIndex` to `lastSubmitted` on every active buffer | `src/logger.js` |
|
|
104
|
+
| `resetBufferToLastSuccessfulUpload()` | `@webex/internal-plugin-support` after a failed diff upload | Copies `lastSubmitted` back to `nextIndex` | `src/logger.js` |
|
|
105
|
+
| `level`, `client_level` | readers of the effective level | Derived, uncached, equal to `getCurrentLevel()` and `getCurrentClientLevel()` | `src/logger.js` |
|
|
106
|
+
| `config.logger` keys | SDK integrators | `level`, `clientLevel`, `bufferLogLevel`, `historyLength`, `clientHistoryLength`, `separateLogBuffers`, `clientName` | `src/logger.js`, `src/config.js` |
|
|
107
|
+
|
|
108
|
+
`filter`, `shouldPrint`, `shouldBuffer`, `getCurrentLevel`, and `getCurrentClientLevel` are prototype methods marked `@private` in JSDoc. Tests call them directly, so they are reachable but carry no compatibility promise.
|
|
109
|
+
|
|
110
|
+
Contract `plugin-logger-sdk` is published and its native artifact is `package.json`. Contract `log-buffer-format` is internal and its source is `src/logger.js`. Required contracts are `webex-core-plugin-host`, `webex-common-js-api`, and `lodash`.
|
|
111
|
+
|
|
112
|
+
## Dependencies
|
|
113
|
+
|
|
114
|
+
| Dependency | Why |
|
|
115
|
+
| ---------- | --- |
|
|
116
|
+
| `@webex/webex-core` | `WebexPlugin.extend` base, `registerPlugin`, and the optional `webex.internal.device.features.developer` toggle |
|
|
117
|
+
| `@webex/common` | `inBrowser` selects stringified console output; `patterns.containsEmails` and `patterns.containsMTID` drive string redaction. Specified in `packages/@webex/common/src/docs/README.md`. |
|
|
118
|
+
| `lodash` | `cloneDeep` before redaction; `has`, `isArray`, `isObject`, and `isString` checks |
|
|
119
|
+
| `console` | Output target. Missing methods fall back through `fallbacks` in `src/logger.js`. |
|
|
120
|
+
| `@webex/test-helper-chai`, `@webex/test-helper-mocha`, `@webex/test-helper-mock-webex` | Listed under `dependencies` and `devDependencies`, but imported only by `test/` |
|
|
121
|
+
|
|
122
|
+
## Requirements
|
|
123
|
+
|
|
124
|
+
| ID | What | Why | Evidence | Verification | Confidence |
|
|
125
|
+
| -- | ---- | --- | -------- | ------------ | ---------- |
|
|
126
|
+
| MOD-001 | Importing the package registers `Logger` as the `logger` plugin with `replace: true` and merges `src/config.js` into webex config. | `@webex/webex-core` registers a fallback logger first. Without `replace`, `registerPlugin` returns early and the fallback stays. | `src/index.js`; webex-core src/lib/webex-core-plugin-mixin.js | No direct test. Unit spec builds the plugin through `MockWebex` instead. | High |
|
|
127
|
+
| MOD-002 | The SDK level resolves in this order: truthy `config.level`; `WEBEX_LOG_LEVEL` when it is in `levels`; `trace` when `NODE_ENV` is `test`; the developer feature `log-level` when it is in `levels`; otherwise the default level (`INV-003`). | Integrators and server toggles can raise verbosity without code changes. | `src/logger.js` `getCurrentLevel` | `#shouldPrint()` cases: `prefers the config specified logger.level`, `uses the WEBEX_LOG_LEVEL environment varable`, `logs at TRACE in test environments`, `checks the developer feature toggle`, `defaults to "error"` | High |
|
|
128
|
+
| MOD-003 | The client level is `config.clientLevel` when truthy, otherwise the SDK level. | Client apps can log at a different level from the SDK. | `src/logger.js` `getCurrentClientLevel` | `factors in log type when passed in as client` | High |
|
|
129
|
+
| MOD-004 | A message prints when `precedence[level] <= precedence[current level]` for its type. | One ordered scale controls output. | `src/logger.js` `shouldPrint` | `indicates whether or not the desired log should be printed` | High |
|
|
130
|
+
| MOD-005 | A message is buffered when `precedence[level] <= precedence[config.bufferLogLevel]`, or the default threshold (`INV-002`) when `bufferLogLevel` is unset, independent of the print level. | The upload buffer keeps a level set chosen for support, separate from developer console output. Rationale and cost are under Key design trade-off. | `src/logger.js` `shouldBuffer` | `#shouldBuffer()` cases | High |
|
|
131
|
+
| MOD-006 | Before output, every non-`Error` argument is deep-cloned, authorization keys (`INV-004`) are deleted, email addresses are replaced with `[REDACTED]`, and MTID values become `MTID=[REDACTED]`. | Tokens and personal data must not reach the console or the uploaded buffer. | `src/logger.js` `filter` and `walkAndFilter` | `#filter`, `removes authorization data`, `#walkAndFilter` cases | High |
|
|
132
|
+
| MOD-007 | `Error` arguments bypass redaction. In the buffer they become `toString()`. | The source comment states `WebexHttpError` already removes tokens. | `src/logger.js` `filter` and `makeLoggerMethod` | `buffers custom errors in a readable fashion`, `formats Errors correctly` | Medium |
|
|
133
|
+
| MOD-008 | Object arguments are `JSON.stringify`-ed with repeated object references dropped. A stringify failure yields `Failed to stringify: <value>`. | Buffers and browser output hold a snapshot, not a live reference. | `src/logger.js` `makeLoggerMethod` | `formats objects as strings`, `w/ circular reference`, `handle circular references` | High |
|
|
134
|
+
| MOD-009 | On overflow (`INV-006`), the oldest entries are removed and `nextIndex` and `lastSubmitted` are reduced by the removed count, clamped at 0. | Diff uploads keep pointing at the same entries after trimming. | `src/logger.js` `makeLoggerMethod` | `prevents the buffer from overflowing`, `adjusts lastSubmitted when buffer overflows`, `clamps lastSubmitted to 0`, `limit` cases | High |
|
|
135
|
+
| MOD-010 | With `separateLogBuffers`, SDK methods write to `sdkBuffer` and `client_` methods write to `clientBuffer`. Otherwise both write to `buffer`. | Client and SDK logs can be capped separately. | `src/logger.js` `makeLoggerMethod` | `stores the specified message in the client and sdk log buffer`, `prevents the client and sdk buffer from overflowing` | High |
|
|
136
|
+
| MOD-011 | `formatLogs({diff: true})` returns only entries from `nextIndex` onward and advances `nextIndex`. With separate buffers, entries are merged in timestamp order and an SDK entry wins a tie. | Support uploads send only new logs per interval in time order. | `src/logger.js` `formatLogs` | `#formatLogs()` and `diff vs full logs` cases | High |
|
|
137
|
+
| MOD-012 | `updateLastSubmittedIndex()` sets `lastSubmitted = nextIndex`. `resetBufferToLastSuccessfulUpload()` sets `nextIndex = lastSubmitted`. Both act on the active buffer set. | A failed upload can be retried at the next interval without losing logs. | `src/logger.js`; internal-plugin-support src/support.js | `#updateLastSubmittedIndex()` and `#resetBufferToLastSuccessfulUpload()` cases | High |
|
|
138
|
+
| MOD-013 | `logToBuffer` and `client_logToBuffer` never print and always buffer. | Callers can record context for upload without console noise. | `src/logger.js` | `#logToBuffer()` cases | High |
|
|
139
|
+
| MOD-014 | A log method never throws. An internal error prints `failed to execute Logger#<level>` through `console.warn` unless the method is a never-print method. | Logging must not break the caller. | `src/logger.js` `makeLoggerMethod` | Gap: no test forces the catch branch | Medium |
|
|
140
|
+
| MOD-015 | When a console method is absent, the method is chosen by popping the `fallbacks` list from its end: `error` uses `log`; `warn` tries `log`, then `error`; `info` uses `log`; `debug` tries `log`, then `info`; `trace` tries `log`, `info`, then `debug`. `group` and `groupEnd` have no fallback. | Older or partial consoles still receive output. | `src/logger.js` `fallbacks` | Unit spec computes the same table to pick spies | Medium |
|
|
141
|
+
|
|
142
|
+
## Design overview
|
|
143
|
+
|
|
144
|
+
`Logger` is an Ampersand-style `WebexPlugin` with three buffer objects and a `groupLevel` counter as session state. At module load, `src/logger.js` loops over `levels` and installs two methods per level on the prototype, `<level>` and `client_<level>`, each built by `makeLoggerMethod`. Two more, `logToBuffer` and `client_logToBuffer`, are built with `neverPrint` and `alwaysBuffer` set.
|
|
145
|
+
|
|
146
|
+
Every generated method follows the same pipeline: pick the buffer and history length from config, decide print and buffer independently, redact, stringify, print, then append and trim. Config is read on each call rather than captured at construction. The source comment explains that Ampersand config is not fully initialized when the methods are bound.
|
|
147
|
+
|
|
148
|
+
The plugin keeps no timers and does no I/O. Upload, scheduling, and retries belong to `@webex/internal-plugin-support`.
|
|
149
|
+
|
|
150
|
+
## Data flow and sequence coverage
|
|
151
|
+
|
|
152
|
+
Transport is a synchronous in-process method call. There are two operation groups: writing a log entry, and reading the buffer for upload.
|
|
153
|
+
|
|
154
|
+
Write a log entry:
|
|
155
|
+
|
|
156
|
+
```mermaid
|
|
157
|
+
sequenceDiagram
|
|
158
|
+
participant Caller
|
|
159
|
+
participant Method as Logger level method
|
|
160
|
+
participant Filter as filter and walkAndFilter
|
|
161
|
+
participant Console
|
|
162
|
+
participant Buffer as active buffer
|
|
163
|
+
Caller->>Method: level(...args)
|
|
164
|
+
Method->>Method: shouldPrint and shouldBuffer
|
|
165
|
+
alt neither print nor buffer
|
|
166
|
+
Method-->>Caller: return
|
|
167
|
+
else print or buffer
|
|
168
|
+
Method->>Filter: clone and redact args
|
|
169
|
+
Filter-->>Method: filtered args
|
|
170
|
+
Method->>Method: stringify objects and Errors
|
|
171
|
+
opt shouldPrint
|
|
172
|
+
Method->>Console: console method with name and values
|
|
173
|
+
end
|
|
174
|
+
opt shouldBuffer
|
|
175
|
+
Method->>Buffer: push [indent, ISO time, name, ...values]
|
|
176
|
+
Method->>Buffer: trim oldest and shift cursors
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
alt internal error and method can print
|
|
180
|
+
Method->>Console: console.warn failed to execute Logger#level
|
|
181
|
+
end
|
|
182
|
+
Method-->>Caller: undefined
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
Read the buffer for upload (caller is `@webex/internal-plugin-support`):
|
|
186
|
+
|
|
187
|
+
```mermaid
|
|
188
|
+
sequenceDiagram
|
|
189
|
+
participant Support as internal-plugin-support
|
|
190
|
+
participant Logger
|
|
191
|
+
Support->>Logger: formatLogs({diff})
|
|
192
|
+
Logger-->>Support: newline-joined text
|
|
193
|
+
Note over Logger: diff advances nextIndex
|
|
194
|
+
alt upload succeeds
|
|
195
|
+
Support->>Logger: updateLastSubmittedIndex()
|
|
196
|
+
else upload fails, diff, retryFailedLogUploadsAtNextInterval
|
|
197
|
+
Support->>Logger: resetBufferToLastSuccessfulUpload()
|
|
198
|
+
end
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
## Class and component relationships
|
|
202
|
+
|
|
203
|
+
```mermaid
|
|
204
|
+
classDiagram
|
|
205
|
+
class WebexPlugin
|
|
206
|
+
class Logger {
|
|
207
|
+
+level
|
|
208
|
+
+client_level
|
|
209
|
+
+buffer
|
|
210
|
+
+sdkBuffer
|
|
211
|
+
+clientBuffer
|
|
212
|
+
+groupLevel
|
|
213
|
+
+formatLogs(options)
|
|
214
|
+
+updateLastSubmittedIndex()
|
|
215
|
+
+resetBufferToLastSuccessfulUpload()
|
|
216
|
+
+logToBuffer()
|
|
217
|
+
+client_logToBuffer()
|
|
218
|
+
}
|
|
219
|
+
WebexPlugin <|-- Logger
|
|
220
|
+
Logger ..> walkAndFilter : redacts with
|
|
221
|
+
Logger ..> makeLoggerMethod : methods built by
|
|
222
|
+
walkAndFilter ..> patterns : uses
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
| Component | Relationship |
|
|
226
|
+
| --------- | ------------ |
|
|
227
|
+
| `Logger` | Subclass created with `WebexPlugin.extend`; owns the session state and the public methods |
|
|
228
|
+
| `makeLoggerMethod` | Module-private factory. Creates every level method and closes over `level`, `impl`, `type`, `neverPrint`, and `alwaysBuffer`. |
|
|
229
|
+
| `walkAndFilter` | Module-private recursive redactor used by `Logger#filter` |
|
|
230
|
+
| `src/config.js` | Supplied to `registerPlugin` as `options.config` |
|
|
231
|
+
|
|
232
|
+
## Use cases and flows
|
|
233
|
+
|
|
234
|
+
1. An SDK plugin calls `this.logger.info('...')`. With the default `error` level the call does not print, but the entry is buffered because `info` is within the default buffer threshold.
|
|
235
|
+
2. A developer sets `WEBEX_LOG_LEVEL=debug` before load or `config.logger.level = 'debug'`. `debug` now prints. It is still not buffered unless `bufferLogLevel` is `debug` or `trace`.
|
|
236
|
+
3. A client app sets `separateLogBuffers: true` and `clientName: 'someclient'`, then calls `client_log`. The entry goes to `clientBuffer` with name `someclient`.
|
|
237
|
+
4. `@webex/internal-plugin-support` calls `formatLogs({diff: true})`, uploads, and on success calls `updateLastSubmittedIndex()`. On a failed diff upload with `retryFailedLogUploadsAtNextInterval`, it calls `resetBufferToLastSuccessfulUpload()` so the next diff includes the failed span.
|
|
238
|
+
5. A caller logs an object with `headers.authorization`. The printed and buffered values omit that key; the caller's original object is not mutated because the logger redacts a deep clone.
|
|
239
|
+
6. A caller writes `logToBuffer('context')`. Nothing prints; the entry is buffered.
|
|
240
|
+
|
|
241
|
+
## Client state model
|
|
242
|
+
|
|
243
|
+
| State or slice | Owner | Initial state | Transition triggers | Reset or persistence boundary |
|
|
244
|
+
| -------------- | ----- | ------------- | ------------------- | ----------------------------- |
|
|
245
|
+
| `buffer` | `Logger` session | `{buffer: [], nextIndex: 0, lastSubmitted: 0}` | Any buffered call when `separateLogBuffers` is falsy | In memory for the plugin instance. Trimmed to `historyLength`. |
|
|
246
|
+
| `sdkBuffer` | `Logger` session | Same shape | Buffered SDK-type call when `separateLogBuffers` is truthy | Trimmed to `clientHistoryLength` or `historyLength` |
|
|
247
|
+
| `clientBuffer` | `Logger` session | Same shape | Buffered `client_` call when `separateLogBuffers` is truthy | Trimmed to `clientHistoryLength` or `historyLength` |
|
|
248
|
+
| `nextIndex` per buffer | `Logger` | `0` | Advanced by `formatLogs({diff: true})`; set back by `resetBufferToLastSuccessfulUpload()`; reduced by trimming | Clamped at `0` after trimming |
|
|
249
|
+
| `lastSubmitted` per buffer | `Logger` | `0` | Set by `updateLastSubmittedIndex()`; reduced by trimming | Clamped at `0` after trimming |
|
|
250
|
+
| `groupLevel` | `Logger` session | `0` | `+1` after a buffered `group`; `-1` after a buffered `groupEnd` when above `0` | Only changes when the call was buffered |
|
|
251
|
+
|
|
252
|
+
## Business rules and invariants
|
|
253
|
+
|
|
254
|
+
| ID | Invariant | WHY | Enforcement source | Test evidence |
|
|
255
|
+
| -- | --------- | --- | ------------------ | ------------- |
|
|
256
|
+
| `INV-001` | Precedence is `silent 0`, `group 1`, `groupEnd 2`, `error 3`, `warn 4`, `log 5`, `info 6`, `debug 7`, `trace 8`. | Single ordered scale for print and buffer decisions | `src/logger.js` `precedence` | `#shouldPrint()` table |
|
|
257
|
+
| `INV-002` | Default buffer threshold is `info`. | Keep uploaded logs focused | `src/logger.js` `shouldBuffer` | `logs info level to buffer by default`, `does not log debug level to buffer by default` |
|
|
258
|
+
| `INV-003` | Default fallback SDK level is `error`. | Quiet console for end users | `src/logger.js` `getCurrentLevel` | `defaults to "error" for all other users` |
|
|
259
|
+
| `INV-004` | Keys matching `/[Aa]uthorization/` are removed from cloned arguments at any depth. | Never emit bearer tokens | `src/logger.js` `authTokenKeyPattern` | `strips auth headers from log output`, `redact Authorization` |
|
|
260
|
+
| `INV-005` | SDK-type entries use the name `wx-js-sdk`. | Uploaded logs can separate SDK and client lines | `src/logger.js` `SDK_LOG_TYPE_NAME` | `removes authorization data` asserts `wx-js-sdk` |
|
|
261
|
+
| `INV-006` | Buffer length never exceeds the history length after a write. | Bounded memory | `src/logger.js` `makeLoggerMethod` | `prevents the buffer from overflowing` |
|
|
262
|
+
| `INV-007` | Default `historyLength` is `10000`. | Default retention size | `src/config.js` | Gap: the unit spec sets `historyLength` explicitly |
|
|
263
|
+
|
|
264
|
+
## Protocol and wire format
|
|
265
|
+
|
|
266
|
+
| Message or frame | Version | Producer or serializer | Consumer or parser | Compatibility and ordering rule |
|
|
267
|
+
| ---------------- | ------- | ---------------------- | ------------------ | ------------------------------- |
|
|
268
|
+
| Buffer entry | Unversioned | `src/logger.js` `makeLoggerMethod` | `src/logger.js` `formatLogs` | Array `[indent, isoTimestamp, name, ...values]`. `indent` is `'| '` repeated `groupLevel` times. Objects are JSON strings, `Error` values are `toString()`, and other values are kept as-is. `formatLogs` reads the timestamp at index 1. |
|
|
269
|
+
| Formatted log text | Unversioned | `src/logger.js` `formatLogs` | internal-plugin-support src/support.js (sibling package) | Entries joined with `\n`. Each entry is converted by `Array#toString`, so fields are comma-joined. Ascending by timestamp when buffers are merged. |
|
|
270
|
+
|
|
271
|
+
Changing the entry order or the timestamp index breaks `formatLogs` merging and the unit spec, which splits lines on `,` and reads index 3.
|
|
272
|
+
|
|
273
|
+
## Pitfalls and constraints
|
|
274
|
+
|
|
275
|
+
- `walkAndFilter` stores primitives in its `visited` list. A string value identical to one already visited in the same call is returned without email or MTID redaction. Executing a copy of `walkAndFilter` with the `@webex/common` patterns gives `{a: '[REDACTED]', b: 'x@y.com'}` for `{a: 'x@y.com', b: 'x@y.com'}`. No unit test covers repeated strings.
|
|
276
|
+
- A string that contains an email has only its emails redacted. Its MTID is left in place, because the MTID branch is an `else`.
|
|
277
|
+
- `/[Aa]uthorization/` does not match `AUTHORIZATION`.
|
|
278
|
+
- Because `Error` arguments skip redaction (`MOD-007`), an error that is not a `WebexHttpError` and carries a token or email in its message reaches the console and buffer unchanged.
|
|
279
|
+
- `logToBuffer` and `client_logToBuffer` pass `levels.info`, which is `undefined` because `levels` is an array. They work because the never-print and always-buffer flags skip the level checks.
|
|
280
|
+
- With `separateLogBuffers`, `clientHistoryLength` caps the SDK buffer as well as the client buffer.
|
|
281
|
+
- `config.level` is not validated against `levels`. An unknown value makes `precedence[...]` `undefined`, so nothing prints.
|
|
282
|
+
- `src/config.js` reads `process.env.WEBEX_LOG_LEVEL` once at module load. Its JSDoc says `historyLength` defaults to `1000`, but the value is `10000`.
|
|
283
|
+
- A shorter `historyLength` takes effect on the next buffered write, not immediately.
|
|
284
|
+
- `test:style` runs eslint over every file under `src/`. Keep this spec under `src/docs/` as Markdown only; eslint reports it as ignored.
|
|
285
|
+
|
|
286
|
+
## Module-specific rules
|
|
287
|
+
|
|
288
|
+
- Route every new log level through `levels` and `makeLoggerMethod` so the `client_` twin and redaction come with it.
|
|
289
|
+
- Keep `wx-js-sdk` as the SDK name. Uploaded logs and tests depend on it.
|
|
290
|
+
- Redact before printing and before buffering. Do not add an output path that skips `filter`.
|
|
291
|
+
- Read config inside the generated methods, not at construction time.
|
|
292
|
+
- Keep `formatLogs`, `updateLastSubmittedIndex`, and `resetBufferToLastSuccessfulUpload` in step with `@webex/internal-plugin-support`.
|
|
293
|
+
|
|
294
|
+
## Export stability
|
|
295
|
+
|
|
296
|
+
The published bindings are the default `Logger` and the named `levels` from `src/index.js`. Importing the package also has the registration side effect described in `MOD-001`. The webex-core fallback logger it replaces has no buffers, no `client_` methods, and no `formatLogs`, so consumers that need those depend on this side effect.
|
|
297
|
+
|
|
298
|
+
Level method names, `formatLogs`, the two cursor methods, and the seven `config.logger` keys are the behavior consumers rely on. Adding a level or config key is backward compatible. Renaming or removing one breaks callers such as `@webex/internal-plugin-support`.
|
|
299
|
+
|
|
300
|
+
## Key design trade-off
|
|
301
|
+
|
|
302
|
+
Buffering excludes `debug` and `trace` by default. The source comment says those logs are numerous and push useful information out of uploaded logs. The cost is that a support upload lacks debug detail unless the integrator sets `bufferLogLevel`.
|
|
303
|
+
|
|
304
|
+
In browsers the logger prints the stringified values instead of live objects. The source comment says a logged browser object is a live reference, so it can show later state. The cost is that browser consoles show JSON strings rather than expandable objects. Node prints the filtered objects.
|
|
305
|
+
|
|
306
|
+
## Verification
|
|
307
|
+
|
|
308
|
+
| Behavior | Check | Evidence | Gap |
|
|
309
|
+
| -------- | ----- | -------- | --- |
|
|
310
|
+
| MOD-002 to MOD-005, INV-001 to INV-003 | `yarn workspace @webex/plugin-logger test:unit` | `#shouldPrint()`, `#shouldBuffer()` | Node-only cases do not run under karma |
|
|
311
|
+
| MOD-006, INV-004 | same | `#filter`, `#walkAndFilter`, per-level `removes authorization data` | Repeated strings, uppercase `AUTHORIZATION`, and email with MTID are untested |
|
|
312
|
+
| MOD-007, MOD-008 | same | `#log()` error and object formatting cases | Stringify failure branch untested |
|
|
313
|
+
| MOD-009, MOD-010, INV-006 | same | overflow and `limit` cases | SDK buffer capped by `clientHistoryLength` untested |
|
|
314
|
+
| MOD-011, MOD-012 | same | `#formatLogs()`, `#updateLastSubmittedIndex()`, `#resetBufferToLastSuccessfulUpload()` | — |
|
|
315
|
+
| MOD-013 | same | `#logToBuffer()` | — |
|
|
316
|
+
| MOD-001, MOD-014, INV-007, `group` and `groupEnd` | none | Source inspection only | No test for registration, the catch branch, default history, or group indentation |
|
|
317
|
+
| Browser output | `yarn workspace @webex/plugin-logger test:browser` | `browserOnly` cases | Requires a karma browser |
|
|
318
|
+
| Lint | `yarn workspace @webex/plugin-logger test:style` | `src/` | — |
|
|
319
|
+
|
|
320
|
+
Do not run the aggregate `test` script from `package.json` as a verification command. It chains `test:integration`, which `package.json` does not define, so it is intentionally not a manifest command.
|