megahertz / electron-log

Simple logging module Electron/Node.js/NW.js application. No dependencies. No complicated configuration.
MIT License
1.32k stars 128 forks source link

Issues with transport format functions and lack of clear documentation #431

Closed melihcoban closed 3 months ago

melihcoban commented 3 months ago

Hi,

I use electron-log 5.1.7. I inspected format page on Github docs but can't wrap my head around the implementation of it.

This example gives ts(2322) error on my end Type '({ message }: { message: any; }) => string' is not assignable to type 'Format'. Type '({ message }: { message: any; }) => string' is not assignable to type '({ message: LogMessage }: { message: any; }) => any[]'. Type 'string' is not assignable to type 'any[]'.ts(2322)

log.transports.console.format = ({ message }) => {
  return util.format(...message.data);
};

If I ignore with // @ts-ignore I get exception from electron-log itself. Unhandled electron-log error TypeError: data.reduce is not a function

Is there any explicit documentation on how to format the log message, for an example change {text} formatting?

megahertz commented 3 months ago

You're right, that's outdated. The function should return an array. I will update it this week.