You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using listen_log to ship all my log messages to Loki. Since I have practically infinite storage and easy log filtering, I want to always enable debug logging.
However, I can't get listen_log to receive any DEBUG messages. Here's my ExternalLogging app:
I have log_level: NOTSET in the config of all my apps, and I'm also running self.set_log_level("NOTSET") in all my app initialize functions, just to be 100% sure. I've also tried "DEBUG" in place of "NOTSET" in all these places.
The print statement in my on_log callback shows up in the "Log" tab of the AppDaemon plugin, and it shows that the callback is only receiving INFO, WARNING, ERROR and CRITICAL log messages. It's not receiving any DEBUG or NOTSET log messages.
Not sure what's going on with the logging callbacks, but generally functions like this (sending the logs somewhere) happen in Python with logging handlers.
This is an example of what I use to send the logs from a single app to Loki.
importasyncioimportlogging.configfromloggingimportHandler, LogRecordimportaiohttpfromappdaemon.adapiimportADAPIclassLokiHandler(Handler):
loop: asyncio.BaseEventLooploki_url: strlevel: int|str=0def__init__(self, loop: asyncio.BaseEventLoop, loki_url: str, level: int|str=0) ->None:
self.loop: asyncio.BaseEventLoop=loopself.loki_url: str=loki_urlsuper().__init__(level)
defemit(self, record: LogRecord) ->None:
self.loop.create_task(self.send_to_loki(record))
asyncdefsend_to_loki(self, record: LogRecord):
message=self.format(record)
ns=round(record.created*1_000_000_000)
# https://grafana.com/docs/loki/latest/reference/loki-http-api/#ingest-logspayload= {
'streams': [
{
'stream': {'appname': record.appname, 'level': record.levelname},
'values': [[str(ns), message]],
}
]
}
asyncwithaiohttp.ClientSession() assession:
awaitsession.post(self.loki_url, json=payload, timeout=3)
classLokiLogger(ADAPI):
asyncdefinitialize(self):
log_cfg= {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'loki': {
'()': 'loki.LokiHandler',
'loop': self.AD.loop,
'loki_url': self.args['loki_url'],
}
},
'loggers': {self.logger.name: {'handlers': ['loki'], 'level': 'DEBUG'}},
}
# Use dictConfig in order to replace the logging configuration every time the app is reloaded# https://docs.python.org/3/library/logging.config.html#configuration-dictionary-schemalogging.config.dictConfig(log_cfg)
self.log('Logging from LokiLogger')
What happened?
I'm using
listen_log
to ship all my log messages to Loki. Since I have practically infinite storage and easy log filtering, I want to always enable debug logging.However, I can't get
listen_log
to receive any DEBUG messages. Here's myExternalLogging
app:I have
log_level: NOTSET
in the config of all my apps, and I'm also runningself.set_log_level("NOTSET")
in all my app initialize functions, just to be 100% sure. I've also tried "DEBUG" in place of "NOTSET" in all these places.The
print
statement in myon_log
callback shows up in the "Log" tab of the AppDaemon plugin, and it shows that the callback is only receiving INFO, WARNING, ERROR and CRITICAL log messages. It's not receiving any DEBUG or NOTSET log messages.Is this a bug or am I missing something?
Version
4.4.2
Installation type
Home Assistant add-on
Relevant log output
Relevant code in the app or config file that caused the issue
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: