Skip to content
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

feat: improve logging #342

Merged
merged 6 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions main/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use strict'

const { app, dialog } = require('electron')
const log = require('electron-log')
const electronLog = require('electron-log')
const path = require('node:path')

console.log('Log file:', electronLog.transports.file.findLogPath())
Copy link
Member Author

Choose a reason for hiding this comment

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

My intention here is to make it easier to locate the electron-log file when troubleshooting problems. I am using console.log instead of electron-log because it feels redundant to log the filename of the log file into that log file.

Let me know if you thing otherwise!

const log = electronLog.scope('main')

// Override the place where we look for config files when running the end-to-end test suite.
// We must call this early on, before any of our modules accesses the config store.
// https://www.npmjs.com/package/electron-store
Expand All @@ -23,6 +26,7 @@ const { ActivityLog } = require('./activity-log')
const { BUILD_VERSION } = require('./consts')
const { JobStats } = require('./job-stats')
const { ipcMain } = require('electron/main')
const os = require('os')
const saturnNode = require('./saturn-node')
const serve = require('electron-serve')
const { setupAppMenu } = require('./app-menu')
Expand All @@ -38,7 +42,12 @@ const { setup: setupDialogs } = require('./dialog')
const inTest = (process.env.NODE_ENV === 'test')
const isDev = !app.isPackaged && !inTest

console.log('Filecoin Station build version:', BUILD_VERSION)
log.info('Filecoin Station build version: %s %s-%s%s%s', BUILD_VERSION, os.platform(), os.arch(), isDev ? ' [DEV]' : '', inTest ? ' [TEST]' : '')
log.info('Machine spec: %s version %s', os.type(), os.release())
// TODO(bajtos) print machine architecture after we upgrade to Electron with Node.js 18
// log.info('Machine spec: %s %s version %s', os.type(),
// os.machine(),
// os.release())

// Expose additional metadata for Electron preload script
process.env.STATION_BUILD_VERSION = BUILD_VERSION
Expand Down
6 changes: 4 additions & 2 deletions main/station-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const Store = require('electron-store')
const { randomUUID } = require('crypto')

const log = require('electron-log').scope('config')

const ConfigKeys = {
OnboardingCompleted: 'station.OnboardingCompleted',
TrayOperationExplained: 'station.TrayOperationExplained',
Expand All @@ -26,11 +28,11 @@ const configStore = new Store({
}
},
beforeEachMigration: (_, context) => {
console.log(`Migrating station-config from ${context.fromVersion} → ${context.toVersion}`)
log.info(`Migrating station-config from ${context.fromVersion} → ${context.toVersion}`)
}
})

console.log('Loading Station configuration from', configStore.path)
log.info('Loading Station configuration from', configStore.path)

let OnboardingCompleted = /** @type {boolean} */ (configStore.get(ConfigKeys.OnboardingCompleted, false))
let TrayOperationExplained = /** @type {boolean} */ (configStore.get(ConfigKeys.TrayOperationExplained, false))
Expand Down
1 change: 1 addition & 0 deletions main/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function beforeQuitCleanup () {
}

function setup (/** @type {import('./typings').Context} */ _ctx) {
autoUpdater.logger = log
autoUpdater.autoDownload = false // we download manually in 'update-available'

autoUpdater.on('error', onUpdaterError)
Expand Down