question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to handle uncaught exceptions

See original GitHub issue

I want to log the uncaught exceptions with Winston and exit process. I’ve configured logger like this

var winston = require('winston');
var logger = new (winston.Logger)({
    transports: [
      new winston.transports.File({ filename: './all-logs.log', timestamp: true, maxsize: 1000000 })
    ],
    exceptionHandlers: [
      new winston.transports.File({ filename: './exceptions.log', timestamp: true, maxsize: 1000000 })
    ],  
    exitOnError: true,
});

Then try throw one error, but no exceptions.logs file was created throw new Exception(“Error here …”);

Did I have the right configuration?

Issue Analytics

  • State:closed
  • Created 12 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
indexzerocommented, Feb 12, 2015

@gowthaman-i2i this is the winston based example:

var winston = require('winston');
var logger = new (winston.Logger)({
    transports: [
      new winston.transports.File({ filename: './all-logs.log', timestamp: true, maxsize: 1000000 })
    ],
    exceptionHandlers: [
      new winston.transports.File({ filename: './exceptions.log', timestamp: true, maxsize: 1000000 })
    ],  
    exitOnError: false, // <--- set this to false
});

but @3rd-Eden is correct this can be handled in multiple places 👍

0reactions
ariv803commented, Mar 25, 2022

FileTransportOptions extends Transport.TransportStreamOptions and TransportStreamOptions has:

format?: logform.Format;
    level?: string;
    silent?: boolean;
    handleExceptions?: boolean;
    handleRejections?: boolean;

FileTransportOptions are:

    filename?: string;
    dirname?: string;
    options?: object;
    maxsize?: number;
    stream?: NodeJS.WritableStream;
    rotationFormat?: Function;
    zippedArchive?: boolean;
    maxFiles?: number;
    eol?: string;
    tailable?: boolean;
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Handle Exceptions in JavaScript - Rollbar
Catching all exceptions. At its simplest, catching exceptions in JavaScript requires simply wrapping an expression in a try-catch statement.
Read more >
android - Need to handle uncaught exception and send log file
Handle uncaughtException in your Application subclass. · After catching an exception, start a new activity to ask the user to send a log....
Read more >
20.4 — Uncaught exceptions and catch-all handlers - Learn C++
If your program uses exceptions, consider using a catch-all handler in main, to help ensure orderly behavior when an unhandled exception occurs.
Read more >
How uncaught exceptions are handled in Java - Javamex
Java actually handles uncaught exceptions according to the thread in which they occur. When an uncaught exception occurs in a particular thread, Java...
Read more >
Uncaught Exceptions in Node.js - George Ornbo
How to deal with uncaught exceptions · You application shouldn't have uncaught exceptions. · You should let your application crash, find uncaught ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found