Commit 245fbac2 authored by Piergiorgio Pancino's avatar Piergiorgio Pancino Committed by Matias Guijarro

logtools:

 - sanitize name of loggers
 - remove creation of loggers for counters
parent bb2dda19
......@@ -8,6 +8,7 @@
import logging
import contextlib
from logging import Logger, StreamHandler, NullHandler, Formatter
import re
from fnmatch import fnmatch, fnmatchcase
import networkx as nx
......@@ -325,21 +326,16 @@ def create_logger_name(G, node_id):
returns:
logger_name for the specific node
"""
# TODO: implement different starting point
try:
# search before through controllers
path = nx.shortest_path(G, "controllers", node_id)
return "session." + ".".join(
format_node(G, n, format_string="tag->name->class->id") for n in path
)
except (nx.exception.NetworkXNoPath, nx.exception.NodeNotFound):
pass
try:
# search next starting from session
path = nx.shortest_path(G, "session", node_id)
return ".".join(
format_node(G, n, format_string="tag->name->class->id") for n in path
)
logger_names = ["session"]
for n in path:
node_name = format_node(G, n, format_string="tag->name->class->id")
# sanitize name
logger_names.append(re.sub(r"[^0-9A-Za-z_:=\-\(\)\[\]]", "_", node_name))
return ".".join(logger_names)
except (nx.exception.NetworkXNoPath, nx.exception.NodeNotFound):
pass
......
......@@ -11,7 +11,7 @@ import re
from bliss.common.logtools import map_update_loggers, Log, LogMixin, logging_startup
from bliss.common.standard import debugon, debugoff, lslog
from bliss.common.mapping import Map
from bliss.common.mapping import Map, map_id
from bliss.common import session
import bliss
......@@ -76,6 +76,16 @@ class MappedController(NotMappedController, LogMixin):
session.get_current().map.register(self, parents_list, children_list)
class Device(LogMixin):
"""
Device for Logging Test
"""
def __init__(self, name="", parents_list=None, children_list=None):
self.name = name
session.get_current().map.register(self, parents_list, children_list)
def test_bare_system(params):
all_loggers = logging.getLogger().manager.loggerDict
names = ["session", "session.controllers"]
......@@ -282,7 +292,6 @@ def test_chain_devices_log(params, caplog):
# \- d6 -- d7 -- d8
# \- d9 -- d10
# \- d11
map = session.get_current().map
d1 = MappedController("d1")
d2 = MappedController("d2", parents_list=[d1])
d3 = MappedController("d3", parents_list=[d2])
......@@ -300,6 +309,17 @@ def test_chain_devices_log(params, caplog):
node_check(d6, caplog, children=[d7, d8, d9, d10, d11])
def test_log_name_sanitize(params):
beacon, log = params
m = session.get_current().map
d1 = Device(r"Hi_*2^a.o@@-[200]")
assert map_id(d1) in m
assert m[map_id(d1)]["_logger"].name == "session.controllers.Hi__2_a_o__-[200]"
d2 = Device(r"/`/deviceDEVICE=+{}()")
assert map_id(d1) in m
assert m[map_id(d2)]["_logger"].name == "session.controllers.___deviceDEVICE=___()"
def test_level_switch(params, caplog):
"""
When we change the level manually with a value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment