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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

log.error() will throw following exception #26

Open
jordy-leung opened this issue Jan 25, 2018 · 20 comments
Open

log.error() will throw following exception #26

jordy-leung opened this issue Jan 25, 2018 · 20 comments

Comments

@jordy-leung
Copy link

Hi,

I just start to use simple-node-logger. When I use "log.error()", I will get this exception. Do you know what I have done incorrectly? It runs ok with log.debug or log.info, etc 馃槃

Would you point me right direction? Thanks!

=============================================
events.js:188
throw err;
^

Error: Unhandled "error" event. ([object Object])
at process.emit (events.js:186:19)
at D:\DEV\nodejs_projects\SystemMonitors\node_modules\simple-node-logger\lib\Logger.js:46:25
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)

@darrylwest
Copy link
Owner

Hi Jordy,

This is a new one to me. Can you tell me what node version you are running and supply some sample code? Also, try running the examples to see if they run ok.

thanks, darryl

@clive-school24
Copy link

Im getting the same error . My node version is 8.9.4

@darrylwest
Copy link
Owner

I'm not able to reproduce so can you send me a snippet of code that breaks?

@zadam
Copy link

zadam commented Apr 2, 2018

Same for me on node 8.11.1:

const logger = require('simple-node-logger').createRollingFileLogger({
    errorEventName: 'error',
    logDirectory: 'app/logs',
    fileNamePattern: 'app-<DATE>.log',
    dateFormat:'YYYY-MM-DD'
});

logger.error("This throws exception");

@bioleyl
Copy link

bioleyl commented Apr 4, 2018

This is a problem on Windows.

To fix it, replace the line 45 of Logger.js by this one:

if (level === 'error' && typeof(errorEventName) === String) {

I created a PR #31

@vinczebalazs
Copy link

@bioleyl Thanks for the fix! Its a problem on macOS as well.

@Wayn0
Copy link

Wayn0 commented Sep 5, 2018

FYI

I am having the problem on Ubuntu 18.04 / Node v8.10.0

Thanks for the fix

@bioleyl
Copy link

bioleyl commented Sep 9, 2018

There is not much activity on the sources.
Anyway I needed syslog function and auto remove (old) logfiles. For now if you remove old log when the app is running, it will crash. If you are interested to test, I made a really simple package to manage the log files. Give it a try and send me back if something is missing for you.

https://www.npmjs.com/package/sw-node-logger

@jpgri
Copy link

jpgri commented Oct 18, 2018

This solves the problem but it no make sense because String is not a possible output for typeof().

Putting

if (level === 'error' && typeof(errorEventName) === String) {

is exactly the same as putting:

if (false) {

@Mark-81
Copy link

Mark-81 commented Jan 15, 2019

I experience this behavior even with the latest version (18.12.21) that should have the commit that fixed the issue. Is it correct?

@darrylwest
Copy link
Owner

hi Mark, are you on Windows? I haven't been able to reproduce this error on mac or linux but I don't have a windows env to test. I guess I should create a windows docker image to see if I can reproduce.

@Mark-81
Copy link

Mark-81 commented Jan 16, 2019

Yes, Windows 7 64-bit. log.fatal() and the other methods work fine.

@pow4all
Copy link

pow4all commented Apr 4, 2019

I am on Ubuntu 18.10 with Node 8.11.4 and log.error() throws also this exception.

Edit:
simple-node-logger version is 18.12.22

The exact error message is:

events.js:188
      throw err;
      ^

Error: Unhandled "error" event. ([object Object])
    at process.emit (events.js:186:19)
    at /home/<xxx>/node_modules/simple-node-logger/lib/Logger.js:46:25
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)

@benivalotker
Copy link

because this line: "errorEventName:'error' " - throw error in node.

remove this line from your "simple-node-looger" config object and the error will not show anymore.

@kyletuite
Copy link

@benivalotker I know this is almost a year later, but this is the fix that worked for me. Thank you! I was having this issue using log.error() after switching from createSimpleFileLogger() to createRollingFileLogger().

@thanhtruong1992
Copy link

thanhtruong1992 commented Jun 18, 2020

Fixed it!

const logger = require('simple-node-logger').createRollingFileLogger({
    logDirectory: 'path_name/logs',
    fileNamePattern: 'app-<DATE>.log',
    dateFormat:'YYYY-MM-DD'
});

logger.log("error", "This throws exception");

@awps
Copy link

awps commented Jun 7, 2021

The problem is still not fixed as I see:

events.js:305
    throw err; // Unhandled 'error' event
    ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. ({
  ts: 1623069318792,
  pid: 27492,
  level: 'error',
  msg: [ 'My message' ]
})
    at process.emit (events.js:303:17)
    at process.EventEmitter.emit (domain.js:483:12)
    at /home/andrew/project/node-app/node_modules/simple-node-logger/lib/Logger.js:46:25
    at processTicksAndRejections (internal/process/task_queues.js:79:11) {
  code: 'ERR_UNHANDLED_ERROR',
  context: {
    ts: 1623069318792,
    pid: 27492,
    level: 'error',
    msg: [ 'My message' ]
  }
}

It disappears if I remove this line from options errorEventName: 'error',, but this looks like it's a bug.

@saru2020
Copy link

After lots of struggle, finally, I simply followed the examples and got it working.

const opts = {
domain:'Domain-A',
logDirectory: __dirname + '../../../logfiles',
fileNamePattern: 'hourly-test-.log',
dateFormat:'YYYY.MM.DD-HH'
};

const log = require('simple-node-logger').createRollingFileLogger( opts );

@jan-kacina
Copy link

The same error here:

  • Ubuntu 20.04.4
  • Node 16.14.0
  • Simple Node Logger 21.8.12

What's the meaning of the code guarded by conditions? Based on previous comments and my case It looks like lines 45-47 could be removed completely...

@pablo-penovi
Copy link

pablo-penovi commented Apr 23, 2022

Running into the same bug, couldn't figure out for the life of me where the exception was coming from, until I replaced ".error()" with ".info()" and voila, the exception disappeared. The exception I get is identical to the one @awps posted. What's more baffling is that there are other sections of the program where .error() works just fine.

Node: v16.9.1
OS: Ubuntu 22.04.
Simple Node Logger: 21.8.12

Since this program has a lot of async functions in it, I'm thinking maybe the problem stems from something related to async? I don't know really. I haven't been able to produce a minimal example of the bug nor can I show you the real source code since it's proprietary.

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