Skip to content

log unhandled exceptions to flat file - #850

Merged
joshaber merged 32 commits into
masterfrom
log-unhandled-exceptions
Feb 8, 2017
Merged

joshaber merged 32 commits into
masterfrom
log-unhandled-exceptions

Conversation

@shiftkey

@shiftkey shiftkey commented Jan 25, 2017 •

Copy link
Copy Markdown
Member

🌵 🌵 Go review #849 first so I can test this failing behaviour before merging master 🌵🌵

A simpler version of #833:

  • logging unhandled exceptions to a flat file in a known location
  • logs organized by date
  • catch everywhere we're listening to uncaughtException, but we can expand this out to other parts of the app
  • added a dev mode option to throw an exception (this came from the classic Windows app)

Here's what it looks like (for development mode):

$ less ~/Library/Logs/GitHub/2017-01-25.desktop.development.log
2017-01-25T12:29:47.163Z - error: uncaughtException: Boomtown! date=Wed Jan 25 2017 13:29:47 GMT+0100 (CET), pid=18800, uid=501, gid=20, cwd=/Users/shiftkey/src/desktop, execPath=/Users/shiftkey/src/desktop/dist/GitHub Desktop-dev-darwin-x64/GitHub Desktop-dev.app/Contents/MacOS/GitHub Desktop-dev, version=v6.5.0, argv=[/Users/shiftkey/src/desktop/dist/GitHub Desktop-dev-darwin-x64/GitHub Desktop-dev.app/Contents/MacOS/GitHub Desktop-dev], rss=110858240, heapTotal=21008384, heapUsed=12780752, loadavg=[1.986328125, 1.73486328125, 1.62451171875], uptime=18502
Error: Boomtown!
    at click (eval at <anonymous> (/Users/shiftkey/src/desktop/dist/GitHub Desktop-dev-darwin-x64/GitHub Desktop-dev.app/Contents/Resources/app/main.js:677:2), <anonymous>:239:23)
    at MenuItem.click (/Users/shiftkey/src/desktop/dist/GitHub Desktop-dev-darwin-x64/GitHub Desktop-dev.app/Contents/Resources/electron.asar/browser/api/menu-item.js:52:9)
    at Function.executeCommand (/Users/shiftkey/src/desktop/dist/GitHub Desktop-dev-darwin-x64/GitHub Desktop-dev.app/Contents/Resources/electron.asar/browser/api/menu.js:121:15)
2017-01-25T12:29:47.176Z - error: Uncaught exception on main process

Comment thread app/src/lib/logging/index.ts Outdated
return `${process.env.LOCALAPPDATA}\\desktop\\${getFileName()}`
} else {
const home = Os.homedir()
return `${home}/Library/Logs/GitHub/${getFileName()}`

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/lib/logging/index.ts Outdated
winston.configure({
transports: [
// log everything to the console
new ElectronConsole(),

This comment was marked as spam.

@shiftkey shiftkey changed the title log unhandled exceptions to flat file [WIP] log unhandled exceptions to flat file Jan 25, 2017
@shiftkey
shiftkey force-pushed the log-unhandled-exceptions branch from 111fab4 to 399b541 Compare January 30, 2017 13:49
@shiftkey
shiftkey force-pushed the log-unhandled-exceptions branch from 62f84c9 to caa0947 Compare January 30, 2017 14:30
@shiftkey shiftkey changed the title [WIP] log unhandled exceptions to flat file log unhandled exceptions to flat file Jan 31, 2017
@shiftkey

Copy link
Copy Markdown
Member Author

Ready for review 🐱

@joshaber joshaber self-assigned this Jan 31, 2017

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome ⏯

Comment thread app/src/lib/logging/electron-console.ts Outdated
import * as winston from 'winston'
const Transport = winston.Transport

type LogLevel = 'emerg' | 'alert' | 'crit' | 'error' | 'warning' | 'notice' | 'info' | 'debug';

This comment was marked as spam.


type LogLevel = 'emerg' | 'alert' | 'crit' | 'error' | 'warning' | 'notice' | 'info' | 'debug';

export class ElectronConsole extends Transport {

This comment was marked as spam.

Comment thread app/src/lib/logging/electron-console.ts Outdated

export class ElectronConsole extends Transport {

public constructor(options?: winston.ConsoleTransportOptions) {

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/lib/logging/index.ts Outdated
return `${process.env.LOCALAPPDATA}\\desktop\\${getFileName()}`
} else {
const home = Os.homedir()
return `${home}/Library/Logs/GitHub/${getFileName()}`

This comment was marked as spam.

Comment thread app/src/lib/logging/index.ts Outdated
return `${process.env.LOCALAPPDATA}\\desktop\\${getFileName()}`
} else {
const home = Os.homedir()
return `${home}/Library/Logs/GitHub/${getFileName()}`

This comment was marked as spam.

Comment thread app/src/lib/logging/index.ts Outdated
}

const filename = getLogFilePath()
createDirectoryIfNotFound(filename)

This comment was marked as spam.

@shiftkey shiftkey changed the title log unhandled exceptions to flat file [WIP] log unhandled exceptions to flat file Feb 1, 2017
Comment thread app/src/lib/logging/index.ts Outdated

// TODO: confirm that one logger is instantiated once for the renderer process
// and once for the main process
let logger: ILogger | null = null

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/lib/logging/index.ts Outdated
// and once for the main process
let logger: ILogger | null = null

export function getLogger(directory: string): ILogger {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@shiftkey

shiftkey commented Feb 7, 2017

Copy link
Copy Markdown
Member Author

🍎

@joshaber joshaber left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥝

Comment thread app/src/lib/logging/index.ts Outdated
import { ElectronConsole } from './electron-console'

interface ILogger {
filename: string,

This comment was marked as spam.

This comment was marked as spam.

Comment thread app/src/lib/logging/index.ts Outdated

// TODO: confirm that one logger is instantiated once for the renderer process
// and once for the main process
let logger: ILogger | null = null

This comment was marked as spam.

Comment thread script/test-review

if (process.platform === 'darwin') {
if (process.env.TRAVIS_TEST_RESULT === '1') {
reviewLogs()

This comment was marked as spam.

Comment thread app/src/lib/logging/index.ts Outdated
// and once for the main process
let logger: ILogger | null = null

export function getLogger(directory: string): ILogger {

This comment was marked as spam.

@shiftkey

shiftkey commented Feb 8, 2017

Copy link
Copy Markdown
Member Author

🍏

@joshaber

joshaber commented Feb 8, 2017

Copy link
Copy Markdown
Contributor

🎂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants