SergiusTheBest / plog

Portable, simple and extensible C++ logging library
MIT License
2.21k stars 391 forks source link

[Feature Request] Single logger, but each appender has a different level #266

Open Smurf-IV opened 1 year ago

Smurf-IV commented 1 year ago

If I am using IoC or shared logger etc. Then the shared instance does not want to know what has been set up and what instances are being used (i.e. default always)

But (for example)

so, If the code calls PLOGD << then I would expect only the file to have an update If the code calls PLOGE, then all the appenders get an entry.

Is this possible, or have I missed something ?

Smurf-IV commented 1 year ago

I think it might be possible, by:

In the IAppender, have it's default severity set to "unknown" then when it is added to the logger, if it is set to unknown, then set it to the loggers value.

I think with some tweaking, the above should then be backward compatible with existing builds as well.

Thoughts ?

SergiusTheBest commented 1 year ago

It should be possible with the following approach: https://github.com/SergiusTheBest/plog/issues/181#issuecomment-786281845 Could you check if it works for your use case?

Smurf-IV commented 1 year ago

That explanation would work, can this be added more prominently, and perhaps in an example please ?

ChrisE2018 commented 1 year ago

I ran into the same problem and added m_severity as an instance variable inside ConsoleAppender. The new write method looks like this, and it solves my problem with a half dozen changed lines of code. ` virtual void write (const Record &record) PLOG_OVERRIDE { if (record.getSeverity() <= m_severity) { util::nstring str = Formatter::format(record); util::MutexLock lock(m_mutex);

            writestr(str);
        }
    }

`