Commit 75419289 authored by Matias Guijarro's avatar Matias Guijarro

logtools: automatically add object to map when _logger if called, if not registered yet

parent 1386ece5
......@@ -33,10 +33,11 @@ class LogMixin:
@autocomplete_property
def _logger(self, *args, **kwargs):
m = session.get_current().map
id_ = id(self)
if id_ not in m.G:
return None
return m.G.node[id_]["_logger"]
id_ = map_id(self)
if id_ in m.G:
return m.G.node[id_]["_logger"]
n = m.register(self)
return n["_logger"]
def improve_logger(logger_instance):
......
......@@ -187,13 +187,9 @@ def test_LogMixin(params, caplog):
beacon, log = params
nmc = NotMappedController()
assert nmc._logger.name == "session.controllers.nmc"
mc = MappedController()
with pytest.raises(AttributeError):
nmc.msg_debug()
with pytest.raises(AttributeError):
nmc.msg_debug_data()
with pytest.raises(AttributeError):
nmc.msg_info()
assert mc._logger.name == "session.controllers.mc"
mc._logger.debugon() # activates debug logging level
expected = "Debug message"
......
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