electron-log
electron-log copied to clipboard
Add logger name to the format
Add logId
(usually called logger name or category) to the format. E.g. as {logger}
(same as in log4j PatternLayout).
Note: https://github.com/megahertz/electron-log/blob/master/docs/format.md does not mention {scope}
and maybe anything else is missing?
Thank you, yes, it should be added to the list. Will do that later.
@megahertz can we disable these time-stamps. "[2021-09-29 18:33:52.290] [info] XXXXXXXXXX". I want the time which prints with every logged line should be disables. & I can't fine any options for this in docs..kindly have a look.
king regards
@bilal68 Just set a format option of the used transport
I tried log.transports.console.format = ''; but it didn't work. can you refer an example
@bilal68 Have you tried both in the main and in a renderer process?
can you please give me an example.
@bilal68 Just make sure you execute your code in all processes
currently i an using something like this.What I am missing.
@bilal68 First of all, please describe more detailed what do you want to change. There are many places where logs are written to.
You can see in the above image there are multiple logged lines....what they will print is something like this:
[2021-09-30 15:13:27.087] [info] User: Bilal Amin [2021-09-30 15:13:27.087] [info] Date and Time: Thu Sep 30 2021 15:13:27 GMT+0500 (Pakistan Standard Time) [2021-09-30 15:13:27.087] [info] Time zone Offset: [2021-09-30 15:13:27.087] [info] Total Events: 9 [2021-09-30 15:13:27.087] [info] Start Date: [2021-09-30 15:13:27.087] [info] End Date: [2021-09-30 15:13:27.087] [info] Filtered Events: 9 [2021-09-30 15:13:27.087] [info] Output Path: C:\Users\TK-LPT-0327\Desktop\600\output [2021-09-30 15:13:27.087] [info] Split type: [2021-09-30 15:13:27.087] [info] Files generated: 1
what I want is something like this: User: Bilal Amin Date and Time: Thu Sep 30 2021 15:14:02 GMT+0500 (Pakistan Standard Time) Time zone Offset: +02:00 Total Events: 9 Start Date: 2021-12-01 End Date: 2021-09-30 Filtered Events: 0 Output Path: C:\Users\TK-LPT-0327\Desktop\600\output Split type: day Files generated:
@bilal68 print where? console/dev tool console/file?
console file
@bilal68 you mean application console? In that case you should make sure that the code is executed in the main process, not renderer
For Googlers, "{scope}" is undocumented but works and will print (scope)
Notice the additional space
Here is my debug formatter:
const fileName = `${log.transports.file.fileName}.${process.env.NODE_ENV}`;
const isMain = fileName.startsWith("main")
const prefix = isMain ? "⚛️ [main]" : "📺 [renderer]"
const defaultConsoleFormat = ":: {level} ::{scope} > {text}"
log.transports.console.format = `${prefix} ${defaultConsoleFormat}`
It works pretty well in console (for file logs or production logs, you may want to add timestamps since you read them asynchronously)