-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: logging and empty config #601
Changes from 7 commits
50e2f64
0d1bcd0
62359be
8002010
cf9059d
526ce96
659052b
7f0c9fd
32fbb8e
33ecde1
c8c8c4d
962db48
3b43699
fa43470
2263ae5
78f0ff0
29ba933
b2e2878
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
import { App } from '@/app-globals'; | ||
import logger, { | ||
type LogFunctions, | ||
type LogLevel, | ||
type MainErrorHandlerOptions, | ||
} from 'electron-log'; // eslint-disable-line no-restricted-imports | ||
import type { | ||
LogFunctions, | ||
LogLevel, | ||
MainErrorHandlerOptions, | ||
} from 'electron-log'; | ||
import log from 'electron-log/main'; | ||
import fs from 'fs'; | ||
import { EOL } from 'os'; | ||
import path from 'path'; | ||
|
||
log.initialize(); | ||
|
||
// This will transport the logs to the renderer process (DevTools) in production too | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please remove comment |
||
log.transports.ipc.level = log.transports.file.level; | ||
|
||
Object.assign(console, log.functions); | ||
const logger = log.scope('main'); | ||
Comment on lines
+12
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
export type Logger = LogFunctions; | ||
export type Levels = LogLevel; | ||
|
||
|
@@ -18,19 +27,20 @@ const onError: MainErrorHandlerOptions['onError'] = ({ error }) => { | |
logger.error(error.message || error); | ||
if (error.stack) logger.debug(error.stack); | ||
}; | ||
logger.errorHandler.startCatching({ onError }); | ||
logger.catchErrors({ onError }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deprecated |
||
log.errorHandler.startCatching({ onError }); | ||
|
||
export const getLastLines = (n: number) => { | ||
const lines = fs | ||
.readFileSync(logger.transports.file.getFile().path) | ||
.readFileSync(log.transports.file.getFile().path) | ||
.toString() | ||
.split(EOL); | ||
const lastLines = lines.slice(lines.length - n); | ||
return lastLines.join(EOL); | ||
}; | ||
|
||
export const getLogsFolder = () => | ||
path.dirname(logger.transports.file.getFile().path); | ||
path.dirname(log.transports.file.getFile().path); | ||
|
||
logger.info(`Logs folder: ${getLogsFolder()}`); | ||
|
||
export default logger as Logger; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { | ||
LogFunctions, | ||
LogLevel, | ||
MainErrorHandlerOptions, | ||
} from 'electron-log'; | ||
import log from 'electron-log/renderer'; | ||
|
||
const logger = log.scope('renderer'); | ||
|
||
export type Logger = LogFunctions; | ||
export type Levels = LogLevel; | ||
|
||
logger.info('Welcome to Caspion log'); | ||
logger.info('Version: <need implementation>'); | ||
|
||
const onError: MainErrorHandlerOptions['onError'] = ({ error }) => { | ||
logger.error(error.message || error); | ||
if (error.stack) logger.debug(error.stack); | ||
}; | ||
log.errorHandler.startCatching({ onError }); | ||
Object.assign(console, log.functions); | ||
|
||
export default logger as Logger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a fix for my case, when the config somehow became
{}
. (Locally on dev env)