GithubHelp home page GithubHelp logo

Comments (5)

emabee avatar emabee commented on May 28, 2024 1

In branch issue-47 I added a builder option 'Logger::duplicate_to_stdout()'.

With this, you could use

// Only log to stderr
        .log_target(LogTarget::StdErr)

// Log to stderr, and duplicate >= INFO to stdout
        .log_target(LogTarget::DevNull)  // only pretends to log
        .duplicate_to_stderr(Duplicate::All)
        .duplicate_to_stdout(Duplicate::Info)

// Log to file, duplicate ALL to stderr, nothing to stdout
        .log_target(LogTarget::File) 
        .duplicate_to_stderr(Duplicate::All)

// Log to file, duplicate to stderr, and duplicate >= INFO to stdout
        .log_target(LogTarget::File) 
        .duplicate_to_stderr(Duplicate::All)
        .duplicate_to_stdout(Duplicate::Info)

What do you think?

from flexi_logger.

pscott avatar pscott commented on May 28, 2024

To make sure we avoid the XY problem, I'm trying to build a logger that works like this:

let log_file: Option<PathBuf>; // path to directory
let stderr_isatty = atty::is(atty::Stream::Stderr); // whether stderr is attached to a terminal or not
match (log_file, isatty) {
  (None, true) => , // Only log to stderr
  (None, false) => , // Log to stderr, and duplicate >= INFO to stdout
  (Some(dir), true) => ,// Log to file, duplicate ALL to stderr, nothing to stdout
  (Some(dir), false) => , // Log to file, duplicate to stderr, and duplicate >= INFO to stdout
}

edit: just noticed that duplication does not occur if log_target is Stderr or Stdout ^^'

from flexi_logger.

pscott avatar pscott commented on May 28, 2024

Yup sounds good!
I would never have thought about using LogTarget::DevNull to "pretend" to log in order to be able to duplicate. It might be worth mentioning it in the docs somewhere (my two cents! :)).

Thank you so much for your help!

from flexi_logger.

emabee avatar emabee commented on May 28, 2024

Implemented with version 0.15.5.

from flexi_logger.

pscott avatar pscott commented on May 28, 2024

@emabee Getting back to this issue, I think I'm missing something like format_for_stdout() to be able to log with colors to stdout, while keeping LogTarget::Stderr and LogTarget::File without colors. Should I try submitting a PR for this one?

from flexi_logger.

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.