rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.77k stars 1.22k forks source link

abilities: an option to disable logging #1241

Closed voidpointer0x00 closed 4 months ago

voidpointer0x00 commented 1 year ago

Is your feature request related to a problem? Please describe. My app has it's own logging system and handles Telegram updates in it's own way. Currently I'm migrating commands to the abilities system. But the thing is, I don't want it to log any unnecessary stuff.

@Override public void onUpdateReceived(final Update update) {
    super.onUpdateReceived(update); /* call the abilities code */
    /* other logic ... */
}

The logging code that I'm reffering to:

https://github.com/rubenlagus/TelegramBots/blob/7029a35cd01dae7f86428ad73e29a4a1d4b725e2/telegrambots-abilities/src/main/java/org/telegram/abilitybots/api/bot/BaseAbilityBot.java#L236-L263

Describe the solution you'd like Either one of these would solve the problem; we can just discuss which one suits the library the best and I'll me glad to make a PR implementing the thing.

Disputable:

Describe alternatives you've considered Theoretically, in the overriden #onUpdateReceived() instead of calling super.onUpdateReceived(...) I could just paste the Stream.of(... code, but most of the methods are package-protected.

Stream.of(update)
        .filter(this::checkGlobalFlags) /* the only one with protected access level */
        /* ... */
        .forEach(this::postConsumption);

A temporary fix is log filtering, but in that case my inner optimization demon will keep me awake at nights telling me that somewhere code's doing unnecessary work :rofl: With logback it can be done changing log level for the ...BaseAbilityBot logger:

<logger name="org.telegram.abilitybots.api.bot.BaseAbilityBot" level="WARN"/>
Chase22 commented 1 year ago

I think the misunderstanding here is that setting a log level is not "Filtering". Slf4j actively checks what level the logger is set to and will not log a message if the level is disabled:

See: Slf4j AbstractLogger

public void info(String format, Object arg) {
    if (isInfoEnabled()) {
        handle_1ArgsCall(Level.INFO, null, format, arg);
    }
}

Adding an additional toggle is a possibility, but there is already an option to disable the logging without having to add extra complexity.  @addo47 would it be an option to downgrade the log to debug?

voidpointer0x00 commented 1 year ago

I think the misunderstanding here is that setting a log level is not "Filtering".

Yes, I guess I didn't put it the right way :smile:

rubenlagus commented 7 months ago

No concerns with downgrade that log line to debug level, feel free to raise a PR against dv if not already done