Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'electron-log' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
const { remote } = window.require('electron');
let remoteLog = {};
if (remote) {
remoteLog = remote.require('electron-log');
} else {
remoteLog = {
info: () => {},
error: () => {},
warn: () => {}
};
}
const logFormat = '{level} | {y}-{m}-{d} {h}:{i}:{s}:{ms} | {text}';
log.transports.file.level = false;
if (process.env.NODE_ENV === 'production') {
log.transports.console.level = false;
} else {
log.transports.console.level = 'debug';
log.transports.console.format = logFormat;
}
let logger;
if (process.env.NODE_ENV !== 'production') {
logger = log;
} else {
logger = remoteLog;
}
(() => {
// saving the original console.log function
// const preservedConsoleLog = console.log;
// const preservedConsoleError = console.error;
} from './constants/storage';
// Utils
import IpcApiMain from './utils/IpcApiMain';
import { defaultRouting, defaultUi } from './utils/DefaultStates';
import SettingsStorage from './utils/SettingsStorage';
// Main window
import MenuBuilder from './main/MenuBuilder';
import TrayBuilder from './main/Tray';
// Initialize store to share it between windows
import configureStore from './store';
// Set level
log.transports.file.level = 'debug';
log.transports.console.level = 'debug';
log.info(app.getPath('userData'));
// Define auto updater
autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'debug';
log.info('App starting...');
// Window, store, history etc. references
let mainWindow = null;
let entriesWindow = null;
let editWindow = null;
let trayBuilder = null;
let store = null;
let ipcApiMain = null;
import logger from 'electron-log'
import moment from 'moment'
import util from 'util'
const level = process.env.NODE_ENV === 'development' ? 'debug' : 'silly'
logger.transports.console.format = '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}] {text}'
logger.transports.console.level = level
logger.transports.file.fileName = `${moment().format('YYYY-MM-DD')}.log`
logger.transports.file.level = level
const styles = {
// styles
bold: [1, 22],
italic: [3, 23],
underline: [4, 24],
inverse: [7, 27],
// grayscale
white: [37, 39],
grey: [90, 39],
black: [90, 39],
// colors
blue: [34, 39],
cyan: [36, 39],
green: [32, 39],
magenta: [35, 39],
const {app, ipcMain, protocol, BrowserWindow, dialog} = require('electron');
const fs = require('fs');
const path = require('path');
const url = require('url');
const log = require('electron-log');
let mainWindow;
log.transports.file.level = 'info'
log.transports.console.level = 'info'
const squirrelEvent = process.argv[1];
log.info('Squirrel event: ' + squirrelEvent);
if(require('electron-squirrel-startup'))
{
return;
}
function interceptFileProtocol() {
// Intercept the file protocol so that references to folders return its index.html file
const fileProtocol = 'file';
const cwd = process.cwd();
protocol.interceptFileProtocol(fileProtocol, (request, callback) => {
const fileUrl = new url.URL(request.url);
// Workaround: Global does not allow setting custom properties.
// We need to cast it to "any" first.
var globalAny = global;
// Workaround to send messages between Electron windows
var EventEmitter = require('events');
var GlobalEventEmitter = /** @class */ (function (_super) {
__extends(GlobalEventEmitter, _super);
function GlobalEventEmitter() {
return _super !== null && _super.apply(this, arguments) || this;
}
return GlobalEventEmitter;
}(EventEmitter));
;
globalAny.globalEmitter = new GlobalEventEmitter();
// By default, electron-log logs only to file starting from level 'warn'. We also want 'info'.
electron_log_1.default.transports.file.level = 'info';
function createWindow() {
var gotTheLock = electron_1.app.requestSingleInstanceLock();
if (!gotTheLock) {
electron_1.app.quit();
}
else {
electron_1.app.on('second-instance', function (event, commandLine, workingDirectory) {
// Someone tried to run a second instance, we should focus our window.
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
mainWindow.focus();
}
});
// Load the previous state with fallback to defaults
fs.mkdirSync(customLogsFolder, { recursive: true });
}
app.setPath('logs', customLogsFolder);
}
if (isLinux) {
this.logPath = app.getPath('appData');
} else {
this.logPath = app.getPath('logs');
}
if (app.isPackaged) {
transports.file.file = path.join(this.logPath, `app_${Date.now()}.log`);
transports.file.level = 'debug';
transports.file.format = '{y}-{m}-{d} {h}:{i}:{s}:{ms} {z} | {level} | {text}';
transports.file.appName = 'Symphony';
}
const logLevel = getCommandLineArgs(process.argv, '--logLevel=', false);
if (logLevel) {
const level = logLevel.split('=')[1];
if (level) {
this.desiredLogLevel = level as LogLevel;
}
}
if (getCommandLineArgs(process.argv, '--enableConsoleLogging', false)) {
this.showInConsole = true;
}
// cleans up old logs if there are any
if (app.isPackaged) {
if (!fs.existsSync(customLogsFolder)) {
fs.mkdirSync(customLogsFolder, { recursive: true });
}
app.setPath('logs', customLogsFolder);
}
if (isLinux) {
this.logPath = app.getPath('appData');
} else {
this.logPath = app.getPath('logs');
}
if (app.isPackaged) {
transports.file.file = path.join(this.logPath, `app_${Date.now()}.log`);
transports.file.level = 'debug';
transports.file.format = '{y}-{m}-{d} {h}:{i}:{s}:{ms} {z} | {level} | {text}';
transports.file.appName = 'Symphony';
}
const logLevel = getCommandLineArgs(process.argv, '--logLevel=', false);
if (logLevel) {
const level = logLevel.split('=')[1];
if (level) {
this.desiredLogLevel = level as LogLevel;
}
}
if (getCommandLineArgs(process.argv, '--enableConsoleLogging', false)) {
this.showInConsole = true;
}
// cleans up old logs if there are any
import { app, BrowserWindow } from 'electron';
import is from 'electron-is';
import { join } from 'path';
import log from 'electron-log';
import * as application from './services/application';
import * as window from './services/window';
import * as menu from './services/menu';
import * as config from './configs/config';
log.transports.file.level = 'info';
log.info('(main/index) >>>>>>>>>>>>>>>>>>');
log.info('(main/index) app start');
log.info(`(main/index) log file at ${log.findLogPath()}`);
if (is.dev()) {
require('electron-debug')(); // eslint-disable-line global-require
}
app.on('ready', () => {
log.info('(main/index) app ready');
application.init();
menu.init();
// 加载 devtools extension
if (is.dev()) {
BrowserWindow.addDevToolsExtension(
join($dirname, '../../extensions/redux-devtools/2.11.1_0'),
);
BrowserWindow.addDevToolsExtension(
import { app, BrowserWindow } from 'electron';
import is from 'electron-is';
import { join } from 'path';
import log from 'electron-log';
import * as application from './services/application';
import * as window from './services/window';
import * as menu from './services/menu';
import * as davAst from './services/dva-ast';
import * as config from './configs/config';
log.info('(main/index) >>>>>>>>>>>>>>>>>>');
log.info('(main/index) app start');
log.info(`(main/index) log file at ${log.findLogPath()}`);
app.on('ready', () => {
log.info('(main/index) app ready');
application.init();
menu.init();
davAst.init();
// 加载 devtools extension
if (is.dev()) {
BrowserWindow.addDevToolsExtension(
join($dirname, '../../extensions/redux-devtools/2.11.1_0'),
);
BrowserWindow.addDevToolsExtension(
join($dirname, '../../extensions/react-developer-tools/0.15.4_0'),
);
}
// fix framenumber, insert it and decrease i again
// so it loops through it again to check
// if first frame missing fill it with default object
let correctedDuplicate;
if (i === 0) {
correctedDuplicate = Object.assign({}, {
frameNumber: 0,
meanColor: "[0,0,0]",
differenceValue: 0,
});
} else {
correctedDuplicate = Object.assign({}, arrayOfFrameScanData[i-1]);
correctedDuplicate.frameNumber = i;
}
log.info(`repaired frameScanData at: ${i}`);
arrayOfFrameScanData.splice(i, 0, correctedDuplicate);
i -= 1;
}
}
// no return is needed as arrayOfFrameScanData gets repaired in place
}