@redthreadlabs/tracelog-client 1.6.0 → 1.7.0

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/dist/LogClient.js CHANGED
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LogClient = void 0;
4
4
  const EventBuilder_1 = require("./EventBuilder");
5
5
  const util_1 = require("./util");
6
+ // Level ordering for the optional getMinLevel gate. An event is dropped when
7
+ // its level ranks below the host-supplied minimum.
8
+ const LEVEL_RANK = { debug: 0, info: 1, warn: 2, error: 3 };
6
9
  // Defaults (all overridable via LogClientOptions)
7
10
  const DEFAULT_FLUSH_CADENCE_MS = 5000;
8
11
  const DEFAULT_MAX_BUFFER_SIZE = 100;
@@ -125,6 +128,11 @@ class LogClient {
125
128
  _enqueueEvent(event) {
126
129
  if (this._disposed)
127
130
  return;
131
+ // Level gate: drop events below the host-supplied minimum before they ever
132
+ // buffer, persist, or ship. No callback ⇒ emit everything (back-compat).
133
+ const minLevel = this._opts.getMinLevel?.();
134
+ if (minLevel && LEVEL_RANK[event.level] < LEVEL_RANK[minLevel])
135
+ return;
128
136
  this._eventBuffer.push(event);
129
137
  this._schedulePersist();
130
138
  if (this._eventBuffer.length >= (this._opts.maxBufferSize ?? DEFAULT_MAX_BUFFER_SIZE)) {
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ClientInfo } from '@redthreadlabs/tracelog-schema';
1
+ import type { ClientInfo, LogLevel } from '@redthreadlabs/tracelog-schema';
2
2
  export type { JsonValue, LogLevel, LogBatch, LogEventItem, LogPerfItem, ClientInfo, } from '@redthreadlabs/tracelog-schema';
3
3
  export interface PerfToken {
4
4
  /** 16-char hex ID for this perf */
@@ -23,6 +23,13 @@ export interface LogClientOptions {
23
23
  getSessionRef?: () => string | undefined;
24
24
  /** Returns native device identifier */
25
25
  getDeviceId?: () => string | undefined;
26
+ /**
27
+ * Returns the minimum level to emit. Events whose level ranks below this
28
+ * (debug < info < warn < error) are dropped before buffering — they never
29
+ * persist or ship. Called once per event, so keep it cheap and synchronous.
30
+ * Omit to emit every level (default). Perfs are unaffected.
31
+ */
32
+ getMinLevel?: () => LogLevel;
26
33
  /** Flush cadence in ms. Default: 5000 */
27
34
  flushCadenceMs?: number;
28
35
  /** Max events buffered before forced flush. Default: 100 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redthreadlabs/tracelog-client",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "Lightweight logging client for tracelog — works in React Native and browsers",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/",