Comments (8)
Yes, you are right, this should be an actual error instead of an Option
.
Thanks for your PR, but I would rather see an implementation using a Result
instead because I will probably need to bump the version anyway (again) to finally fix #19.
from simplelog.rs.
Hey @Drakulix , Glad to read that you're open to a breaking change to improve things 🙂
I'll submit a PR in the upcoming days to change the retun of TermLogger::new
from Option
to Result
and have nice Err
messages if that's OK for you. Could you tell me if TermLogger::init
is concerned too and if I should take a look at it at the same time?
from simplelog.rs.
I'll submit a PR in the upcoming days to change the retun of
TermLogger::new
fromOption
toResult
and have niceErr
messages if that's OK for you. Could you tell me ifTermLogger::init
is concerned too and if I should take a look at it at the same time?
Thanks, that sounds absolutely OK. 😄
TermLogger::init
should also be updated. It already returns an Error because setting the logger globally might fail, e.g. if another one is already set, but the Term-Variant should be updated to contain the Error returned by TermLogger::new
.
from simplelog.rs.
i just discovered this too, in a systemd unit TERM
is undefined so the logger fails to start.
it'd be neat to document this (or alternatively default to xterm
or something rather than failing out).
from simplelog.rs.
i just discovered this too, in a systemd unit
TERM
is undefined so the logger fails to start.
it'd be neat to document this (or alternatively default toxterm
or something rather than failing out).
Allowing TermLogger
to fail is absolutely reasonable and will not be changed. You are supposed to handle errors and silently "fixing" this by hacking together a non-existing TERM
variable is not the solution. systemd does not set TERM
deliberately and you should instead fall back to SimpleLogger
if TermLogger
fails, which will work in the circumstances.
from simplelog.rs.
I think the concern is more about the failure case not being documented. I see a few possible ways to deal with this
- Don't fail (but you have made it clear that there are failure cases)
- Document the failure cases
- Document the best practice of falling back to SimpleLogger in your readme/top level docs to handle these events.
Certainly the "surprise" failure in CI/docker/systemd would catch people out who want a logger to stdout, so advertising the best practice to handle this situation would be really helpful.
Thanks!
from simplelog.rs.
yeah that's p much it ^_^
Allowing TermLogger to fail is absolutely reasonable and will not be changed. You are supposed to handle errors
the dx here is that you setup a TermLogger
following the example in the README or api, then when you try and daemonise it either faults out with a non-useful error or silently fails and your logs disappear depending on whether you let _ =
or .unwrap()
.
silently "fixing" this by hacking together a non-existing TERM variable is not the solution.
you should instead fall back to SimpleLogger if TermLogger fails, which will work in the circumstances.
so, documenting this failure and how to mitigate it in the API docs / example, and improving the error would improve the situation, but as an alternative could TermLogger
fall back to SimpleLogger
if no term variable is set? that seems like a more predictable behaviour, and means that every user of TermLogger
doesn't have to handle the Error::NoTermSet
case.
from simplelog.rs.
Upon discovering, that term
does not provide an error, but just an Option
as well, I decided to keep it. term
does not give us further information and I do not want to create an error case based on reading it's source code.
Instead, I have decided to merge @Horgix original PR #41 and expand it with some further examples in 70b09e2.
from simplelog.rs.
Related Issues (20)
- How can append data in WriteLogger if file exist? HOT 2
- Add a helper function to initialize loggers with default config HOT 1
- ConfigBuilder::add_filter_allow example documentation HOT 3
- attempted to set a logger after the logging system was already initialized HOT 3
- Updating filters after initialization
- How to update file path of the `WriteLogger` after I call `CombinedLogger::init`? HOT 2
- question: full time stamp? HOT 1
- Add module level
- logs with rfc3339 time have no consistent length HOT 2
- README should call out feature differences vs. env_logger
- TestLogger not working
- crash on openbsd with set_time_offset_to_local() HOT 1
- how do I config the logger to log only the actual message? HOT 1
- Please make a v0.12.2 release HOT 5
- `enabled()` methods don't respect the target filter
- Question: is it safe to use `TermLogger` across threads without additional synchronisation? HOT 2
- "termcolor" version is too restrictive HOT 3
- Implement key/value feature of the log crate (now stable)
- Error with rust-nightly: type annotations needed for Box<_> HOT 2
- Multiple, intependen logger HOT 1
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 simplelog.rs.