Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Smurf-IV opened this issue Aug 16, 2023 · 4 comments
Open

Comments

@Smurf-IV
Copy link

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)

  • Errors only should go to the EventLog,
  • Anything that is not Debug / Verbose goes to Console
  • Everything goes to a file
    All via the default macros

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
Copy link
Author

I think it might be possible, by:

  • Moving the Severity calls into IAppender
  • In Logger.h
    • Iterate over Appenders to get the Max Severity
    • If set is called at this level, then call set on all appenders
    • in the operator call, also check the severity before calling it's write.

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
Copy link
Owner

It should be possible with the following approach: #181 (comment) Could you check if it works for your use case?

@Smurf-IV
Copy link
Author

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

@ChrisE2018
Copy link

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);
        }
    }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants