sloplog 0.0.5 → 0.0.6

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.
@@ -17,10 +17,11 @@ export interface SentryLogger {
17
17
  */
18
18
  export interface SentryCollectorOptions {
19
19
  /**
20
- * Sentry logger instance (e.g. Sentry.logger). Requires the Sentry logger
21
- * integration to be configured during Sentry.init().
20
+ * Sentry logger instance (e.g. Sentry.logger) or a function that returns it.
21
+ * Using a getter function allows lazy initialization (e.g., waiting for Sentry.init()).
22
+ * Requires the Sentry logger integration to be configured during Sentry.init().
22
23
  */
23
- logger: SentryLogger;
24
+ logger: SentryLogger | (() => SentryLogger | undefined);
24
25
  /** Default log level for events (default: "info") */
25
26
  level?: SentryLogLevel;
26
27
  /** Optional function to derive log level per event */
@@ -49,7 +50,7 @@ export interface SentryCollectorOptions {
49
50
  * if used with proper Sentry integrations.
50
51
  */
51
52
  export declare class SentryCollector implements LogCollectorClient {
52
- private logger;
53
+ private getLogger;
53
54
  private defaultLevel;
54
55
  private levelSelector?;
55
56
  private message;
@@ -8,14 +8,16 @@ import { flattenObject, withSuppressedConsole } from './index.js';
8
8
  * if used with proper Sentry integrations.
9
9
  */
10
10
  export class SentryCollector {
11
- logger;
11
+ getLogger;
12
12
  defaultLevel;
13
13
  levelSelector;
14
14
  message;
15
15
  flattenAttributes;
16
16
  suppressConsole;
17
17
  constructor(options) {
18
- this.logger = options.logger;
18
+ // Support both direct logger and getter function for lazy initialization
19
+ this.getLogger =
20
+ typeof options.logger === 'function' ? options.logger : () => options.logger;
19
21
  this.defaultLevel = options.level ?? 'info';
20
22
  this.levelSelector = options.levelSelector;
21
23
  this.message = options.message ?? 'wide-event';
@@ -23,6 +25,10 @@ export class SentryCollector {
23
25
  this.suppressConsole = options.suppressConsole ?? true;
24
26
  }
25
27
  async flush(event, partials, options) {
28
+ const logger = this.getLogger();
29
+ if (!logger) {
30
+ return;
31
+ }
26
32
  const partialsObj = {};
27
33
  for (const [key, value] of partials) {
28
34
  partialsObj[key] = value;
@@ -39,17 +45,17 @@ export class SentryCollector {
39
45
  ? this.levelSelector(event, partials, options)
40
46
  : this.defaultLevel;
41
47
  const logFn = () => {
42
- const loggerMethod = (level === 'trace' && this.logger.trace) ||
43
- (level === 'debug' && this.logger.debug) ||
44
- (level === 'info' && this.logger.info) ||
45
- (level === 'warn' && this.logger.warn) ||
46
- (level === 'error' && this.logger.error) ||
47
- (level === 'fatal' && this.logger.fatal);
48
+ const loggerMethod = (level === 'trace' && logger.trace) ||
49
+ (level === 'debug' && logger.debug) ||
50
+ (level === 'info' && logger.info) ||
51
+ (level === 'warn' && logger.warn) ||
52
+ (level === 'error' && logger.error) ||
53
+ (level === 'fatal' && logger.fatal);
48
54
  if (loggerMethod) {
49
55
  loggerMethod(this.message, attributes);
50
56
  return;
51
57
  }
52
- this.logger.log?.(level, this.message, attributes);
58
+ logger.log?.(level, this.message, attributes);
53
59
  };
54
60
  // Suppress console output from Sentry SDK if configured
55
61
  if (this.suppressConsole) {
package/dist/index.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import type { ZodRawShape } from 'zod';
2
2
  import type { LogCollectorClient } from './collectors/index.js';
3
+ export * from './collectors/index.js';
4
+ export * from './collectors/sentry.js';
3
5
  import type { PartialMetadata, PartialDefinition, PartialOptions, Registry, RegistryType } from './registry.js';
4
6
  /** Current sloplog library version (propagated onto Service). */
5
- export declare const SLOPLOG_VERSION = "0.0.2";
7
+ export declare const SLOPLOG_VERSION = "0.0.6";
6
8
  /**
7
9
  * TYPES
8
10
  */
package/dist/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  import { extractPartialMetadata } from './registry.js';
2
+ // Re-export collectors from main entry point for easier bundler compatibility
3
+ export * from './collectors/index.js';
4
+ export * from './collectors/sentry.js';
2
5
  /**
3
6
  * Generate a nano ID for unique identifiers
4
7
  */
@@ -11,7 +14,7 @@ function nanoId() {
11
14
  return result;
12
15
  }
13
16
  /** Current sloplog library version (propagated onto Service). */
14
- export const SLOPLOG_VERSION = '0.0.2';
17
+ export const SLOPLOG_VERSION = '0.0.6';
15
18
  /** Default language marker when Service.sloplogLanguage is not set. */
16
19
  const SLOPLOG_LANGUAGE = 'typescript';
17
20
  function isOriginatorResult(input) {
@@ -11,11 +11,11 @@ declare const error: import("./registry.js").PartialFactory<"error", {
11
11
  declare const logMessage: import("./registry.js").PartialFactory<"log_message", {
12
12
  message: z.ZodString;
13
13
  level: z.ZodEnum<{
14
- error: "error";
15
14
  trace: "trace";
16
15
  debug: "debug";
17
16
  info: "info";
18
17
  warn: "warn";
18
+ error: "error";
19
19
  fatal: "fatal";
20
20
  }>;
21
21
  data: z.ZodOptional<z.ZodString>;
@@ -57,11 +57,11 @@ export declare const builtInPartials: {
57
57
  log_message: import("./registry.js").PartialFactory<"log_message", {
58
58
  message: z.ZodString;
59
59
  level: z.ZodEnum<{
60
- error: "error";
61
60
  trace: "trace";
62
61
  debug: "debug";
63
62
  info: "info";
64
63
  warn: "warn";
64
+ error: "error";
65
65
  fatal: "fatal";
66
66
  }>;
67
67
  data: z.ZodOptional<z.ZodString>;
@@ -102,11 +102,11 @@ export declare const builtInRegistry: import("./registry.js").Registry<(import("
102
102
  }> | import("./registry.js").PartialFactory<"log_message", {
103
103
  message: z.ZodString;
104
104
  level: z.ZodEnum<{
105
- error: "error";
106
105
  trace: "trace";
107
106
  debug: "debug";
108
107
  info: "info";
109
108
  warn: "warn";
109
+ error: "error";
110
110
  fatal: "fatal";
111
111
  }>;
112
112
  data: z.ZodOptional<z.ZodString>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sloplog",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "A TypeScript library for constructing wide events",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",