Giter Club home page Giter Club logo

Comments (8)

Drakulix avatar Drakulix commented on July 26, 2024

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.

Horgix avatar Horgix commented on July 26, 2024

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.

Drakulix avatar Drakulix commented on July 26, 2024

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?

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.

ryankurte avatar ryankurte commented on July 26, 2024

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.

Drakulix avatar Drakulix commented on July 26, 2024

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).

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.

Firstyear avatar Firstyear commented on July 26, 2024

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.

ryankurte avatar ryankurte commented on July 26, 2024

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.

Drakulix avatar Drakulix commented on July 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.