8000 core: Logger implementation · lordnox/sentry-javascript@30342ae · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit 30342ae

Browse files
committed
core: Logger implementation
1 parent daa4f33 commit 30342ae

File tree

5 files changed

+60
-13
lines changed

5 files changed

+60
-13
lines changed

packages/browser/src/client.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseClient, DSN, SentryError } from '@sentry/core';
2-
import { DSNLike, SdkInfo } from '@sentry/types';
2+
import { DSNLike } from '@sentry/types';
33
import { getGlobalObject } from '@sentry/utils/misc';
44
import { BrowserBackend, BrowserOptions } from './backend';
55

@@ -19,16 +19,6 @@ export class BrowserClient extends BaseClient<BrowserBackend, BrowserOptions> {
1919
super(BrowserBackend, options);
2020
}
2121

22-
/**
23-
* @inheritDoc
24-
*/
25-
public getSdkInfo(): SdkInfo {
26-
return {
27-
name: 'sentry-browser',
28-
version: '4.0.0-beta.6',
29-
};
30-
}
31-
3222
/**
3323
* TODO
3424
*/

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { logger } from './logger';
12
export { captureException, captureMessage, configureScope } from '@sentry/minimal';
23
export { Hub, Scope } from '@sentry/hub';
34
export { BackendClass, BaseClient } from './base';

packages/core/src/logger.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { getGlobalObject } from '@sentry/utils/misc';
2+
3+
// TODO: Implement different loggers for different environments
4+
const global = getGlobalObject() as Window;
5+
6+
/** TODO */
7+
class Logger {
8+
/** TODO */
9+
private readonly console: Console;
10+
/** TODO */
11+
private disabled: boolean;
12+
13+
/** TODO */
14+
public constructor() {
15+
this.console = global.console;
16+
this.disabled = true;
17+
}
18+
/** TODO */
19+
public disable(): void {
20+
this.disabled = true;
21+
}
22+
/** TODO */
23+
public enable(): void {
24+
this.disabled = false;
25+
}
26+
/** TODO */
27+
public log(message: any): void {
28+
if (this.disabled) {
29+
return;
30+
}
31+
this.console.log(`Sentry Logger [Log]: ${message}`); // tslint:disable-line:no-console
32+
}
33+
/** TODO */
34+
public warn(message: any): void {
35+
if (this.disabled) {
36+
return;
37+
}
38+
this.console.warn(`Sentry Logger [Warn]: ${message}`); // tslint:disable-line:no-console
39+
}
40+
/** TODO */
41+
public error(message: any): void {
42+
if (this.disabled) {
43+
return;
44+
}
45+
this.console.error(`Sentry Logger [Error]: ${message}`); // tslint:disable-line:no-console
46+
}
47+
}
48+
49+
const logger = new Logger();
50+
51+
export { logger };

packages/core/src/sdk.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getDefaultHub } from '@sentry/hub';
22
import { Integration } from '@sentry/types';
33
import { Client, Options } from './interfaces';
4+
import { logger } from './logger';
45

56
/** A class object that can instanciate Client objects. */
67
export interface ClientClass<F extends Client, O extends Options> {
@@ -24,6 +25,9 @@ export function initAndBind<F extends Client, O extends Options>(
2425
return;
2526
}
2627

28+
// TODO: Options.debug? Options.enableLogger?
29+
logger.enable();
30+
2731
const client = new clientClass(options);
2832
client.install();
2933

@@ -41,7 +45,8 @@ export function initAndBind<F extends Client, O extends Options>(
4145
// Just in case someone will return non-array from a `itegrations` callback
4246
if (Array.isArray(integrations)) {
4347
integrations.forEach(integration => {
44-
integration.install();
48+
integration.install(options);
49+
logger.log(`Integration installed: ${integration.name}`);
4550
});
4651
}
4752
}

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export interface Mechanism {
196196
/** TODO */
197197
export interface Integration {
198198
name: string;
199-
install(): void;
199+
install(options?: object): void;
200200
}
201201

202202
/** TODO */

0 commit comments

Comments
 (0)
0