-
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
Log refactoring #193
Log refactoring #193
Changes from all commits
79606f4
17e3b38
4334f0a
904866e
b46cbd9
72b0b86
281fa20
9c7177a
6278662
8ad8f28
82b3f36
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { BudgetTrackingEventEmitter, EventPublisher } from '@/backend/eventEmitters/EventEmitter'; | ||
|
||
interface Logger { | ||
info: (...params: any[]) => void | ||
} | ||
|
||
export function buildLoggerEmitter(logger: Logger): EventPublisher { | ||
const loggerEmitter = new BudgetTrackingEventEmitter(); | ||
loggerEmitter.onAny((eventName, eventData) => { | ||
logger.info(`${eventName}:`, eventData); | ||
}); | ||
return loggerEmitter; | ||
} | ||
Comment on lines
+1
to
+13
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. This is not a very smart method, but it is here for a reason. Here, in the So, continuously, we can use this method to
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
import { App } from 'electron'; | ||
import logger from 'electron-log'; | ||
import { App } from '@/app-globals'; | ||
import logger, { LogFunctions, LogLevel } from 'electron-log'; // eslint-disable-line no-restricted-imports | ||
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. If you will try to |
||
import fs from 'fs'; | ||
import { EOL } from 'os'; | ||
import path from 'path'; | ||
|
||
declare module 'electron-log' { | ||
interface ElectronLog { | ||
getLastLines: (n: number) => string | ||
} | ||
} | ||
export type Logger = LogFunctions | ||
export type Levels = LogLevel | ||
|
||
export default function CreateLogger(app: App) { | ||
logger.info(`Welcome to ${app.getName()} log`); | ||
logger.info(`Version: ${app.getVersion()}`); | ||
logger.info(`Welcome to ${App.getName()} log`); | ||
logger.info(`Version: ${App.getVersion()}`); | ||
|
||
const onError = (error: Error) => { | ||
logger.error(error.message ? error.message : error); | ||
if (error.stack) logger.debug(error.stack); | ||
}; | ||
logger.catchErrors({ onError }); | ||
const onError = (error: Error) => { | ||
logger.error(error.message || error); | ||
if (error.stack) logger.debug(error.stack); | ||
}; | ||
logger.catchErrors({ onError }); | ||
Comment on lines
+13
to
+17
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. Note, this catching only the At least for the Vue part, we need to open a new issue to catch exceptions during the render process (I even can't say what exactly happened during such case. For in React, for example, the component tree will crash- if you're not using error boundary) 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. |
||
|
||
logger.getLastLines = (n) => { | ||
const lines = fs.readFileSync(logger.transports.file.getFile().path).toString().split(EOL); | ||
const lastLines = lines.slice(lines.length - n); | ||
return lastLines.join(EOL); | ||
}; | ||
export const getLastLines = (n: number) => { | ||
const lines = fs.readFileSync(logger.transports.file.getFile().path).toString().split(EOL); | ||
const lastLines = lines.slice(lines.length - n); | ||
return lastLines.join(EOL); | ||
}; | ||
|
||
return logger; | ||
} | ||
export const getLogsFolder = () => path.dirname(logger.transports.file.getFile().path); | ||
|
||
export default logger as Logger; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,8 @@ | |
</v-row> | ||
</v-container> | ||
<small>*indicates required field</small> | ||
<br> | ||
<small>You can find the logs here: {{ logsDir }}</small> | ||
Comment on lines
+63
to
+64
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. |
||
</v-form> | ||
</v-card-text> | ||
<v-card-actions> | ||
|
@@ -95,6 +97,8 @@ import { shell } from 'electron'; | |
import Sentry from '@/logging/sentry'; | ||
import LogSheet from '@/ui/components/shared/LogSheet'; | ||
import os from 'os'; | ||
import { getLastLines, getLogsFolder } from '@/logging/logger'; | ||
import { defineComponent } from '@vue/composition-api'; | ||
import { repository } from '../../../../package.json'; | ||
|
||
const createGithubIssueLink = (title, details, log) => { | ||
|
@@ -130,7 +134,7 @@ const defaultFormData = { | |
attachLogs: true, | ||
}; | ||
|
||
export default { | ||
export default defineComponent({ | ||
name: 'ReportProblemDialog', | ||
components: { LogSheet }, | ||
props: { | ||
|
@@ -146,6 +150,7 @@ export default { | |
validateEmail: false, | ||
formData: { ...defaultFormData }, | ||
raw: null, | ||
logsDir: getLogsFolder() | ||
}; | ||
}, | ||
computed: { | ||
|
@@ -193,12 +198,12 @@ export default { | |
} | ||
}, | ||
resetForm() { | ||
this.raw = this.$logger.getLastLines(10); | ||
this.raw = getLastLines(10); | ||
this.formData = { ...defaultFormData }; | ||
this.validateEmail = false; | ||
}, | ||
}, | ||
}; | ||
}); | ||
</script> | ||
|
||
<style> | ||
|
This file was deleted.
This file was deleted.
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.
Please review