sloplog 0.0.5 → 0.0.7
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/collectors/index.d.ts +0 -6
- package/dist/collectors/index.js +0 -33
- package/dist/collectors/sentry.d.ts +5 -11
- package/dist/collectors/sentry.js +17 -19
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -1
- package/dist/partials.d.ts +3 -3
- package/package.json +1 -1
|
@@ -9,12 +9,6 @@ export declare function truncateStack(stack: string | undefined): string | undef
|
|
|
9
9
|
* Stack traces are automatically truncated.
|
|
10
10
|
*/
|
|
11
11
|
export declare function flattenObject(obj: unknown, prefix?: string, result?: Record<string, unknown>): Record<string, unknown>;
|
|
12
|
-
/**
|
|
13
|
-
* Execute a function with all console methods suppressed.
|
|
14
|
-
* Useful for preventing Sentry SDK from outputting its own logs to console
|
|
15
|
-
* when we're already handling console output ourselves.
|
|
16
|
-
*/
|
|
17
|
-
export declare function withSuppressedConsole<T>(fn: () => T): T;
|
|
18
12
|
/**
|
|
19
13
|
* Options passed to collectors when flushing an event
|
|
20
14
|
*/
|
package/dist/collectors/index.js
CHANGED
|
@@ -49,39 +49,6 @@ export function flattenObject(obj, prefix = '', result = {}) {
|
|
|
49
49
|
}
|
|
50
50
|
return result;
|
|
51
51
|
}
|
|
52
|
-
/**
|
|
53
|
-
* Execute a function with all console methods suppressed.
|
|
54
|
-
* Useful for preventing Sentry SDK from outputting its own logs to console
|
|
55
|
-
* when we're already handling console output ourselves.
|
|
56
|
-
*/
|
|
57
|
-
export function withSuppressedConsole(fn) {
|
|
58
|
-
/* eslint-disable no-console */
|
|
59
|
-
const noop = () => { };
|
|
60
|
-
const originalLog = console.log;
|
|
61
|
-
const originalInfo = console.info;
|
|
62
|
-
const originalWarn = console.warn;
|
|
63
|
-
const originalError = console.error;
|
|
64
|
-
const originalDebug = console.debug;
|
|
65
|
-
const originalTrace = console.trace;
|
|
66
|
-
console.log = noop;
|
|
67
|
-
console.info = noop;
|
|
68
|
-
console.warn = noop;
|
|
69
|
-
console.error = noop;
|
|
70
|
-
console.debug = noop;
|
|
71
|
-
console.trace = noop;
|
|
72
|
-
try {
|
|
73
|
-
return fn();
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
console.log = originalLog;
|
|
77
|
-
console.info = originalInfo;
|
|
78
|
-
console.warn = originalWarn;
|
|
79
|
-
console.error = originalError;
|
|
80
|
-
console.debug = originalDebug;
|
|
81
|
-
console.trace = originalTrace;
|
|
82
|
-
}
|
|
83
|
-
/* eslint-enable no-console */
|
|
84
|
-
}
|
|
85
52
|
/**
|
|
86
53
|
* Simple collector to log the event to stdout/console
|
|
87
54
|
*/
|
|
@@ -17,10 +17,11 @@ export interface SentryLogger {
|
|
|
17
17
|
*/
|
|
18
18
|
export interface SentryCollectorOptions {
|
|
19
19
|
/**
|
|
20
|
-
* Sentry logger instance (e.g. Sentry.logger)
|
|
21
|
-
*
|
|
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 */
|
|
@@ -33,12 +34,6 @@ export interface SentryCollectorOptions {
|
|
|
33
34
|
* Default: true
|
|
34
35
|
*/
|
|
35
36
|
flattenAttributes?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* If true, suppress console output from Sentry SDK during logging.
|
|
38
|
-
* Useful when you're already handling console output via another collector.
|
|
39
|
-
* Default: true
|
|
40
|
-
*/
|
|
41
|
-
suppressConsole?: boolean;
|
|
42
37
|
}
|
|
43
38
|
/**
|
|
44
39
|
* Collector that sends events to Sentry Logs via the Sentry logger API.
|
|
@@ -49,12 +44,11 @@ export interface SentryCollectorOptions {
|
|
|
49
44
|
* if used with proper Sentry integrations.
|
|
50
45
|
*/
|
|
51
46
|
export declare class SentryCollector implements LogCollectorClient {
|
|
52
|
-
private
|
|
47
|
+
private getLogger;
|
|
53
48
|
private defaultLevel;
|
|
54
49
|
private levelSelector?;
|
|
55
50
|
private message;
|
|
56
51
|
private flattenAttributes;
|
|
57
|
-
private suppressConsole;
|
|
58
52
|
constructor(options: SentryCollectorOptions);
|
|
59
53
|
flush(event: WideEventBase, partials: Map<string, PartialValue>, options: FlushOptions): Promise<void>;
|
|
60
54
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { flattenObject
|
|
1
|
+
import { flattenObject } from './index.js';
|
|
2
2
|
/**
|
|
3
3
|
* Collector that sends events to Sentry Logs via the Sentry logger API.
|
|
4
4
|
*
|
|
@@ -8,21 +8,25 @@ import { flattenObject, withSuppressedConsole } from './index.js';
|
|
|
8
8
|
* if used with proper Sentry integrations.
|
|
9
9
|
*/
|
|
10
10
|
export class SentryCollector {
|
|
11
|
-
|
|
11
|
+
getLogger;
|
|
12
12
|
defaultLevel;
|
|
13
13
|
levelSelector;
|
|
14
14
|
message;
|
|
15
15
|
flattenAttributes;
|
|
16
|
-
suppressConsole;
|
|
17
16
|
constructor(options) {
|
|
18
|
-
|
|
17
|
+
// Support both direct logger and getter function for lazy initialization
|
|
18
|
+
this.getLogger =
|
|
19
|
+
typeof options.logger === 'function' ? options.logger : () => options.logger;
|
|
19
20
|
this.defaultLevel = options.level ?? 'info';
|
|
20
21
|
this.levelSelector = options.levelSelector;
|
|
21
22
|
this.message = options.message ?? 'wide-event';
|
|
22
23
|
this.flattenAttributes = options.flattenAttributes ?? true;
|
|
23
|
-
this.suppressConsole = options.suppressConsole ?? true;
|
|
24
24
|
}
|
|
25
25
|
async flush(event, partials, options) {
|
|
26
|
+
const logger = this.getLogger();
|
|
27
|
+
if (!logger) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
26
30
|
const partialsObj = {};
|
|
27
31
|
for (const [key, value] of partials) {
|
|
28
32
|
partialsObj[key] = value;
|
|
@@ -39,25 +43,19 @@ export class SentryCollector {
|
|
|
39
43
|
? this.levelSelector(event, partials, options)
|
|
40
44
|
: this.defaultLevel;
|
|
41
45
|
const logFn = () => {
|
|
42
|
-
const loggerMethod = (level === 'trace' &&
|
|
43
|
-
(level === 'debug' &&
|
|
44
|
-
(level === 'info' &&
|
|
45
|
-
(level === 'warn' &&
|
|
46
|
-
(level === 'error' &&
|
|
47
|
-
(level === 'fatal' &&
|
|
46
|
+
const loggerMethod = (level === 'trace' && logger.trace) ||
|
|
47
|
+
(level === 'debug' && logger.debug) ||
|
|
48
|
+
(level === 'info' && logger.info) ||
|
|
49
|
+
(level === 'warn' && logger.warn) ||
|
|
50
|
+
(level === 'error' && logger.error) ||
|
|
51
|
+
(level === 'fatal' && logger.fatal);
|
|
48
52
|
if (loggerMethod) {
|
|
49
53
|
loggerMethod(this.message, attributes);
|
|
50
54
|
return;
|
|
51
55
|
}
|
|
52
|
-
|
|
56
|
+
logger.log?.(level, this.message, attributes);
|
|
53
57
|
};
|
|
54
|
-
|
|
55
|
-
if (this.suppressConsole) {
|
|
56
|
-
withSuppressedConsole(logFn);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
logFn();
|
|
60
|
-
}
|
|
58
|
+
logFn();
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
/**
|
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.
|
|
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.
|
|
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) {
|
package/dist/partials.d.ts
CHANGED
|
@@ -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>;
|