Skip to content
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

Cannot read properties of undefined (reading 'level'” #445

Open
faqfaqfaqfaq opened this issue Nov 25, 2024 · 3 comments
Open

Cannot read properties of undefined (reading 'level'” #445

faqfaqfaqfaq opened this issue Nov 25, 2024 · 3 comments

Comments

@faqfaqfaqfaq
Copy link

function consoleTransportFactory(logger) {
return Object.assign(transport, {
format: DEFAULT_FORMAT,
level: 'silly',
transforms: [
addTemplateColors,
format,
formatStyles,
concatFirstStringElements,
maxDepth,
toJSON,
],
useStyles: process.env.FORCE_STYLES,

writeFn({ message }) {
  const consoleLogFn = consoleMethods[message.level] || consoleMethods.info;
  consoleLogFn(...message.data);
},

});其中的[message.level]报错TypeError; Cannot read properties of undefined (reading 'level'”
at Function.writeFn (D:\内网通缓存\陈大荣\国周率软件-保密检查工具(3.0.0)
(2024.11.15.10)-绿色版\保密检查客户端
resources\app,asar\node modules\electron-log\src\main\transportsiconsole.j...51)
at defaultlogger,processinternalErrorFn(D:\内网通缓存\陈大荣\圆周率软件-保密检育
I具(3.0.0)-(2024.11.15.10)-绿色版\保密检查客户端

@megahertz
Copy link
Owner

megahertz commented Nov 25, 2024

I need a code sample that reproduces the issue.

@leyriel
Copy link

leyriel commented Jan 13, 2025

Hi there,

I'm encountering an issue with electron-log when trying to set up logging for autoUpdater in my Electron app. The app crashes during the startup phase with the following error:


TypeError: Cannot set properties of undefined (setting 'level')
    at Module.<anonymous> (path_to_main_file:line_number:column_number)

Steps to Reproduce:

1.Import electron-log into the main process using import log from 'electron-log';.
2.Assign log to autoUpdater.logger and configure the logging levels:

autoUpdater.logger = log;
autoUpdater.logger.transports.file.level = 'info';
autoUpdater.logger.transports.console.level = 'info';

3.Run the app.
Expected Behavior: The logger should correctly log messages to the console and file without crashing.

Actual Behavior: The app crashes with the error TypeError: Cannot set properties of undefined (setting 'level').

Environment:


Electron Version: [your version, e.g., 28.1.0]
Electron Builder Version: [your version, e.g., 25.1.8]
Electron Log Version: [your version, e.g., 4.4.7]
OS: [your OS, e.g., Windows 11]

Troubleshooting Steps Tried:

Verified that electron-log is correctly installed in dependencies.
Tried using log.transports.file.level = 'info'; before assigning it to autoUpdater.logger.
Checked for potential conflicts with other dependencies.
Followed the official documentation for electron-log.
Question: Is there a known issue or specific configuration requirement when using electron-log with autoUpdater? Am I missing something in the setup, or could this be a bug?

Any guidance or suggestions would be greatly appreciated!

@megahertz
Copy link
Owner

@leyriel you need to import from 'electron-log/main' instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants