@bifold/remote-logs 2.11.3 → 2.11.4

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/build/logger.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BifoldError, AbstractBifoldLogger } from '@bifold/core';
2
+ import { LogLevel } from '@credo-ts/core';
2
3
  import { RemoteLoggerOptions } from './transports';
3
4
  export declare enum RemoteLoggerEventTypes {
4
5
  ENABLE_REMOTE_LOGGING = "RemoteLogging.Enable"
@@ -14,7 +15,6 @@ interface LogMethod {
14
15
  (message: string, data: Record<string, unknown>, error: Error): void;
15
16
  }
16
17
  export declare class RemoteLogger extends AbstractBifoldLogger {
17
- private readonly baseLogger;
18
18
  private _remoteLoggingEnabled;
19
19
  private _sessionId;
20
20
  private _autoDisableRemoteLoggingIntervalInMinutes;
@@ -22,6 +22,7 @@ export declare class RemoteLogger extends AbstractBifoldLogger {
22
22
  private lokiLabels;
23
23
  private remoteLoggingAutoDisableTimer;
24
24
  private eventListener;
25
+ private _baseLogLevel;
25
26
  constructor(options: RemoteLoggerOptions);
26
27
  get sessionId(): number;
27
28
  set sessionId(value: number);
@@ -29,6 +30,8 @@ export declare class RemoteLogger extends AbstractBifoldLogger {
29
30
  get remoteLoggingEnabled(): boolean;
30
31
  set remoteLoggingEnabled(value: boolean);
31
32
  private configureLogger;
33
+ /** Update minimum log level and reconfigure underlying transport */
34
+ setLogLevel(level: LogLevel): void;
32
35
  startEventListeners(): void;
33
36
  stopEventListeners(): void;
34
37
  overrideCurrentAutoDisableExpiration(expirationInMinutes: number): void;
@@ -47,5 +50,7 @@ export declare class RemoteLogger extends AbstractBifoldLogger {
47
50
  * @returns Parsed data and error objects
48
51
  */
49
52
  private parseLogArguments;
53
+ /** Dispose of timers and listeners, disable remote logging */
54
+ dispose(): void;
50
55
  }
51
56
  export {};
package/build/logger.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RemoteLogger = exports.RemoteLoggerEventTypes = void 0;
4
4
  const core_1 = require("@bifold/core");
5
+ const core_2 = require("@credo-ts/core");
5
6
  const react_native_1 = require("react-native");
6
7
  const react_native_logs_1 = require("react-native-logs");
7
8
  const transports_1 = require("./transports");
@@ -22,53 +23,70 @@ class RemoteLogger extends core_1.AbstractBifoldLogger {
22
23
  super();
23
24
  this._remoteLoggingEnabled = false;
24
25
  this._autoDisableRemoteLoggingIntervalInMinutes = 0;
26
+ this._baseLogLevel = core_2.LogLevel.debug;
25
27
  // Standardized logging methods with consistent overloads
26
28
  this.test = (message, dataOrError, error) => {
27
29
  var _a, _b;
30
+ if (!this.isEnabled(core_2.LogLevel.debug))
31
+ return;
28
32
  const { data, actualError } = this.parseLogArguments(dataOrError, error);
29
33
  (_b = (_a = this._log) === null || _a === void 0 ? void 0 : _a.test) === null || _b === void 0 ? void 0 : _b.call(_a, { message, data, error: actualError });
30
34
  };
31
35
  this.trace = (message, dataOrError, error) => {
32
36
  var _a, _b;
37
+ if (!this.isEnabled(core_2.LogLevel.debug))
38
+ return;
33
39
  const { data, actualError } = this.parseLogArguments(dataOrError, error);
34
40
  (_b = (_a = this._log) === null || _a === void 0 ? void 0 : _a.trace) === null || _b === void 0 ? void 0 : _b.call(_a, { message, data, error: actualError });
35
41
  };
36
42
  this.debug = (message, dataOrError, error) => {
37
43
  var _a, _b;
44
+ if (!this.isEnabled(core_2.LogLevel.debug))
45
+ return;
38
46
  const { data, actualError } = this.parseLogArguments(dataOrError, error);
39
47
  (_b = (_a = this._log) === null || _a === void 0 ? void 0 : _a.debug) === null || _b === void 0 ? void 0 : _b.call(_a, { message, data, error: actualError });
40
48
  };
41
49
  this.info = (message, dataOrError, error) => {
42
50
  var _a, _b;
51
+ if (!this.isEnabled(core_2.LogLevel.info))
52
+ return;
43
53
  const { data, actualError } = this.parseLogArguments(dataOrError, error);
44
54
  (_b = (_a = this._log) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.call(_a, { message, data, error: actualError });
45
55
  };
46
56
  this.warn = (message, dataOrError, error) => {
47
57
  var _a, _b;
58
+ if (!this.isEnabled(core_2.LogLevel.warn))
59
+ return;
48
60
  const { data, actualError } = this.parseLogArguments(dataOrError, error);
49
61
  (_b = (_a = this._log) === null || _a === void 0 ? void 0 : _a.warn) === null || _b === void 0 ? void 0 : _b.call(_a, { message, data, error: actualError });
50
62
  };
51
63
  this.error = (message, dataOrError, error) => {
52
64
  var _a, _b;
65
+ if (!this.isEnabled(core_2.LogLevel.error))
66
+ return;
53
67
  const { data, actualError } = this.parseLogArguments(dataOrError, error);
54
68
  (_b = (_a = this._log) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, { message, data, error: actualError });
55
69
  };
56
70
  this.fatal = (message, dataOrError, error) => {
57
71
  var _a, _b;
72
+ if (!this.isEnabled(core_2.LogLevel.fatal))
73
+ return;
58
74
  const { data, actualError } = this.parseLogArguments(dataOrError, error);
59
75
  (_b = (_a = this._log) === null || _a === void 0 ? void 0 : _a.fatal) === null || _b === void 0 ? void 0 : _b.call(_a, { message, data, error: actualError });
60
76
  };
61
- this.baseLogger = new core_1.BifoldLogger();
62
77
  this.lokiUrl = (_a = options.lokiUrl) !== null && _a !== void 0 ? _a : undefined;
63
78
  this.lokiLabels = (_b = options.lokiLabels) !== null && _b !== void 0 ? _b : {};
64
79
  this._autoDisableRemoteLoggingIntervalInMinutes = (_c = options.autoDisableRemoteLoggingIntervalInMinutes) !== null && _c !== void 0 ? _c : 0;
80
+ if (options.logLevel !== undefined) {
81
+ this.logLevel = options.logLevel;
82
+ }
83
+ this._baseLogLevel = this.logLevel;
65
84
  this.configureLogger();
66
85
  }
67
86
  get sessionId() {
68
- if (!this._sessionId) {
69
- this._sessionId = Math.floor(SESSION_ID_RANGE.MIN + Math.random() * (SESSION_ID_RANGE.MAX - SESSION_ID_RANGE.MIN + 1));
70
- }
71
- return this._sessionId;
87
+ var _a;
88
+ // When remote logging is disabled this will be 0; enabled path guarantees initialization
89
+ return (_a = this._sessionId) !== null && _a !== void 0 ? _a : 0;
72
90
  }
73
91
  set sessionId(value) {
74
92
  this._sessionId = value;
@@ -82,16 +100,34 @@ class RemoteLogger extends core_1.AbstractBifoldLogger {
82
100
  }
83
101
  set remoteLoggingEnabled(value) {
84
102
  this._remoteLoggingEnabled = value;
85
- if (value === false) {
103
+ if (value) {
104
+ // Generate a new session id on first enable
105
+ if (!this._sessionId) {
106
+ this._sessionId = Math.floor(SESSION_ID_RANGE.MIN + Math.random() * (SESSION_ID_RANGE.MAX - SESSION_ID_RANGE.MIN + 1));
107
+ }
108
+ // Override to most verbose when remote logging active
109
+ this.logLevel = core_2.LogLevel.debug;
110
+ }
111
+ else {
86
112
  this._sessionId = undefined;
113
+ if (this.remoteLoggingAutoDisableTimer) {
114
+ clearTimeout(this.remoteLoggingAutoDisableTimer);
115
+ this.remoteLoggingAutoDisableTimer = undefined;
116
+ }
117
+ // Restore base level after deactivation
118
+ this.logLevel = this._baseLogLevel;
87
119
  }
88
120
  this.configureLogger();
89
121
  }
90
122
  configureLogger() {
91
123
  const transportOptions = {};
92
124
  const transport = [transports_1.consoleTransport];
125
+ // We rely on per-method isEnabled() gating and keep transport severity at lowest (debug)
126
+ // so react-native-logs does not perform an additional filter layer.
127
+ const severity = 'debug';
93
128
  const config = Object.assign(Object.assign({}, this._config), { transport,
94
- transportOptions });
129
+ transportOptions,
130
+ severity });
95
131
  if (this.remoteLoggingEnabled && this.lokiUrl) {
96
132
  transport.push(transports_1.lokiTransport);
97
133
  config['transportOptions'] = {
@@ -106,12 +142,24 @@ class RemoteLogger extends core_1.AbstractBifoldLogger {
106
142
  }
107
143
  this._log = react_native_logs_1.logger.createLogger(config);
108
144
  }
145
+ /** Update minimum log level and reconfigure underlying transport */
146
+ setLogLevel(level) {
147
+ this._baseLogLevel = level;
148
+ // Only apply immediately if remote logging isn't forcing
149
+ // debug
150
+ if (!this._remoteLoggingEnabled) {
151
+ this.logLevel = level;
152
+ }
153
+ this.configureLogger();
154
+ }
109
155
  startEventListeners() {
110
156
  this.eventListener = react_native_1.DeviceEventEmitter.addListener(RemoteLoggerEventTypes.ENABLE_REMOTE_LOGGING, (value) => {
111
157
  this.remoteLoggingEnabled = value;
112
158
  });
113
159
  }
114
160
  stopEventListeners() {
161
+ var _a;
162
+ (_a = this.eventListener) === null || _a === void 0 ? void 0 : _a.remove();
115
163
  this.eventListener = undefined;
116
164
  }
117
165
  overrideCurrentAutoDisableExpiration(expirationInMinutes) {
@@ -160,5 +208,14 @@ class RemoteLogger extends core_1.AbstractBifoldLogger {
160
208
  }
161
209
  return { data, actualError };
162
210
  }
211
+ /** Dispose of timers and listeners, disable remote logging */
212
+ dispose() {
213
+ this.stopEventListeners();
214
+ this.remoteLoggingEnabled = false;
215
+ if (this.remoteLoggingAutoDisableTimer) {
216
+ clearTimeout(this.remoteLoggingAutoDisableTimer);
217
+ this.remoteLoggingAutoDisableTimer = undefined;
218
+ }
219
+ }
163
220
  }
164
221
  exports.RemoteLogger = RemoteLogger;
@@ -100,11 +100,46 @@ const consoleTransport = (props) => {
100
100
  const formattedData = messageDataFormatter(...Object.values(rest)).join(' ');
101
101
  logMessage = `${logMessage} ${formattedData}`;
102
102
  }
103
+ // Only prepend a tag for test logs.
104
+ const levelText = props.level.text.toLowerCase();
105
+ if (levelText === 'test') {
106
+ const levelTag = `[${props.level.text.toUpperCase()}]`;
107
+ logMessage = `${levelTag} ${logMessage}`;
108
+ }
103
109
  if ((_d = props.options) === null || _d === void 0 ? void 0 : _d.consoleFunc) {
104
110
  props.options.consoleFunc(logMessage);
105
111
  }
106
112
  else {
107
- console.log(logMessage);
113
+ // Use appropriate console method based on log level
114
+ switch (props.level.text.toLowerCase()) {
115
+ case 'trace':
116
+ // console.trace prints a stack; we only want the message. Provide a wrapper.
117
+ // Some environments always include stack; if so this remains acceptable.
118
+ console.trace(logMessage);
119
+ break;
120
+ case 'debug':
121
+ // Prefer console.debug for debug level; fallback to console.log if unavailable
122
+ if (typeof console.debug === 'function') {
123
+ console.debug(logMessage);
124
+ }
125
+ else {
126
+ console.log(logMessage);
127
+ }
128
+ break;
129
+ case 'warn':
130
+ console.warn(logMessage);
131
+ break;
132
+ case 'error':
133
+ case 'fatal':
134
+ console.error(logMessage);
135
+ break;
136
+ case 'info':
137
+ console.info(logMessage);
138
+ break;
139
+ default:
140
+ console.log(logMessage);
141
+ break;
142
+ }
108
143
  }
109
144
  };
110
145
  exports.consoleTransport = consoleTransport;
@@ -1,9 +1,11 @@
1
1
  import { transportFunctionType } from 'react-native-logs';
2
+ import { LogLevel } from '@credo-ts/core';
2
3
  export interface RemoteLoggerOptions {
3
4
  lokiUrl?: string;
4
5
  lokiLabels?: Record<string, string>;
5
6
  autoDisableRemoteLoggingIntervalInMinutes?: number;
6
7
  job?: string;
8
+ logLevel?: LogLevel;
7
9
  }
8
10
  export type LokiTransportProps = {
9
11
  msg: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifold/remote-logs",
3
- "version": "2.11.3",
3
+ "version": "2.11.4",
4
4
  "description": "Remote logging for credo-ts agents",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -59,7 +59,7 @@
59
59
  "hoistingLimits": "workspaces"
60
60
  },
61
61
  "dependencies": {
62
- "@bifold/core": "2.11.3",
62
+ "@bifold/core": "2.11.4",
63
63
  "@credo-ts/core": "0.5.17",
64
64
  "axios": "~1.4.0",
65
65
  "buffer": "~6.0.3",