Skip to content

Commit 5be32dd

Browse files
committed
Add logger
1 parent 4b56ee1 commit 5be32dd

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

src/background.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import browser from "webextension-polyfill";
1+
import Browser from "webextension-polyfill";
2+
import { initTracker } from "./tracker";
3+
import { logger } from "./compositions/logger";
24

3-
console.log("Start background script");
5+
logger.log("Start background script");
46

5-
browser.runtime.onInstalled.addListener((details) => {
6-
console.log("Extension installed:", details);
7+
Browser.runtime.onInstalled.addListener((details) => {
8+
logger.log("Extension installed:", details);
79
});
10+
11+
initTracker();

src/compositions/logger.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
function print(logFn: typeof console.log, style: string, ...args: any[]) {
2+
if (typeof args[0] === 'string') {
3+
const newArgs = [...args];
4+
logFn(
5+
`%cWeb Activity Time Tracker%c${new Date().toLocaleTimeString()}%c ${newArgs.shift()}`,
6+
style,
7+
'background-color: #eaf1fb; padding: 2px 4px; border-radius: 3px',
8+
'',
9+
...newArgs,
10+
);
11+
} else {
12+
logFn('%cWeb Activity Time Tracker', style, ...args);
13+
}
14+
}
15+
16+
export function log(...args: any[]) {
17+
if (__DEV__)
18+
print(
19+
console.log,
20+
'color: white; background-color: #1e8e3e; padding: 2px 4px; border-radius: 3px; font-weight: bold',
21+
...args,
22+
);
23+
}
24+
25+
26+
export const logger = {
27+
log,
28+
};

src/repository/inject-tabs-repository.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ async function createAndInitInstance() {
1111

1212
export async function injectTabsRepository(): Promise<ITabsRepository> {
1313
if (instanse == null) {
14-
console.log("test");
1514
instanse = await createAndInitInstance();
1615
}
1716
return instanse;

0 commit comments

Comments
 (0)