electron-log icon indicating copy to clipboard operation
electron-log copied to clipboard

Add logger name to the format

Open xmedeko opened this issue 3 years ago • 13 comments

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?

xmedeko avatar Apr 13 '21 14:04 xmedeko

Thank you, yes, it should be added to the list. Will do that later.

megahertz avatar Apr 13 '21 15:04 megahertz

@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 avatar Sep 29 '21 13:09 bilal68

@bilal68 Just set a format option of the used transport

megahertz avatar Sep 29 '21 14:09 megahertz

I tried log.transports.console.format = ''; but it didn't work. can you refer an example

bilal68 avatar Sep 29 '21 14:09 bilal68

@bilal68 Have you tried both in the main and in a renderer process?

megahertz avatar Sep 29 '21 16:09 megahertz

can you please give me an example.

bilal68 avatar Sep 29 '21 16:09 bilal68

@bilal68 Just make sure you execute your code in all processes

megahertz avatar Sep 29 '21 16:09 megahertz

currently i an using something like this.What I am missing. image

bilal68 avatar Sep 30 '21 05:09 bilal68

@bilal68 First of all, please describe more detailed what do you want to change. There are many places where logs are written to.

megahertz avatar Sep 30 '21 07:09 megahertz

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 avatar Sep 30 '21 10:09 bilal68

@bilal68 print where? console/dev tool console/file?

megahertz avatar Sep 30 '21 11:09 megahertz

console file

bilal68 avatar Sep 30 '21 12:09 bilal68

@bilal68 you mean application console? In that case you should make sure that the code is executed in the main process, not renderer

megahertz avatar Sep 30 '21 14:09 megahertz

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)

eric-burel avatar Oct 21 '22 14:10 eric-burel