-
-
Notifications
You must be signed in to change notification settings - Fork 13
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
Split code for main/renderer, refactor and new features #19
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably fix linter errors ;)
@xxczaki I completely agree with you 😄 I will try to fix them ASAP. @sindresorhus Maybe it would be better to create a |
All linter errors fixed. Only remain 4 warnings due to |
I will try to find some time tomorrow to look through the code. It's a lot of changes. Looking at the output, it's not clear to me what the Right now it shows a unique name for each renderer, like |
That part of my output has nothing to do with
I create two different loggers in my project.
I think the best decision would be adding a new option @sindresorhus Let me know if I've clarified your doubts and what do you think about the |
Since all loggers are registered upfront, can you make it not show the column if there is only the
👍 But the option name is not clear enough. It needs to be something more explicit. |
I'm really sorry. I completely forgot about this PR. I looked at it many times, but it's a very big PR and it pretty much changes everything, so it's both time-consuming and daunting to review. Before I spend time on this, @cgalvarez are you still interested in finishing this and getting it merged? |
Closing as this PR has not seen any activity for a long time. I'm more than happy to reopen if you ever get a chance to finish this though :) |
I've tried my best to keep the code as short and concise as possible, and not adding new external deps (the only exception is the package
callsites
, maintained by @sindresorhus), but this PR has become something really big 😅Any insights/help will be greatly appreciated. Still missing some features that I would like to include.
New options
collector
(false
,"main"
,"renderer"
orid
; defaults to"main"
): the logger that will collect all the logger messages. All messages are logged on their original logger apart from the collector. This implements Add option to show main process output in the renderer #15 :false
: removes any collector and each side (main/renderer) collects its own messages."main"
: all logged messages are collected ontimber [main]
(default behavior until now)."renderer"
: all logged messages are collected on the first created browserWindow.id
: all logged messages are collected on the browserWindow with IDid
after it is created (all messages logged prior to its creation are only logged on their respective loggers).devToolsDarkTheme
(false
ortrue
; defaults tofalse
):true
if electron app is using the devTools dark theme,false
otherwise. When prettifying the logged message, all colors are check at renderer side when internally cached to improve the contrast, so the messages are legible.muteElectronInspector
(false
,true
or a level priority (0=error, 1=warn, 2=everything else); defaults tofalse
): allows muting the messages printed by Electron. Combining this option withignore
, user can mute messages with a very fine-grained control. This closes Filter out Electron junk logging #13 .prettify
("none"
,"context"
or"all"
; defaults to"context"
): the logged text can be colorized on both sides (main/renderer). If a transport does not support this feature, defaults tonone
. Possible values:none
: strips all colors.context
: colorizes only the context part (logger [side] >
).all
: colorizes the context and all the arguments passed to the logging method.separator
(any non-empty string; defaults to"›"
): the separator used to separate the context and the message.timestamp
(false
,"iso"
or"time"
; defaults tofalse
): messages can be prepended with a (ISO formatted or only time) timestamp on demand, which defaults tofalse
, and may have as possible valuesfalse
,'iso'
or'time'
. This feature is only available for main logger because user can manually activate this on renderer devTools underConsole settings > Show timestamps
.transports
((string|Object)[]
; defaults to["console"]
): the transports to set up for all loggers.New features
setDefaults()
from renderer process(es) too.ConsoleTransport
is always used as default (which is the unique currently available).error
(0),warn
(1),info
(2) (withlog
as alias),verbose
(3),debug
(4),silly
(5). So it's backwards compatible and provides new methods for more fine-grained control. User can set its own log levels through the new public methodsetLevels()
.timber
, and if noname
provided when creating a custom logger, thenelectron-timber
tries to find out the caller package and extract its name from itspackage.json
file. If not found, it will throw an error.timber [main]
,myCustomLogger [renderer 2]
. This eases a lot debugging multi-window apps and distinguishing one logger from another after fixing Add option to show main process output in the renderer #15 .collector
option) uncatched exceptions.TIMBER_LOGGERS
:TIMBER_HOOK_CONSOLE
,...).Internals/refactor
console
stuff moved to its ownAbstractConsoleTransport
class, extended byMainConsoleTransport
andRendererConsoleTransport
.constants.js
and imported where/when necessary.error
,warn
,info
,log
and so on) are created, optimized and binded dynamically now (these are inferred from the log levels, global defaults and other options).README.md
.Fixes
time
/timeEnd
were always being logged previously. Now they are logged based on the loggerlogLevel
(they default to be printed withinfo
/log
level).electron-utils.appReady.then()
was missing some browserWindows because of its asynchronous behaviour.Closes
Some screenshots of this PR in action
Collector as
"main"
with multiple browserWindows, hooking native console and prettifying"all"
:Collector as
"renderer"
with multiple browserWindows, native console hooked,"all"
prettified and devTools with dark theme: