Log4j2: log stack trace without an exception

vektor

I am using Log4j2, some beta-10 version or so.

It's easy to log a stack trace when you have an exception:

} catch (Exception ex) {
  log.error("Doing stuff went wrong", ex);
}

Suppose though there is no Throwable object available - I just realized there is a problem and want to log an error:

 if (stuffIsWrong()) {
   log.error("Stuff went wrong");
 }

How can I tell Log4j2 to log a stack trace beginning in the current method?

Absurd-Mind

Just create a new Exception

if (stuffIsWrong()) {
    log.error("Stuff went wrong", new Exception("Stracktracegenerator"));
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL Exception with log4j2

From Dev

log not printing the full stack trace

From Dev

cxf null pointer exception without stack trace

From Dev

Log4j not printing complete stack trace

From Dev

Finding the Stack Trace Log from an EXE that crashes

From Dev

log4j2 how to disable "date:" lookup - log4j throws exception

From Dev

log4j2 how to disable "date:" lookup - log4j throws exception

From Dev

log4j CustomConfigurationFactory creating a new log file for every line of a stack trace?

From Dev

How to get stack trace string without raising exception in python?

From Dev

How to get stack trace string without raising exception in python?

From Dev

Use Sleuth trace-and span id in log4j2 patternlayout

From Dev

How to make log4j syslog appender write a stack trace in one line?

From Dev

Exception Stack Trace Missing Items

From Dev

Why is the exception stack trace not logged in?

From Dev

Log.e does not print the stack trace of UnknownHostException

From Dev

AbortProcessingException leaves stack trace in server log, how to disable this?

From Dev

Suppressing stack trace dump in Laravel log after App::abort(403)

From Dev

PHP-FPM breaks up stack trace log into separate events

From Dev

Suppressing stack trace dump in Laravel log after App::abort(403)

From Dev

Getting line numbers from a stack trace in a JVM crash log

From Dev

Error Details without Stack Trace

From Dev

Log4j2: How can I get Class Name and Line Number without using Throwable?

From Dev

Log onto Stack Exchange websites without a Mouse

From Dev

log4j2 exception:ERROR Could not unregister MBeans for org.apache.logging.log4j2:type=AsyncContext@694ae32f,component=AsyncLoggerRingBuffer

From Dev

laptop crashes without leaving any trace - log is corrupted

From Dev

How to enable log-back log stack trace og uncaught exceptions

From Dev

MVC4/IIS7 Error 500 diagnostics. No stack trace, no event log

From Java

How to print the stack trace of an exception object in Python?

From Dev

Exception that emails stack trace when raised

Related Related

  1. 1

    SQL Exception with log4j2

  2. 2

    log not printing the full stack trace

  3. 3

    cxf null pointer exception without stack trace

  4. 4

    Log4j not printing complete stack trace

  5. 5

    Finding the Stack Trace Log from an EXE that crashes

  6. 6

    log4j2 how to disable "date:" lookup - log4j throws exception

  7. 7

    log4j2 how to disable "date:" lookup - log4j throws exception

  8. 8

    log4j CustomConfigurationFactory creating a new log file for every line of a stack trace?

  9. 9

    How to get stack trace string without raising exception in python?

  10. 10

    How to get stack trace string without raising exception in python?

  11. 11

    Use Sleuth trace-and span id in log4j2 patternlayout

  12. 12

    How to make log4j syslog appender write a stack trace in one line?

  13. 13

    Exception Stack Trace Missing Items

  14. 14

    Why is the exception stack trace not logged in?

  15. 15

    Log.e does not print the stack trace of UnknownHostException

  16. 16

    AbortProcessingException leaves stack trace in server log, how to disable this?

  17. 17

    Suppressing stack trace dump in Laravel log after App::abort(403)

  18. 18

    PHP-FPM breaks up stack trace log into separate events

  19. 19

    Suppressing stack trace dump in Laravel log after App::abort(403)

  20. 20

    Getting line numbers from a stack trace in a JVM crash log

  21. 21

    Error Details without Stack Trace

  22. 22

    Log4j2: How can I get Class Name and Line Number without using Throwable?

  23. 23

    Log onto Stack Exchange websites without a Mouse

  24. 24

    log4j2 exception:ERROR Could not unregister MBeans for org.apache.logging.log4j2:type=AsyncContext@694ae32f,component=AsyncLoggerRingBuffer

  25. 25

    laptop crashes without leaving any trace - log is corrupted

  26. 26

    How to enable log-back log stack trace og uncaught exceptions

  27. 27

    MVC4/IIS7 Error 500 diagnostics. No stack trace, no event log

  28. 28

    How to print the stack trace of an exception object in Python?

  29. 29

    Exception that emails stack trace when raised

HotTag

Archive