Skip to content

Commit ac40cce

Browse files
committed
[__init__] logging should be defined in the calling script - option B
Add a method in __init__ whcih defines the original log settings (handles, formatter, ...)
1 parent 6b51831 commit ac40cce

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

OMPython/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,29 @@
3636
CONDITIONS OF OSMC-PL.
3737
"""
3838

39+
import logging
40+
3941
from OMPython.OMCSession import OMCSessionBase, OMCSessionZMQ
4042
from OMPython.ModelicaSystem import ModelicaSystem, ModelicaSystemError, LinearizationResult
4143

44+
45+
def ompython_log_definiton():
46+
# Logger Defined
47+
logger = logging.getLogger('OMPython')
48+
logger.setLevel(logging.DEBUG)
49+
# create console handler with a higher log level
50+
logger_console_handler = logging.StreamHandler()
51+
logger_console_handler.setLevel(logging.INFO)
52+
53+
# create formatter and add it to the handlers
54+
logger_formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
55+
logger_console_handler.setFormatter(logger_formatter)
56+
57+
# add the handlers to the logger
58+
logger.addHandler(logger_console_handler)
59+
logger.setLevel(logging.WARNING)
60+
61+
4262
# global names imported if import 'from OMPython import *' is used
4363
__all__ = [
4464
'ModelicaSystem',

0 commit comments

Comments
 (0)