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

Cannot use log level "info" to send logs to loki #20

Open
Koushikgudipati opened this issue Aug 16, 2021 · 3 comments
Open

Cannot use log level "info" to send logs to loki #20

Koushikgudipati opened this issue Aug 16, 2021 · 3 comments

Comments

@Koushikgudipati
Copy link

I am trying to push logs to loki.

When pushing logs with log level info , I do not see any logs going to loki .also it does not throw any error as well.
When i use log level as error/warn i can logs pushed to loki.

Do i need to make any change to send info log level logs to info loki?

logger.info(
    "test loki forward",
    extra={"tags": {"app": "app1"}},
)

Also i have used

from logging_loki import LokiHandler, emitter
emitter.LokiEmitter.level_tag = "level"
@gatlee21
Copy link

gatlee21 commented Sep 12, 2021

@Koushikgudipati did you ever resolve this? I'm running into the same issue as well.

Update: after some digging, I discovered that when you call logger.info(...) or say logger.error(...) the logger object itself servers as a filter because it has a level associated with it.

I discovered that the logger object's default level is set to WARNING. You can check this by printing out the current level with this statement:
print(logger.getEffectiveLevel())
You will see it output the value 30 which maps to WARNING (see enum levels below). What this means is that any log message with the level of anything higher than or equal to a warning (30) gets the go-ahead to move on.

CRITICAL = 50
FATAL = CRITICAL
ERROR = 40
WARNING = 30 # right now anything lower than this won't pass through.
WARN = WARNING
INFO = 20
DEBUG = 10
NOTSET = 0

So what we have to do is set the level (change the filter) to which we will allow messages to carry through. We can do this by adding this line after calling logging.getLogger(...):

logger.setLevel(logging.DEBUG)

Now check the logger current level print(logger.getEffectiveLevel()) and you will see the value 10. This means that any log with a level of 10 or higher will pass through. You should now see debug and info logs going to Loki.

@Scavallarin
Copy link

gatlee21 This is awsome! Thanks so much for sharing, can i ask you where have you been digging to find this out? So i can do the same!

@ngocdd
Copy link

ngocdd commented May 5, 2024

2024 and anyone resolved this problem, I got the same issue on Python, this is a foolish bug :d

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

4 participants