Skip to content

Commit 69511dc

Browse files
committed
Add logging level module
1 parent 0d1aab8 commit 69511dc

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

lnxlink/modules/logging_level.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""Information and control of logging level"""
2+
import logging
3+
4+
logger = logging.getLogger("lnxlink")
5+
6+
7+
class Addon:
8+
"""Addon module"""
9+
10+
def __init__(self, lnxlink):
11+
"""Setup addon"""
12+
self.name = "Logging Level"
13+
self.lnxlink = lnxlink
14+
15+
def exposed_controls(self):
16+
"""Exposes to home assistant"""
17+
log_levels = [
18+
"NOTSET",
19+
"DEBUG",
20+
"INFO",
21+
"WARNING",
22+
"ERROR",
23+
]
24+
return {
25+
"Logging Level": {
26+
"type": "select",
27+
"icon": "mdi:math-log",
28+
"options": log_levels,
29+
"entity_category": "diagnostic",
30+
},
31+
}
32+
33+
def get_info(self):
34+
"""Gather information from the system"""
35+
current_level = logger.getEffectiveLevel()
36+
level_name = logging.getLevelName(current_level)
37+
return level_name
38+
39+
def start_control(self, topic, data):
40+
"""Control system"""
41+
if data in [0, "notset", "Notset", "NOTSET"]:
42+
logger.setLevel(logging.NOTSET)
43+
elif data in [1, 10, "debug", "Debug", "DEBUG"]:
44+
logger.setLevel(logging.DEBUG)
45+
elif data in [2, 20, "info", "Info", "INFO"]:
46+
logger.setLevel(logging.INFO)
47+
elif data in [3, 30, "warning", "Warning", "WARNING"]:
48+
logger.setLevel(logging.WARNING)
49+
elif data in [4, 40, "error", "Error", "ERROR"]:
50+
logger.setLevel(logging.ERROR)
51+
elif data in [5, 50, "critical", "Critical", "CRITICAL"]:
52+
logger.setLevel(logging.CRITICAL)

0 commit comments

Comments
 (0)