feat: 增加debug参数

This commit is contained in:
weidingjian 2026-06-25 01:02:16 +08:00
parent e5844bbfe9
commit c7e8e24332
5 changed files with 35 additions and 13 deletions

6
dist/index.cjs.js vendored

File diff suppressed because one or more lines are too long

6
dist/index.esm.js vendored

File diff suppressed because one or more lines are too long

6
dist/index.iife.js vendored

File diff suppressed because one or more lines are too long

View File

@ -35,7 +35,7 @@ class Client implements LightClient {
}
setDebug(config.debug === true);
logDebug('Client', 'Initializing SDK', { dsn: config.dsn, debug: config.debug, enabled: config.enabled });
logDebug('Client', 'Initializing SDK', { dsn: config.dsn, debug: config.debug, enabled: config.enabled !== false });
this.dsn = parseDSN(config.dsn);
this.configManager = new ConfigManager(config);

View File

@ -6,10 +6,14 @@ import BehaviorPlugin from './plugins/BehaviorPlugin';
import OfflinePlugin from './plugins/OfflinePlugin';
import SamplingPlugin from './plugins/SamplingPlugin';
import type { LightConfig, LightClient, SentryEvent, EventLevel, UserInfo, Breadcrumb, LightPlugin, ErrorEvent, PerformanceEvent, NetworkEvent, BehaviorEvent, DSNInfo } from './types';
import { logDebug, setDebug } from './utils/logger';
let globalClient: LightClient | null = null;
function init(config: LightConfig): LightClient {
setDebug(config.debug === true);
logDebug('Index', 'init called', { dsn: config.dsn, debug: config.debug });
const client = new Client(config);
const defaultPlugins: LightPlugin[] = [
@ -30,6 +34,8 @@ function init(config: LightConfig): LightClient {
defaultPlugins.push(new BehaviorPlugin());
}
logDebug('Index', 'Registering plugins', { count: defaultPlugins.length, plugins: defaultPlugins.map(p => p.name) });
for (const plugin of defaultPlugins) {
client.use(plugin);
}
@ -45,6 +51,7 @@ function init(config: LightConfig): LightClient {
client.init();
globalClient = client;
logDebug('Index', 'init completed, globalClient set');
return client;
}
@ -53,15 +60,30 @@ function getClient(): LightClient | null {
}
function captureException(error: Error | unknown): void {
globalClient?.captureException(error);
logDebug('Index', 'captureException called', { hasClient: !!globalClient });
if (!globalClient) {
console.warn('[LightSDK] SDK not initialized. Call LightSentry.init() first.');
return;
}
globalClient.captureException(error);
}
function captureMessage(message: string, level?: EventLevel): void {
globalClient?.captureMessage(message, level);
logDebug('Index', 'captureMessage called', { hasClient: !!globalClient });
if (!globalClient) {
console.warn('[LightSDK] SDK not initialized. Call LightSentry.init() first.');
return;
}
globalClient.captureMessage(message, level);
}
function captureEvent(event: Partial<SentryEvent> & { type: string }): void {
globalClient?.captureEvent(event);
logDebug('Index', 'captureEvent called', { hasClient: !!globalClient });
if (!globalClient) {
console.warn('[LightSDK] SDK not initialized. Call LightSentry.init() first.');
return;
}
globalClient.captureEvent(event);
}
function setUser(user: UserInfo | null): void {