Skip to content

Commit ab8afce

Browse files
Merge pull request #213 from splunk/Add-logging-support-helmut.log
ACD-4560 Added logging in helmut
2 parents 9368498 + 06093d1 commit ab8afce

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

pytest_splunk_addon/helmut/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
@author: Nicklas Ansman-Giertz
33
44
@since: 2011-11-23
5-
"""
5+
"""
6+
from . import log
7+
log.setup_logger(debug=True)

pytest_splunk_addon/helmut/log/__init__.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,30 @@
99
import logging.config
1010
import os
1111
from builtins import object
12-
from logging import Formatter
12+
from logging import FileHandler, Formatter
1313

1414
from future.utils import with_metaclass
1515

1616
_LOG_FORMAT = "[%(asctime)s] %(levelname)s - %(name)s: %(message)s"
1717
_DATE_FORMAT = "%Y-%m-%d %H:%M:%S.%f"
18-
_FILE_NAME = "..log"
18+
_FILE_NAME = "helmut.log"
1919

20-
21-
def setup_logger():
20+
def setup_logger(debug=False):
2221
"""
2322
Setups up the logging library
23+
24+
@param debug: If debug log messages are to be outputted
25+
@type debug: bool
2426
"""
25-
logging_conf = os.path.join(
26-
os.path.dirname(os.path.abspath(__file__)), "logging.conf"
27-
)
28-
logging.config.fileConfig(logging_conf)
27+
logger = logging.getLogger('')
28+
handler = FileHandler(filename=_FILE_NAME, mode="w")
29+
handler.setFormatter(HelmutFormatter(_LOG_FORMAT))
30+
level = logging.INFO
31+
if debug:
32+
level = logging.DEBUG
33+
logger.addHandler(handler)
34+
logger.setLevel(level)
35+
logger.debug('Logger: DEBUG logging is enabled')
2936

3037

3138
class HelmutFormatter(Formatter):

0 commit comments

Comments
 (0)