Belle II Software  release-08-01-10
logsummary.py
1 #!/usr/bin/env python3
2 
3 
10 
11 # this is a test executable, not a module so we don't need doxygen warnings
12 # @cond SUPPRESS_DOXYGEN
13 
14 """
15 Test if the log summary is shown correctly in all cases
16 """
17 
18 from basf2 import create_path, process, Module, logging, LogLevel, LogInfo, \
19  B2WARNING, B2FATAL, B2ERROR
20 import multiprocessing
21 
22 
23 def fork_process(*args, target=process):
24  """Run function in forked child to eliminate side effects"""
25  sub = multiprocessing.Process(target=target, args=args)
26  sub.start()
27  sub.join()
28 
29 
30 class FatalError(Module):
31  """Simple module to just print a warning, an error and a fatal error"""
32 
33  def event(self):
34  """print messages"""
35  B2WARNING("warning")
36  B2ERROR("error")
37  B2FATAL("fatal error")
38 
39 
40 logging.log_level = LogLevel.WARNING
41 for level in LogLevel.values.values():
42  logging.set_info(level, LogInfo.LEVEL | LogInfo.MODULE | LogInfo.PACKAGE | LogInfo.MESSAGE)
43 
44 main = create_path()
45 main.add_module("EventInfoSetter")
46 module = main.add_module(FatalError())
47 
48 print("run in default settings")
49 fork_process(main)
50 
51 print("run with no warnings")
52 logging.log_level = LogLevel.ERROR
53 fork_process(main)
54 logging.log_level = LogLevel.WARNING
55 
56 print("run with no framework warnings")
57 logging.package("framework").log_level = LogLevel.ERROR
58 fork_process(main)
59 logging.package("framework").log_level = LogLevel.WARNING
60 
61 print("run with no module warnings")
62 module.set_log_level(LogLevel.ERROR)
63 fork_process(main)
64 module.set_log_level(LogLevel.WARNING)
65 
66 print("run without summary")
67 logging.enable_summary(False)
68 fork_process(main)
69 
70 # @endcond