Skip to content

Commit c59cc2b

Browse files
committed
refactor: extract all loggers to helper
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent ebf2dd6 commit c59cc2b

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

src/main/utils.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ export function openLogsDirectory() {
4343
const logDirectory = path.dirname(log.transports.file?.getFile()?.path);
4444

4545
if (!logDirectory) {
46-
logError('openLogsDirectory', 'Could not find log directory!');
46+
logError(
47+
'openLogsDirectory',
48+
'Could not find log directory!',
49+
new Error('Directory not found'),
50+
);
4751
return;
4852
}
4953

src/shared/logger.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ describe('renderer/utils/logger.ts', () => {
2121
logInfo('foo', 'bar');
2222

2323
expect(logInfoSpy).toHaveBeenCalledTimes(1);
24-
expect(logInfoSpy).toHaveBeenCalledWith('[foo]:', 'bar');
24+
expect(logInfoSpy).toHaveBeenCalledWith('[foo]', 'bar');
2525
});
2626

2727
it('log info with notification', () => {
2828
logInfo('foo', 'bar', mockSingleNotification);
2929

3030
expect(logInfoSpy).toHaveBeenCalledTimes(1);
3131
expect(logInfoSpy).toHaveBeenCalledWith(
32-
'[foo]:',
32+
'[foo]',
3333
'bar',
34-
'[Issue]: I am a robot and this is a test! for repository gitify-app/notifications-test',
34+
'[Issue >> gitify-app/notifications-test >> I am a robot and this is a test!]',
3535
);
3636
});
3737
});
@@ -41,17 +41,17 @@ describe('renderer/utils/logger.ts', () => {
4141
logWarn('foo', 'bar');
4242

4343
expect(logWarnSpy).toHaveBeenCalledTimes(1);
44-
expect(logWarnSpy).toHaveBeenCalledWith('[foo]:', 'bar');
44+
expect(logWarnSpy).toHaveBeenCalledWith('[foo]', 'bar');
4545
});
4646

4747
it('log warn with notification', () => {
4848
logWarn('foo', 'bar', mockSingleNotification);
4949

5050
expect(logWarnSpy).toHaveBeenCalledTimes(1);
5151
expect(logWarnSpy).toHaveBeenCalledWith(
52-
'[foo]:',
52+
'[foo]',
5353
'bar',
54-
'[Issue]: I am a robot and this is a test! for repository gitify-app/notifications-test',
54+
'[Issue >> gitify-app/notifications-test >> I am a robot and this is a test!]',
5555
);
5656
});
5757
});
@@ -61,17 +61,17 @@ describe('renderer/utils/logger.ts', () => {
6161
logError('foo', 'bar', mockError);
6262

6363
expect(logErrorSpy).toHaveBeenCalledTimes(1);
64-
expect(logErrorSpy).toHaveBeenCalledWith('[foo]:', 'bar', mockError);
64+
expect(logErrorSpy).toHaveBeenCalledWith('[foo]', 'bar', mockError);
6565
});
6666

6767
it('log error with notification', () => {
6868
logError('foo', 'bar', mockError, mockSingleNotification);
6969

7070
expect(logErrorSpy).toHaveBeenCalledTimes(1);
7171
expect(logErrorSpy).toHaveBeenCalledWith(
72-
'[foo]:',
72+
'[foo]',
7373
'bar',
74-
'[Issue]: I am a robot and this is a test! for repository gitify-app/notifications-test',
74+
'[Issue >> gitify-app/notifications-test >> I am a robot and this is a test!]',
7575
mockError,
7676
);
7777
});

src/shared/logger.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ function logMessage(
1010
err?: Error,
1111
notification?: Notification,
1212
) {
13-
const args: (string | Error)[] = [`[${type}]:`, message];
13+
const args: (string | Error)[] = [`[${type}]`, message];
1414

1515
if (notification) {
1616
args.push(
17-
`[${notification.subject.type}]: ${notification.subject.title} for repository ${notification.repository.full_name}`,
17+
`[${notification.subject.type} >> ${notification.repository.full_name} >> ${notification.subject.title}]`,
1818
);
1919
}
2020

@@ -44,7 +44,7 @@ export function logWarn(
4444
export function logError(
4545
type: string,
4646
message: string,
47-
err?: Error,
47+
err: Error,
4848
notification?: Notification,
4949
) {
5050
logMessage(log.error, type, message, err, notification);

0 commit comments

Comments
 (0)