-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Feature: add logs for picgo-server
ISSUES CLOSED: #627
- Loading branch information
1 parent
a657c51
commit 2d9e9c0
Showing
6 changed files
with
86 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { app } from 'electron' | ||
import fse from 'fs-extra' | ||
import path from 'path' | ||
import dayjs from 'dayjs' | ||
import util from 'util' | ||
const STORE_PATH = app.getPath('userData') | ||
const LOG_PATH = path.join(STORE_PATH, '/picgo.log') | ||
|
||
// since the error may occur in picgo-core | ||
// so we can't use the log from picgo | ||
const loggerWriter = (error: Error) => { | ||
let log = `${dayjs().format('YYYY-MM-DD HH:mm:ss')} [PicGo ERROR] startup error` | ||
if (error?.stack) { | ||
log += `\n------Error Stack Begin------\n${util.format(error.stack)}\n-------Error Stack End-------\n` | ||
} else { | ||
const msg = JSON.stringify(error) | ||
log += `${msg}\n` | ||
} | ||
fse.appendFileSync(LOG_PATH, log) | ||
} | ||
|
||
const handleProcessError = (error: Error) => { | ||
console.error(error) | ||
loggerWriter(error) | ||
} | ||
|
||
process.on('uncaughtException', error => { | ||
handleProcessError(error) | ||
}) | ||
|
||
process.on('unhandledRejection', (error: any) => { | ||
handleProcessError(error) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters