GithubHelp home page GithubHelp logo

Comments (11)

pmwmedia avatar pmwmedia commented on May 25, 2024

For tinylog 1.1 are planned includes and excludes patterns for logging writers (-> http://www.tinylog.org/roadmap). It will be possible to define packages and class names. Will it help you?

from tinylog.

degill avatar degill commented on May 25, 2024

I think it could help me, depending on the implementation. If the filtering is defined at package/class level than it would not help me. I have classes emitting different types of log messages (status, result, errors, etc.) so I want to redirect those messages into different files depending on the logmessage itself, not by which class it was emitted.

Right now I worked around it and implemented my own writers, which are wrappers (because your classes are final) and which delegate the actual writing to a FileWriter only if a pattern is matched, with each writer having its own pattern.

public abstract static class FileWriterWrapper implements Writer {

    public final FileWriter WRITER;

    public FileWriterWrapper(String filename) {
        WRITER = new FileWriter(filename, false);
    }

    @Override
    public Set<LogEntryValue> getRequiredLogEntryValues() {
        return WRITER.getRequiredLogEntryValues();
    }

    @Override
    public void init(Configuration configuration) throws Exception {
        WRITER.init(configuration);
    }

    @Override
    public void flush() throws Exception {
        WRITER.flush();
    }

    @Override
    public void close() throws Exception {
        WRITER.close();
    }
}

and then subclassing that writer to have my filtering:

private static class FileWriterSystem extends FileWriterWrapper {

    public FileWriterSystem(String filename) {
        super(filename);
    }

    @Override
    public void write(LogEntry logEntry) throws Exception {
        if (condition-matched) {
                super.WRITER.write(logEntry);
        }
    }
}

Of course its a bit inconvenient, but it was my first idea and its fine for now.
The upside is, I can still define all the things as before for each custom writer (Labeler, Polciy, Logging-Format)

from tinylog.

pmwmedia avatar pmwmedia commented on May 25, 2024

You parse the log message for your condition? I think about a small filter framework for writers. So you have just to implement a filter interface.

public interface Filter {

    boolean accept(LogEntry logEntry);

}

Would it helpful for you? I could imagine such a feature for tinylog 2.0. But it depends a bit on the demand.

from tinylog.

degill avatar degill commented on May 25, 2024

Yes, that was actually my initial idea. But I can imagine that would be a performance loss.

from tinylog.

pmwmedia avatar pmwmedia commented on May 25, 2024

I'm open for better ideas :-)

from tinylog.

degill avatar degill commented on May 25, 2024

I did not want to say that it was a bad idea :) I just think one should then be careful when using such a filter..Its depending on the usecase, I guess

from tinylog.

degill avatar degill commented on May 25, 2024

I prefered it that way because then the log-emitter (the code executing Logger.*) does not have to think about any filtering.

Another solution could be to explicitly define some kind of a tag/label to a logmessage.

new FileWriter(..., "system", "user:degill")

to define which FileWriter is responsible for which file and which tags.
Downside: Now the log-caller needs to decide where the log message should go

Logger.info(message, "user:degill")

from tinylog.

pmwmedia avatar pmwmedia commented on May 25, 2024

I like the idea of tags:

Logger.tag("SYSTEM").info("Hello World");

from tinylog.

 avatar commented on May 25, 2024

Hi together, I'd like to add that I'm also just waiting for this particular feature to use tinylog in production. Also, I think that the idea of using tags is a nice solution.

from tinylog.

pmwmedia avatar pmwmedia commented on May 25, 2024

Implemented in branch v2.0

from tinylog.

github-actions avatar github-actions commented on May 25, 2024

This closed issue has been locked automatically. However, please feel free to file a new issue.

from tinylog.

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.