holado 0.2.4__py3-none-any.whl → 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of holado might be problematic. Click here for more details.

@@ -14,23 +14,20 @@
14
14
 
15
15
 
16
16
 
17
- def configure(initialize_logging=True, log_level=None):
17
+ def configure(use_holado_logger=True, logging_config_file_path=None, log_level=None, log_on_console=False, log_in_file=True):
18
18
  from holado_logging.common.logging.log_config import LogConfig
19
- if log_level is None:
20
- import logging
21
- log_level = logging.INFO
22
-
23
- LogConfig.configure(initialize_logging=initialize_logging, log_level=log_level)
19
+ LogConfig.configure(use_holado_logger=use_holado_logger, config_file_path=logging_config_file_path, log_level=log_level, log_on_console=log_on_console, log_in_file=log_in_file)
24
20
 
25
21
  def dependencies():
26
22
  return None
27
23
 
28
- def register():
24
+ def initialize_and_register():
29
25
  from holado.common.context.session_context import SessionContext
30
26
  from holado_logging.common.logging.log_manager import LogManager
31
27
 
32
28
  log_manager = LogManager()
33
- log_manager.initialize(log_on_console=True)
29
+ log_manager.configure()
30
+ log_manager.initialize()
34
31
 
35
32
  SessionContext.instance().services.register_service_instance("log_manager", log_manager, SessionContext.instance(),
36
33
  raise_if_service_exist=False, raise_if_object_exist=False)
@@ -15,7 +15,7 @@ import logging
15
15
 
16
16
  logger = logging.getLogger(__name__)
17
17
 
18
- #TODO EKL: rename HoladoLogger
18
+
19
19
  class HALogger(logging.Logger):
20
20
  default_message_size_limit = None
21
21
 
@@ -56,7 +56,7 @@ class HALogger(logging.Logger):
56
56
  # logger.print(f"Change logger {self} level to {level}")
57
57
  # logging.Logger.setLevel(self, level)
58
58
 
59
- class TestRootLogger(HALogger):
59
+ class HARootLogger(HALogger):
60
60
  """
61
61
  Implementation is a copy of logging.RootLogger
62
62
  """
@@ -20,36 +20,61 @@ import logging
20
20
  class LogConfig(object):
21
21
  TLogger = None
22
22
  TManager = None
23
+ config_file_path = None
23
24
  default_level = logging.INFO
25
+ log_on_console=False
26
+ log_in_file=True
27
+ __is_configured = False
24
28
 
25
29
  @classmethod
26
- def configure(cls, initialize_logging=True, log_level=None):
30
+ def configure(cls, use_holado_logger=True, config_file_path=None, log_level=None, log_on_console=False, log_in_file=True):
31
+ if cls.__is_configured:
32
+ logging.warning(f"Logging was already configured, it is not possible to configure it twice. This new configuration is skipped.")
33
+ return
34
+
27
35
  # HolAdo needs at least to add logging level TRACE and PRINT
28
36
  cls.add_logging_level_trace()
29
37
  cls.add_logging_level_print()
30
38
 
39
+ cls.config_file_path = config_file_path
40
+ if config_file_path:
41
+ import configparser
42
+ config = configparser.ConfigParser()
43
+ config.read(config_file_path)
44
+ log_level = config.get("holado", "level")
45
+ log_on_console = config.get("holado", "log_on_console")
46
+ log_in_file = config.get("holado", "log_in_file")
47
+
31
48
  if log_level:
32
49
  if isinstance(log_level, str):
33
- cls.default_level = logging._nameToLevel[log_level]
34
- else:
35
- cls.default_level = log_level
50
+ log_level = logging._nameToLevel[log_level]
51
+ cls.default_level = log_level
52
+ if log_on_console:
53
+ if isinstance(log_on_console, str):
54
+ log_on_console = True if log_on_console == "True" else False
55
+ cls.log_on_console = log_on_console
56
+ if log_in_file:
57
+ if isinstance(log_in_file, str):
58
+ log_in_file = True if log_in_file == "True" else False
59
+ cls.log_in_file = log_in_file
60
+
61
+ if use_holado_logger:
62
+ cls.__set_holado_loggers()
36
63
 
37
- if initialize_logging:
38
- from holado_logging.common.logging.holado_logger import HALogger
39
-
40
- HALogger.default_message_size_limit = 10000
41
- cls.TLogger = HALogger
42
- cls.TManager = logging.Manager
43
-
44
- # Configure logging
45
- cls.configure_logging()
64
+ cls.__is_configured = True
46
65
 
47
66
  @classmethod
48
- def configure_logging(cls):
49
- #TODO EKL: make loggers configuration optional
50
- # Configure loggers
51
- from holado_logging.common.logging.holado_logger import TestRootLogger
52
- logging.root = TestRootLogger(cls.default_level)
67
+ def __set_holado_loggers(cls):
68
+ from holado_logging.common.logging.holado_logger import HALogger
69
+
70
+ # Configure loggers to use
71
+ HALogger.default_message_size_limit = 10000
72
+ cls.TLogger = HALogger
73
+ cls.TManager = logging.Manager
74
+
75
+ # Set loggers in logging
76
+ from holado_logging.common.logging.holado_logger import HARootLogger
77
+ logging.root = HARootLogger(cls.default_level)
53
78
  logging.Logger.root = logging.root
54
79
  logging.Logger.manager = cls.TManager(cls.TLogger.root)
55
80
 
@@ -63,28 +63,28 @@ class LogManager(object):
63
63
  self.format = '%(asctime)s | %(process)-5d-%(thread)-5d | %(levelname)5s | %(module)35s | %(message)s'
64
64
  self.style = '%'
65
65
 
66
- def initialize(self, log_on_console=True):
66
+ def configure(self):
67
+ self.__config_file_path = LogConfig.config_file_path
68
+
69
+ if self.__config_file_path:
70
+ config = configparser.ConfigParser()
71
+ config.read(self.__config_file_path)
72
+
73
+ if config.has_section("loggers_levels"):
74
+ self.__loggers_levels = config.items(section="loggers_levels")
75
+
76
+ def initialize(self):
67
77
  """
68
78
  Initialize log manager.
69
79
  If log_on_console is True, logs are published on console until a new configuration by calling method set_config
70
80
  """
71
- if log_on_console:
81
+ handlers = []
82
+ if LogConfig.log_on_console:
72
83
  self.on_console = True
73
84
  self.__console_handler = self.__new_console_handler()
74
- logging.basicConfig(format=self.format, style=self.style, level=LogConfig.default_level, handlers=[self.__console_handler])
75
- else:
76
- logging.basicConfig(format=self.format, style=self.style, level=LogConfig.default_level, handlers=[])
77
-
78
- def set_config_file_path(self, file_path, update_default_level=True):
79
- self.__config_file_path = file_path
85
+ handlers.append(self.__console_handler)
80
86
 
81
- config = configparser.ConfigParser()
82
- config.read(self.__config_file_path)
83
- if update_default_level:
84
- LogConfig.default_level = config.get("logger_root", "level")
85
-
86
- if config.has_section("loggers_levels"):
87
- self.__loggers_levels = config.items(section="loggers_levels")
87
+ logging.basicConfig(format=self.format, style=self.style, level=LogConfig.default_level, handlers=handlers)
88
88
 
89
89
  def has_log_file(self, file_name):
90
90
  with self.__files_lock:
@@ -154,8 +154,7 @@ class LogManager(object):
154
154
  # Update log destination to files
155
155
  with self.__files_lock:
156
156
  # Remove old log files
157
- # if self.__root_file_name:
158
- # self.remove_root_file_handler(do_reset=True)
157
+ # Note: root file is not removed if it is configured
159
158
  for file_name in list(self.__file_handlers.keys()):
160
159
  if file_name not in self.__file_names:
161
160
  self.remove_file_handler(file_name, do_remove_log_file=False)
@@ -166,7 +165,6 @@ class LogManager(object):
166
165
  for file_name in self.__file_names:
167
166
  if file_name not in list(self.__file_handlers.keys()):
168
167
  self.add_file_handler(file_name)
169
-
170
168
 
171
169
  # level
172
170
  if logger_.getEffectiveLevel() != LogConfig.default_level:
@@ -176,7 +174,10 @@ class LogManager(object):
176
174
  for name, level in self.__loggers_levels:
177
175
  if not name.startswith("#"):
178
176
  logging.getLogger(name).setLevel(level)
179
-
177
+
178
+ # WARNING: For local debug only
179
+ # logging.getLogger("holado_logging.common.logging.log_manager").setLevel(logging.DEBUG)
180
+
180
181
  def set_level(self, log_level, do_set_config=True):
181
182
  from holado_core.common.exceptions.technical_exception import TechnicalException
182
183
 
@@ -187,7 +187,7 @@ class MultitaskManager(object):
187
187
 
188
188
  def prepare_thread(self, name, update_parent=True):
189
189
  """
190
- Create a process context and return a unique name based to given name
190
+ Create a thread context and return a unique name based to given name
191
191
  """
192
192
  with self.__thread_lock:
193
193
  res = name
@@ -21,6 +21,7 @@ from holado_python.standard_library.typing import Typing
21
21
  from holado.common.handlers.undefined import undefined_argument, default_context
22
22
  from holado_core.common.exceptions.technical_exception import TimeoutTechnicalException
23
23
  from holado_core.common.exceptions.functional_exception import FunctionalException
24
+ from holado_python.common.tools.datetime import DateTime, FORMAT_DATETIME_ISO
24
25
 
25
26
  logger = logging.getLogger(__name__)
26
27
 
@@ -35,7 +36,8 @@ class Thread(threading.Thread):
35
36
  default_wait_timeout = Config.timeout_seconds * 1000
36
37
 
37
38
  self.__name = name
38
- self.__unique_name = SessionContext.instance().multitask_manager.prepare_thread(name)
39
+ # Note: if SessionContext doesn't have an instance (like during session context reset), use name+now as unique name
40
+ self.__unique_name = SessionContext.instance().multitask_manager.prepare_thread(name) if SessionContext.has_instance() else f"{name}_{DateTime.datetime_2_str(DateTime.now(), FORMAT_DATETIME_ISO)}"
39
41
  self.__default_wait_timeout = default_wait_timeout
40
42
  self.__delay_before_run_sec = delay_before_run_sec
41
43
 
@@ -48,7 +50,8 @@ class Thread(threading.Thread):
48
50
  self._is_idle.set()
49
51
 
50
52
  # Register thread
51
- if register_thread:
53
+ # Note: Do not register thread if session context doesn't have an instance (like during session context reset)
54
+ if register_thread and SessionContext.has_instance():
52
55
  # Registered name has to be unique
53
56
  SessionContext.instance().threads_manager.register_thread(self.__unique_name, self, scope=register_scope)
54
57
 
@@ -74,13 +77,14 @@ class Thread(threading.Thread):
74
77
 
75
78
  def _set_ident(self):
76
79
  super()._set_ident()
77
- if not MultitaskManager.has_thread_native_id():
80
+ if not MultitaskManager.has_thread_native_id() and SessionContext.has_instance():
78
81
  SessionContext.instance().multitask_manager.set_thread_uid(self.__unique_name, MultitaskManager.get_thread_uid(thread=self))
79
82
 
80
83
  if MultitaskManager.has_thread_native_id():
81
84
  def _set_native_id(self):
82
85
  super()._set_native_id()
83
- SessionContext.instance().multitask_manager.set_thread_uid(self.__unique_name, MultitaskManager.get_thread_uid(thread=self))
86
+ if SessionContext.has_instance():
87
+ SessionContext.instance().multitask_manager.set_thread_uid(self.__unique_name, MultitaskManager.get_thread_uid(thread=self))
84
88
 
85
89
  def join(self, timeout=undefined_argument, raise_if_still_alive=True):
86
90
  """
@@ -14,6 +14,7 @@
14
14
  import logging
15
15
  from behave.runner import Runner
16
16
  from behave.parser import parse_feature
17
+ from holado.holado_config import Config
17
18
 
18
19
 
19
20
  logger = logging.getLogger(__name__)
@@ -55,12 +56,9 @@ class IndependantRunner(Runner):
55
56
  feature_text = \
56
57
  """
57
58
  Feature: Fake
58
-
59
59
  Scenario: Fake
60
- # Wait 7 days
61
- Given DELAY = ${7 * 24 * 3600}
62
- When wait DELAY seconds
63
- """
60
+ When wait {runner_session_timeout} seconds
61
+ """.format(runner_session_timeout=Config.session_timeout_seconds)
64
62
  feature = parse_feature(feature_text)
65
63
 
66
64
  return super().run_model([feature])
@@ -426,6 +426,8 @@ class StepTools(object):
426
426
  new_type = {'pattern':pattern, 'function':func}
427
427
  if type_name in cls.__registered_types:
428
428
  logger.warning(f"Overriding step parameter type '{type_name}': {cls.__registered_types[type_name]['pattern']} -> {new_type['pattern']}")
429
+ import traceback
430
+ logging.warning("".join(traceback.format_list(traceback.extract_stack())))
429
431
  cls.__registered_types[type_name] = new_type
430
432
  if Tools.do_log(logger, logging.TRACE): # @UndefinedVariable
431
433
  logger.trace(f"Registered step parameter type '{type_name}'")
@@ -31,7 +31,7 @@ import holado
31
31
  # - log_on_console is True for initialization phase, it will be set to False when root log file will be defined
32
32
  # - logging config file
33
33
  from test_holado.test_holado_session_context import TestHoladoSessionContext
34
- holado.initialize(TSessionContext=TestHoladoSessionContext, logging_config_file=os.path.join(here, 'logging.conf'), log_level=logging.INFO, log_on_console=True)
34
+ holado.initialize(TSessionContext=TestHoladoSessionContext, logging_config_file_path=os.path.join(here, 'logging.conf'), log_level=logging.INFO, log_on_console=True)
35
35
 
36
36
 
37
37
 
test_holado/logging.conf CHANGED
@@ -1,7 +1,9 @@
1
- [logger_root]
1
+ [holado]
2
2
  #level=INFO
3
3
  level=DEBUG
4
4
  #level=TRACE
5
+ log_on_console=False
6
+ log_in_file=True
5
7
 
6
8
  [loggers_levels]
7
9
  holado=INFO
File without changes