Skip to content

Commit

Permalink
remove {source}:{function:s}:{line:d}; from debug log configs, as log…
Browse files Browse the repository at this point in the history
…ging2 doesn't support stacklevel (which logging does); also removed local_call_depth, which served the same purpose as stacklevel in our old log system; will replace it when stacklevel is available, or write our own; remove debugging prints
  • Loading branch information
artgoldberg committed Dec 26, 2019
1 parent 87a4e8f commit 960c533
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions de_sim/config/debug.default.cfg
Expand Up @@ -17,13 +17,13 @@

[[loggers]]
[[[de_sim.debug.file]]]
template = {timestamp}; {name:s}; {level:s}; {source}:{function:s}:{line:d}; {sim_time:f}; {message:s}
template = {timestamp}; {name:s}; {level:s}; {sim_time:f}; {message:s}
handler = debug.file
[[[[additional_context]]]]
sim_time = get_sim_time

[[[de_sim.debug.console]]]
template = {timestamp}; {name:s}; {level:s}; {source}:{function:s}:{line:d}; {sim_time:f}; {message:s}
template = {timestamp}; {name:s}; {level:s}; {sim_time:f}; {message:s}
handler = debug.console
[[[[additional_context]]]]
sim_time = get_sim_time
Expand Down
4 changes: 2 additions & 2 deletions de_sim/simulation_engine.py
Expand Up @@ -288,10 +288,10 @@ def simulate(self, end_time, stop_condition=None, progress=False):

return num_events_handled

def log_with_time(self, msg, local_call_depth=1):
def log_with_time(self, msg):
"""Write a debug log message with the simulation time.
"""
self.fast_debug_file_logger.fast_log(msg, sim_time=self.time, local_call_depth=local_call_depth)
self.fast_debug_file_logger.fast_log(msg, sim_time=self.time)

def provide_event_counts(self):
""" Provide the simulation's categorized event counts
Expand Down
9 changes: 4 additions & 5 deletions de_sim/simulation_object.py
Expand Up @@ -173,19 +173,18 @@ def next_events(self):

return events

def log_event(self, event, local_call_depth=1):
def log_event(self, event):
""" Log an event with its simulation time
Args:
event (:obj:`Event`): the Event to log
local_call_depth (:obj:`int`, optional): the local call depth; default = 1
"""
msg = "Execute: {} {}:{} {} ({})".format(event.event_time,
type(event.receiving_object).__name__,
event.receiving_object.name,
event.message.__class__.__name__,
str(event.message))
self.fast_debug_file_logger.fast_log(msg, sim_time=event.event_time, local_call_depth=local_call_depth)
self.fast_debug_file_logger.fast_log(msg, sim_time=event.event_time)

def render(self, sim_obj=None, as_list=False, separator='\t'):
""" Return the content of an `EventQueue`
Expand Down Expand Up @@ -506,10 +505,10 @@ def render_event_queue(self):
"""
return self.simulator.event_queue.render()

def log_with_time(self, msg, local_call_depth=1):
def log_with_time(self, msg):
""" Write a debug log message with the simulation time.
"""
self.fast_debug_file_logger.fast_log(msg, sim_time=self.time, local_call_depth=local_call_depth)
self.fast_debug_file_logger.fast_log(msg, sim_time=self.time)


class ApplicationSimulationObjectInterface(object, metaclass=ABCMeta): # pragma: no cover
Expand Down
3 changes: 0 additions & 3 deletions de_sim/utilities.py
Expand Up @@ -94,8 +94,6 @@ def __init__(self, logger, level_used):
level_used (:obj:`str`): a logging level, as used in :obj:`logging2.LogLevel`:
"""
self.active = FastLogger.active_logger(logger, level_used)
if self.active:
print(f'FastLogger {logger.name} IS active at {level_used}')
self.method = getattr(logger, level_used)
self.logger = logger

Expand Down Expand Up @@ -150,5 +148,4 @@ def fast_log(self, msg, **kwargs):
kwargs (:obj:`dict`): other logging arguments
"""
if self.active:
print(f'logging: {self.logger.name}')
self.method(msg, **kwargs)
4 changes: 2 additions & 2 deletions examples/config/debug.default.cfg
Expand Up @@ -12,9 +12,9 @@

[[loggers]]
[[[de_sim.debug.example.file]]]
template = {timestamp}; {name:s}; {level:s}; {source}:{function:s}:{line:d}; {message:s}
template = {timestamp}; {name:s}; {level:s}; {message:s}
handler = debug.example.file

[[[de_sim.debug.example.console]]]
template = {timestamp}; {name:s}; {level:s}; {source}:{function:s}:{line:d}; {message:s}
template = {timestamp}; {name:s}; {level:s}; {message:s}
handler = debug.example.console
4 changes: 2 additions & 2 deletions tests/fixtures/config/debug.default.cfg
Expand Up @@ -12,13 +12,13 @@

[[loggers]]
[[[de_sim.debug.testing.file]]]
template = {timestamp}; {name:s}; {level:s}; {source}:{function:s}:{line:d}; {sim_time:f}; {message:s}
template = {timestamp}; {name:s}; {level:s}; {sim_time:f}; {message:s}
handler = debug.testing.file
[[[[additional_context]]]]
sim_time = get_sim_time

[[[de_sim.debug.testing.console]]]
template = {timestamp}; {name:s}; {level:s}; {source}:{function:s}:{line:d}; {sim_time:f}; {message:s}
template = {timestamp}; {name:s}; {level:s}; {sim_time:f}; {message:s}
handler = debug.testing.console
[[[[additional_context]]]]
sim_time = get_sim_time

0 comments on commit 960c533

Please sign in to comment.