Stack trace error across multiple lines - log4net

I am using log4net to log errors in my C# application. I am logging the error to the csv file. I am also logging stack trace error to this log. But the issue is that the stack trace error is very long and is like 7 to 8 lines of error. So in the CSV file the output is coming out to be messy.
Does anyone have a suggestion as to how can i log stack trace error better to either csv or excel so that the whole stacke trace error message comes in one cel rather than being split into different lines?

Try using double quotes for the stack trace and any other similar strings.

Related

Show only my lines of code in error stack trace in NodeJS?

Is there a way to filter out the lines of code from error stack trace that I can't control or debug? I mean, my nodeJS project depends on many third party dependencies and I don't pretend to debug them. It just ads noise to the stack trace.
For example, here I just want to show lines 1 and 7, because the file prepareServer.js is the one I created, all the others are not mine.
Error
at buildAdministrationsObject (/home/joao/dev/geoptapi/prepareServer.js:350:11)
at /home/joao/dev/geoptapi/node_modules/async/dist/async.js:3638:28
at replenish (/home/joao/dev/geoptapi/node_modules/async/dist/async.js:443:21)
at iterateeCallback (/home/joao/dev/geoptapi/node_modules/async/dist/async.js:427:21)
at /home/joao/dev/geoptapi/node_modules/async/dist/async.js:324:20
at /home/joao/dev/geoptapi/node_modules/async/dist/async.js:3643:17
at /home/joao/dev/geoptapi/prepareServer.js:158:7
at wrapper (/home/joao/dev/geoptapi/node_modules/async/dist/async.js:271:20)
at iterateeCallback (/home/joao/dev/geoptapi/node_modules/async/dist/async.js:424:28)
at /home/joao/dev/geoptapi/node_modules/async/dist/async.js:324:20
Basically I just want to show in the stack files within my project and exclude files in node_modules/
Came up with this solution that strips out any line with /node_modules/ or \node_modules\
const stripedStack = (new Error().stack).replace(/^.*[\\/]node_modules[\\/].*$/gm, '').replace(/\n+/g, '\n')
console.error(stripedStack)
Now as I wanted :)
Error
at readShapefile (/home/joao/dev/geoptapi/prepareServer.js:106:16)
at /home/joao/dev/geoptapi/prepareServer.js:100:7

Nodejs permanent stack tracing to file

console.trace("Here I am!") - prints stack trace in current position of code. Is it possible to start writing stack trace from the beginning of script (or certain position) till the end of script to external log file like (/tmp/myTraceFile_${process.pid})?

Stack Trace is missing for uncaught python exceptions

I'm using Python 3.7.3 and runtime exceptions are suddenly generating the following type of error instead of the usual, handy stack trace.
(<class 'NameError'>, NameError("name 'window' is not defined"), <traceback object at 0x24857260>)
If I can't find the error based on the object name, I'm forced to add a bunch of print statements to isolate it. This is sub-optimum. I initially contacted PyCharm support regarding this but it's related to the Python instance and not the IDE so they were no help other than to tell me to "Google it". Most of what I've found on line tells me how to catch explicit exceptions via a try-catch block. But that would force me to add a bunch of try-catch blocks everywhere which were never required before when runtime errors simply spit out a stack trace complete with module and line numbers. I suspect there is some way of resolving the module/line based on the hex traceback address? But I just want my trusty stack trace back! Thanks!
Simply surrounding the code of the main module as follows fixed the first problem.
try:
app = QApplication(sys.argv)
app.setFont(QFont('SansSerif', 12))
window = MyWindow()
...
except Exception as e:
print(traceback.format_exc())
I now get stack traces on runtime errors.
Thanks,
Jeff

How to truncate org.jasig.cas.authentication.handler.BadCredentialsAuthenticationException Stack trace in log file?

I'm using CAS for single signon solution, My log(log4j version 1.2.15) file completely fills with the Exception(org.jasig.cas.authentication.handler.BadCredentialsAuthenticationException)
Stack trace when User enters invalid login credentials.
Is there a solution to trim the Stack trace in CAS or Java?
I can't use log4j EnhancePatternLayout to achieve this as it requires log4j version 1.2.16
Any suggestions around this problem would be appreciated.
Thanks
I haven't used CAS. However, the way that I've gotten around similar problems in the past is by suppressing log messages from the offending class. For example, if you're using a log4j.properties file, insert this line:
log4j.logger.com.jasig.cas.WhateverClassLogsTheException=OFF
Note that you will need to suppress messages from the class that throws the exception, not the exception class itself. Also, you can also use FATAL or other values to ensure that only log messages that are at or above the given level are logged. See the Log4J docs for more information.
Note that this will suppress all messages from that class, not just the particular log message that produces that exception.
The problem is CAS is passing Exception object to Log4j,so I did comment that line in my overlayed class. BindLdapAuthenticationHandler.java

log4j truncates the stacktrace

I am trying to track down a problem with GWT. I get an error which I want to track down to the source but log4j truncates the stacktrace by indicating something like "... 26 more" hence I cannot determine the exact location for the problem. I tried finding out if there is anyway to prevent that truncation but have been unable to find any option that will accomplish that. Is this truncation a configurable feature?
I am running Tomcat 6.0.31, Spring 3.0 (for backend), GWT 2.1.0.
Thanks
It isn't log4j truncating the stack trace, it's standard Java. And it's actually only making the trace more readable because those lines that were omitted were already output by the 'enclosing' exception. See Throwable javadoc.

Resources