6b11f67dc6
- Logging is available in main process as well as renderer process, and entries all go to one set of rotating files. Log entries in the renderer process go to DevTools as well as the console. Entries from the main process only show up in the console. - We save three days of logs, one day per file in %userData%/logs - The 'debug' object store is deleted in a new database migration - Timestamps and level included in the new log we generate for publish as well as the devtools - The bunyan API is exposed via windows.log (providing the ability to log at different levels, and save objects instead of just text), so we can move our code to it over time. FREEBIE
62 lines
1.3 KiB
JavaScript
62 lines
1.3 KiB
JavaScript
const path = require('path');
|
|
const fs = require('fs');
|
|
const app = require('electron').app;
|
|
const _ = require('lodash');
|
|
|
|
const logger = require('./logging').getLogger();
|
|
|
|
function normalizeLocaleName(locale) {
|
|
if (/^en-/.test(locale)) {
|
|
return 'en';
|
|
}
|
|
|
|
return locale;
|
|
}
|
|
|
|
function getLocaleMessages(locale) {
|
|
const onDiskLocale = locale.replace('-', '_');
|
|
|
|
const targetFile = path.join(
|
|
__dirname,
|
|
'..',
|
|
'_locales',
|
|
onDiskLocale,
|
|
'messages.json'
|
|
);
|
|
|
|
return JSON.parse(fs.readFileSync(targetFile, 'utf-8'));
|
|
}
|
|
|
|
function load() {
|
|
var english = getLocaleMessages('en');
|
|
|
|
// Load locale - if we can't load messages for the current locale, we
|
|
// default to 'en'
|
|
//
|
|
// possible locales:
|
|
// https://github.com/electron/electron/blob/master/docs/api/locales.md
|
|
let localeName = normalizeLocaleName(app.getLocale());
|
|
let messages;
|
|
|
|
try {
|
|
messages = getLocaleMessages(localeName);
|
|
|
|
// We start with english, then overwrite that with anything present in locale
|
|
messages = _.merge(english, messages);
|
|
} catch (e) {
|
|
logger.error('Problem loading messages for locale ' + localeName + ' ' + e.stack);
|
|
logger.error('Falling back to en locale');
|
|
|
|
localeName = 'en';
|
|
messages = english;
|
|
}
|
|
|
|
return {
|
|
name: localeName,
|
|
messages
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
load: load
|
|
};
|