forked from mirrors/thatmattlove-hyperglass
fix logging issues
This commit is contained in:
parent
b617df24d1
commit
41248231ae
5 changed files with 14 additions and 8 deletions
|
|
@ -47,7 +47,7 @@ async def execute(query: "Query") -> Union["OutputDataModel", str]:
|
||||||
"""Initiate query validation and execution."""
|
"""Initiate query validation and execution."""
|
||||||
params = use_state("params")
|
params = use_state("params")
|
||||||
output = params.messages.general
|
output = params.messages.general
|
||||||
_log = log.bind(query=query, device=query.device)
|
_log = log.bind(query=query.summary(), device=query.device)
|
||||||
_log.debug("")
|
_log.debug("")
|
||||||
|
|
||||||
mapped_driver = map_driver(query.device.driver)
|
mapped_driver = map_driver(query.device.driver)
|
||||||
|
|
@ -67,7 +67,6 @@ async def execute(query: "Query") -> Union["OutputDataModel", str]:
|
||||||
response = await driver.collect()
|
response = await driver.collect()
|
||||||
|
|
||||||
output = await driver.response(response)
|
output = await driver.response(response)
|
||||||
_log.bind(response=response).debug("Query response")
|
|
||||||
|
|
||||||
if is_series(output):
|
if is_series(output):
|
||||||
if len(output) == 0:
|
if len(output) == 0:
|
||||||
|
|
|
||||||
|
|
@ -56,8 +56,6 @@ async def read_package_json() -> t.Dict[str, t.Any]:
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
raise RuntimeError(f"Error reading package.json: {str(err)}") from err
|
raise RuntimeError(f"Error reading package.json: {str(err)}") from err
|
||||||
|
|
||||||
log.bind(package_json=package_json).debug("package.json value")
|
|
||||||
|
|
||||||
return package_json
|
return package_json
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -328,7 +326,6 @@ async def build_frontend( # noqa: C901
|
||||||
}
|
}
|
||||||
|
|
||||||
build_json = json.dumps(build_data, default=str)
|
build_json = json.dumps(build_data, default=str)
|
||||||
log.bind(data=build_json).debug("UI Build Data")
|
|
||||||
|
|
||||||
# Create SHA256 hash from all parameters passed to UI, use as
|
# Create SHA256 hash from all parameters passed to UI, use as
|
||||||
# build identifier.
|
# build identifier.
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,11 @@ _LOG_LEVELS = [
|
||||||
{"name": "CRITICAL", "color": "<r>"},
|
{"name": "CRITICAL", "color": "<r>"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
_EXCLUDE_MODULES = (
|
||||||
|
"PIL",
|
||||||
|
"svglib",
|
||||||
|
)
|
||||||
|
|
||||||
HyperglassConsole = Console(
|
HyperglassConsole = Console(
|
||||||
theme=Theme(
|
theme=Theme(
|
||||||
{
|
{
|
||||||
|
|
@ -119,6 +124,9 @@ class LibInterceptHandler(logging.Handler):
|
||||||
def init_logger(level: t.Union[int, str] = logging.INFO):
|
def init_logger(level: t.Union[int, str] = logging.INFO):
|
||||||
"""Initialize hyperglass logging instance."""
|
"""Initialize hyperglass logging instance."""
|
||||||
|
|
||||||
|
for mod in _EXCLUDE_MODULES:
|
||||||
|
logging.getLogger(mod).propagate = False
|
||||||
|
|
||||||
# Reset built-in Loguru configurations.
|
# Reset built-in Loguru configurations.
|
||||||
_loguru_logger.remove()
|
_loguru_logger.remove()
|
||||||
|
|
||||||
|
|
@ -133,6 +141,7 @@ def init_logger(level: t.Union[int, str] = logging.INFO):
|
||||||
log_time_format="[%Y%m%d %H:%M:%S]",
|
log_time_format="[%Y%m%d %H:%M:%S]",
|
||||||
),
|
),
|
||||||
format=formatter,
|
format=formatter,
|
||||||
|
colorize=False,
|
||||||
level=level,
|
level=level,
|
||||||
filter=filter_uvicorn_values,
|
filter=filter_uvicorn_values,
|
||||||
enqueue=True,
|
enqueue=True,
|
||||||
|
|
@ -144,6 +153,7 @@ def init_logger(level: t.Union[int, str] = logging.INFO):
|
||||||
enqueue=True,
|
enqueue=True,
|
||||||
format=_FMT if level == logging.INFO else _FMT_DEBUG,
|
format=_FMT if level == logging.INFO else _FMT_DEBUG,
|
||||||
level=level,
|
level=level,
|
||||||
|
colorize=False,
|
||||||
filter=filter_uvicorn_values,
|
filter=filter_uvicorn_values,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -192,6 +202,7 @@ def enable_file_logging(
|
||||||
serialize=structured,
|
serialize=structured,
|
||||||
level=level,
|
level=level,
|
||||||
encoding="utf8",
|
encoding="utf8",
|
||||||
|
colorize=False,
|
||||||
rotation=max_size.human_readable(),
|
rotation=max_size.human_readable(),
|
||||||
)
|
)
|
||||||
_loguru_logger.bind(path=log_file).debug("Logging to file")
|
_loguru_logger.bind(path=log_file).debug("Logging to file")
|
||||||
|
|
@ -207,5 +218,6 @@ def enable_syslog_logging(*, host: str, port: int) -> None:
|
||||||
SysLogHandler(address=(str(host), port)),
|
SysLogHandler(address=(str(host), port)),
|
||||||
format=_FMT_BASIC,
|
format=_FMT_BASIC,
|
||||||
enqueue=True,
|
enqueue=True,
|
||||||
|
colorize=False,
|
||||||
)
|
)
|
||||||
_loguru_logger.bind(host=host, port=port).debug("Logging to syslog target")
|
_loguru_logger.bind(host=host, port=port).debug("Logging to syslog target")
|
||||||
|
|
|
||||||
|
|
@ -77,8 +77,6 @@ def parse_juniper(output: Sequence[str]) -> "OutputDataModel": # noqa: C901
|
||||||
parsed: "OrderedDict" = xmltodict.parse(
|
parsed: "OrderedDict" = xmltodict.parse(
|
||||||
cleaned, force_list=("rt", "rt-entry", "community")
|
cleaned, force_list=("rt", "rt-entry", "community")
|
||||||
)
|
)
|
||||||
_log.debug("Pre-parsed data", data=parsed)
|
|
||||||
|
|
||||||
if "rpc-reply" in parsed.keys():
|
if "rpc-reply" in parsed.keys():
|
||||||
if "xnm:error" in parsed["rpc-reply"]:
|
if "xnm:error" in parsed["rpc-reply"]:
|
||||||
if "message" in parsed["rpc-reply"]["xnm:error"]:
|
if "message" in parsed["rpc-reply"]["xnm:error"]:
|
||||||
|
|
|
||||||
|
|
@ -162,7 +162,7 @@ class InputPluginManager(PluginManager[InputPlugin], type="input"):
|
||||||
"""Execute all input transformation plugins."""
|
"""Execute all input transformation plugins."""
|
||||||
result = query.query_target
|
result = query.query_target
|
||||||
for plugin in self._gather_plugins(query):
|
for plugin in self._gather_plugins(query):
|
||||||
result = plugin.transform(query=query)
|
result = plugin.transform(query=query.summary())
|
||||||
log.bind(name=plugin.name, result=repr(result)).debug("Input Plugin Transform")
|
log.bind(name=plugin.name, result=repr(result)).debug("Input Plugin Transform")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue