Comments (11)
Fwiw, the stdlib's Logger
also logs the original exception message, regardless of the message passed to the .exception(...)
method.
from structlog.
Okay, it seems this is already (mostly) addressed by #22.
The stdlib's .exception()
also includes the original exception message; I can't quickly see whether structlog's emulation does that as well?
from structlog.
Please try and file a bug if it doesn’t. (respectively transform this ticket into that in that case to make use of it :)).
from structlog.
(I’m not 100% sure what you mean so I figure it’s faster if you just test it before I start asking clarification questions and test it then to tell you)
from structlog.
This Python file:
logging.basicConfig()
logger = logging.getLogger(__name__)
try:
raise ValueError("This is the exception message.")
except ValueError:
logger.exception("This is the log message.")
shows this output:
ERROR:__main__:This is the log message.
Traceback (most recent call last):
File "blah.py", line 8, in <module>
raise ValueError("This is the exception message.")
ValueError: This is the exception message.
As you can see, both the log message and the exception message show up in the log. A similar setup with structlog
loses the exception message.
from structlog.
The structlog
configuration is from the docs:
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
from structlog.
So, I’ve tested it with
import logging
import structlog
logging.basicConfig()
structlog.configure(
processors=[
structlog.stdlib.filter_by_level,
structlog.processors.StackInfoRenderer(),
structlog.processors.format_exc_info,
structlog.processors.JSONRenderer(),
],
context_class=dict,
logger_factory=structlog.stdlib.LoggerFactory(),
wrapper_class=structlog.stdlib.BoundLogger,
cache_logger_on_first_use=True,
)
logger = structlog.get_logger()
try:
raise ValueError("This is the exception message.")
except ValueError:
logger.exception("This is the log message.")
And the reformatted output I’m getting is:
{
"exception": "Traceback (most recent call last):\n File \"t2.py\", line 22, in <module>\n raise ValueError(\"This is the exception message.\")\nValueError: This is the exception message.",
"event": "This is the log message."
}
So the error message clearly is there (the stdlib output is completely within the formatted string), but what you’re saying is that you’d like the exception data in a more structured form?
Right now, format_exc_info really just formats the traceback: https://github.com/hynek/structlog/blob/master/structlog/processors.py#L169
It’s totally thinkable to pull data out of the exception I guess? I’m removing the milestone though because this is a nice but not too important feature (and you can implement it for yourself for now if you want to).
from structlog.
Okay maybe I was just being blind. The original message is part of the formatted traceback, right?
from structlog.
Yes, it should. Scroll to the right above to verify. :) The job of format_exc_info is to emulate the output you would have gotten on the console.
from structlog.
In that case I must've missed
it the first time in the huge json spaghetti on my screen. I'm sorry for the noise.
Hynek Schlawack [email protected] schreef op 10 januari 2015 09:40:00 CET:
Yes, it should. Scroll to the right above to verify. :) The job of
format_exc_info is to emulate the output you would have gotten on the
console.
Reply to this email directly or view it on GitHub:
https://github.com/hynek/structlog/issues/31#issuecomment-69448676
Sent from my Android device with K-9 Mail. Please excuse my brevity.
from structlog.
I think extracting the actual error message from a stack trace is not that useful anyway. The message will likely not be that useful without the additional info from the stack trace, so I guess the current output is fine.
Closing this issue.
from structlog.
Related Issues (20)
- add_logger_name not working with many logger factories HOT 2
- Redirecting logs to stderr suppresses colored output HOT 1
- Logging to both stdout and file with orjson via BytesLoggerFactory? HOT 3
- .debug() not working when LoggerFactory() is used HOT 2
- FilteringBoundLogger exception() method has different API HOT 2
- Colors missing from structlog when using ray HOT 2
- How can I intercept stdlib logging used in 3rd party library? HOT 1
- Add support for stdlib's stacklevel parameter
- Changing TimeStamper `key` to `"ts"` breaks ordering of logs for ConsoleRenderer HOT 3
- Traceback when using `stdlib.filter_by_level` with Python Standard Logging Library HOT 3
- structlog logger.exception doesn't accept positional arguments HOT 1
- How to disable logging? HOT 3
- How to configure CallsiteParameter so I can click on log lines in IDE and jump to the correct line in the file? HOT 3
- Please add documentation for how to configure logging to standard error HOT 1
- Allow renaming keys added by CallsiteParameterAdder
- question/feature request: Adjustable width in rich_traceback / Passing options to rich HOT 1
- Changes to behavior of `runtime_checkable()` in py 3.12 HOT 6
- WriteLogger log rotation HOT 2
- logs reader HOT 1
- Structlog does not work with tqdm HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from structlog.