7.6.112 • Published 10 months ago

@patrtorg/asperiores-rerum v7.6.112

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

electron-log

Tests NPM version Downloads

Simple logging module Electron/Node.js/NW.js application. No dependencies. No complicated configuration.

By default, it writes logs to the following locations:

  • on Linux: ~/.config/{app name}/logs/main.log
  • on macOS: ~/Library/Logs/{app name}/main.log
  • on Windows: %USERPROFILE%\AppData\Roaming\{app name}\logs\main.log

Installation

Starts from v5, electron-log requires Electron 13+ or Node.js 14+. Feel free to use electron-log v4 for older runtime. v4 supports Node.js 0.10+ and almost any Electron build.

Install with npm:

npm install electron-log

Usage

Main process

import log from 'electron-log/main';

// Optional, initialize the logger for any renderer process
log.initialize();

log.info('Log from the main process');

Renderer process

If a bundler is used, you can just import the module:

import log from 'electron-log/renderer';
log.info('Log from the renderer process');

This function uses sessions to inject a preload script to make the logger available in a renderer process.

Without a bundler, you can use a global variable __electronLog. It contains only log functions like info, warn and so on.

There are a few other ways how a logger can be initialized for a renderer process. Read more.

Node.js and NW.js

import log from 'electron-log/node';
log.info('Log from the nw.js or node.js');

electron-log v2.x, v3.x, v4.x

If you would like to upgrade to the latest version, read the migration guide and the changelog.

Log levels

electron-log supports the following log levels:

error, warn, info, verbose, debug, silly

Transport

Transport is a simple function which does some work with log message. By default, two transports are active: console and file.

You can set transport options or use methods using:

log.transports.console.format = '{h}:{i}:{s} {text}';

log.transports.file.getFile();

Each transport has level and transforms options.

Console transport

Just prints a log message to application console (main process) or to DevTools console (renderer process).

Options
  • format, default '%c{h}:{i}:{s}.{ms}%c › {text}' (main), '{h}:{i}:{s}.{ms} › {text}' (renderer)
  • level, default 'silly'
  • useStyles, force enable/disable styles

Read more about console transport.

File transport

The file transport writes log messages to a file.

Options
  • format, default '[{y}-{m}-{d} {h}:{i}:{s}.{ms}] [{level}] {text}'
  • level, default 'silly'
  • resolvePathFn function sets the log path, for example

log.transports.file.resolvePathFn = () => path.join(APP_DATA, 'logs/main.log');

Read more about file transport.

IPC transport

It displays log messages from main process in the renderer's DevTools console. By default, it's disabled for a production build. You can enable in the production mode by setting the level property.

Options
  • level, default 'silly' in the dev mode, false in the production.

Remote transport

Sends a JSON POST request with LogMessage in the body to the specified url.

Options
  • level, default false
  • url, remote endpoint

Read more about remote transport.

Disable a transport

Just set level property to false, for example:

log.transports.file.level = false;
log.transports.console.level = false;

Override/add a custom transport

Transport is just a function (msg: LogMessage) => void, so you can easily override/add your own transport. More info.

Third-party transports

Overriding console.log

Sometimes it's helpful to use electron-log instead of default console. It's pretty easy:

console.log = log.log;

If you would like to override other functions like error, warn and so on:

Object.assign(console, log.functions);

Colors

Colors can be used for both main and DevTools console.

log.info('%cRed text. %cGreen text', 'color: red', 'color: green')

Available colors:

  • unset (reset to default color)
  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white

For DevTools console you can use other CSS properties.

Catch errors

electron-log can catch and log unhandled errors/rejected promises:

log.errorHandler.startCatching(options?);

More info.

Electron events logging

Sometimes it's helpful to save critical electron events to the log file.

log.eventLogger.startLogging(options?);

By default, it save the following events:

  • certificate-error, child-process-gone, render-process-gone of app
  • crashed, gpu-process-crashed of webContents
  • did-fail-load, did-fail-provisional-load, plugin-crashed, preload-error of every WebContents. You can switch any event on/off.

More info.

Hooks

In some situations, you may want to get more control over logging. Hook is a function which is called on each transport call.

(message: LogMessage, transport: Transport, transportName) => LogMessage

More info.

Multiple logger instances

You can create multiple logger instances with different settings:

import log from 'electron-log/main';

const anotherLogger = log.create({ logId: 'anotherInstance' });

Be aware that you need to configure each instance (e.g. log file path) separately.

Logging scopes

import log from 'electron-log/main';
const userLog = log.scope('user');

userLog.info('message with user scope');
// Prints 12:12:21.962 (user) › message with user scope

Related

classesuuidquerylanguageargspolyfillexpresschineselockfilevestObject.valuesrequirergbtslibfunctionalshrinkwrapfullrouterscheme-validationcircularspeedpackageeffect-tshasOwnPropertysharedarraybufferstylehookscallboundglacierfp__proto__ajvchildwhichtypanionnodejs.gitignoreendermoveserializationpackage manageryupObject.keystranspile3dcurlgroupByECMAScript 2021sinatraeslintreadableBigUint64ArrayjQueryassignjestpureramdasqsdebugintrinsichasWebSocketzxkinesises2018emojijson-schematypescriptlook-upqsCSSgetoptroutingpnpm9viewhelpersownweakmapchecktypesflattenglobalArray.prototype.filterphonepathflagsinferencevalidatorpicomatchstreamsprefixtrimefficientwgetformatschemainternalperformancevariablesredux-toolkitsuperstructhas-ownjson-schema-validatorES2016requestspinnerscollectionshamreact poselinkwriteESnextURLSearchParamsisxhrupprettytypedarrayrestquotestyled-componentscharacterslocalerrordescriptionmomentES2023iammapsidenopeReactiveExtensionscomputed-typesArray.prototype.containsfastifymodulelastrules$.extendvalidECMAScript 2015-0consoleiteratejsonenvflatfunctionsdefinePropertymake dirECMAScript 3a11yworkspace:*toSortednegative zero[[Prototype]]ES2021setterprotobuffetchparserapollofiletypedgettacitbinaryimportexportObject.getPrototypeOffsserializeweaksetfast-deep-copysuperagenttextamazonworkflowcollection.es6ECMAScript 2017posesubprocesss3springlocationiedeep-clone@@toStringTagmetadatainvariantmodulesfast-deep-cloneprotoPromiseES2022debuggergetterdirworker0es6RegExp#flagsES2018tapeclass-validatorperformantidentifiersfastforkglobal this valueeventDispatcherfullwidthObservableeast-asian-widthflagwindowcall-bindidledirectoryterminalecmascriptCSSStyleDeclarationestreeelasticacheoptimizertoReversedarraybuffernpmInt32ArraypreprocessorflatMaptrimLeftinstallerjsxqueueMicrotasktsdayjsmanipulationES2017utiltimewidthconstcliECMAScript 2019global objectrapidimmutablecore-jstermstoragegatewaytestsymbolpropECMAScript 6inspectcloudtrailstylingnumberimmerfpsRxJSmobileoutputcallbeanstalkequalcssbrowserlistenvironmentshelpervarsdeterministicdependenciesfromkeysacornstreamemrnodefastcopyhtmlfunctiondom-testing-librarypluginreducermkdirpisConcatSpreadablemergeMicrosoftgetOwnPropertyDescriptortddrandomes7StreamglobalsdeepcloneES6command-lineclassnameIteratorjssymlinksjsdomhashUint8ArrayatomartequalitydeepparentsAsyncIteratorRxjsonschemaReflect.getPrototypeOftouchcommandcolourredactawssomesettingsloadingObject.definePropertydataViewpopmotionStyleSheetsource mapreversedponyfillspecoptimistMapdotenvreal-timeconcatstringifierelectronTypedArraytrimRightpinoSymbol.toStringTagwaitanimationString.prototype.trimreact-testing-libraryexpressionstyleguidesyntaxerrorwaapiresolveESbundlingutilitiesrfc4122vpcdataviewroutebyteLengthslicecontainsuser-streamsparseprocesscode pointsobjfind-upregexObject.assignformescapeloadbalancingglobalThisreuseshimutilswhatwgdynamodbfantasy-landpositivecallbindquerystringutil.inspectURLserializerstylescss-in-jstrimEndArray.prototype.flattensetlogaccessibilitybrowserslistasyncWeakMapcloudfrontchaiselfHyBispawnfunction.lengthStreamshookformfeedstablermdirletrangeerroryamlObjectRegExp.prototype.flagstoArrayclonevaluebuffersidmonoreporeduceobjectstringregexptypeerrorgesturesdeletedragtransportloggerfast-clonexmlfile systemcolumnautoscalingjoisearchcopybytebabel-coreSymbolreact animationpruneReactiveXasteriskstc39var6to5espreeruntimemkdires5zodcoerciblebabeljapanesetaproute53corereactgenericsArrayBuffer.prototype.slicees2015proxyeventstypesafereworkreact-hooksebsmochamanagerargvgroupautoprefixerSystem.globalframerassertrmtakeexecutecallbackcurriedjasminewebdomansiignorewalkingwarningFloat32Arrayhttpregular expressionentrieslintArray.prototype.findLastsetPrototypeOflibphonenumberTypeBoxkoreantransforml10ncensorfindLastInt16Arrayassertionqueuees-shim APIECMAScriptuninstalldeep-copyregulares2016cjkendpointconcatMapcloudsearchlruSetbinclassnamesclientRFC-6455WebSocketspropertiesArrayBufferbannerfolder_.extendelbprivatetypedarraysrm -frloggingrestfulistanbulsortparentECMAScript 5astio-tsUnderscorenpmignoregdprArrayshebangpyyamlfindupeslintconfiges-abstractjsdiffdropspinnersetImmediateindicatorconfigpostcss-pluginObject.iswritabledeepcopyES7wafbddcodesgetPrototypeOfttypostcssdependency managerapiinthreecall-boundfiltershelljavascriptbufferECMAScript 2016findLastIndexstringifyinstallfindpropertyxtermhasOwnextraextendemittraversetrimStartsesES3execfiledefineharmonyjshintargumentcompilertoolkitsnsiteratorvaluesframeworktelephonetranspilerUint32Arrayarraytoobjectcommandereslint-pluginregular expressionswalkES5simpledbairbnbbyteOffsetomitdescriptorFloat64ArrayschemehttpsYAMLUint16Arrayboundes2017urleverypoint-freeinputeslintpluginfastclonecomparematchmatchAllmkdirsArray.prototype.flatvalidationenvironmentcoverageformsbinariesTypeScriptArray.prototype.findLastIndexarktypetypeprototypevisualfnmatchform-validationrdsappoptionchromesymbolssharedtoStringTagECMAScript 2022readforEachprotocol-buffersstarterpipehardlinksrecursivetostringtagminimalunicodesyntaxbusyreact-hook-formonceglobfull-widthInt8ArraycolorES8utilitypushJSON-Schemaregular-expressionaccessorWeakSetstructuredClonecryptozeroObservablesECMAScript 2020safeformattingECMAScript 2023estoolsrm -rfremovegitignoreES2019graphqlarraysincludesawesomesauceslotsameValueZeronamescloudformationavachromiumnegativeinternal slotkeyexecprogressimportbindjson-schema-validationpatchObject.fromEntriesreadablestreamtypeof256Uint8ClampedArraykarmaes8swfguidmru.envconfigurableeventEmitterrobustsorteddiffagentoffsetajaxcachebundlercharacterinstrumentationFunction.prototype.namepackagesprivate dataes-shimsgetintrinsictesterdatacloudwatchArrayBuffer#slicedescriptorsnativepackage.jsonArray.prototype.includesPushlengthString.prototype.matchAllnamehigher-orderES2020
7.6.112

10 months ago

7.6.111

10 months ago

7.6.110

10 months ago

7.6.109

10 months ago

7.5.108

10 months ago

7.5.107

10 months ago

7.5.109

10 months ago

7.5.106

10 months ago

6.4.105

10 months ago

6.4.106

10 months ago

6.4.103

10 months ago

6.4.104

10 months ago

6.4.101

10 months ago

6.4.102

10 months ago

6.4.100

10 months ago

5.4.94

11 months ago

5.4.95

11 months ago

5.4.92

11 months ago

5.4.93

11 months ago

7.4.106

10 months ago

5.4.96

11 months ago

6.4.98

10 months ago

6.4.97

10 months ago

6.4.99

10 months ago

6.4.96

10 months ago

4.4.90

11 months ago

5.4.90

11 months ago

5.4.91

11 months ago

4.4.89

11 months ago

4.4.88

11 months ago

4.4.87

11 months ago

4.4.86

11 months ago

4.4.85

11 months ago

4.4.84

11 months ago

4.4.83

11 months ago

4.4.82

11 months ago

4.4.81

11 months ago

4.4.80

11 months ago

4.4.79

11 months ago

4.4.78

11 months ago

4.4.77

11 months ago

4.4.76

11 months ago

4.4.75

11 months ago

4.3.75

11 months ago

4.3.74

11 months ago

4.3.73

11 months ago

4.2.73

11 months ago

4.2.72

11 months ago

4.2.71

11 months ago

4.2.70

11 months ago

4.2.69

12 months ago

4.2.68

12 months ago

4.2.67

12 months ago

4.2.66

12 months ago

3.2.66

12 months ago

3.2.65

12 months ago

3.2.64

12 months ago

3.2.63

12 months ago

3.2.62

12 months ago

3.1.62

12 months ago

3.1.61

12 months ago

3.0.61

12 months ago

3.0.60

12 months ago

3.0.59

12 months ago

3.0.58

12 months ago

3.0.57

12 months ago

3.0.56

12 months ago

3.0.55

12 months ago

3.0.54

12 months ago

3.0.53

12 months ago

3.0.52

1 year ago

3.0.51

1 year ago

3.0.50

1 year ago

3.0.49

1 year ago

3.0.48

1 year ago

3.0.47

1 year ago

3.0.46

1 year ago

3.0.45

1 year ago

3.0.44

1 year ago

3.0.43

1 year ago

3.0.42

1 year ago

3.0.41

1 year ago

3.0.40

1 year ago

3.0.39

1 year ago

3.0.38

1 year ago

3.0.37

1 year ago

2.0.37

1 year ago

2.0.36

1 year ago

2.0.35

1 year ago

2.0.34

1 year ago

2.0.33

1 year ago

2.0.32

1 year ago

2.0.31

1 year ago

2.0.30

1 year ago

2.0.29

1 year ago

2.0.28

1 year ago

2.0.27

1 year ago

2.0.26

1 year ago

2.0.25

1 year ago

2.0.24

1 year ago

2.0.23

1 year ago

2.0.22

1 year ago

2.0.21

1 year ago

2.0.20

1 year ago

2.0.19

1 year ago

2.0.18

1 year ago

2.0.17

1 year ago

2.0.16

1 year ago

2.0.15

1 year ago

2.0.14

1 year ago

2.0.13

1 year ago

2.0.12

1 year ago

2.0.11

1 year ago

2.0.10

1 year ago

2.0.9

1 year ago

2.0.8

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago