Skip to content

Commit

Permalink
Merge pull request #21 from lobax/fix/logging
Browse files Browse the repository at this point in the history
Fall back to stdout when /dev/null doesn't exist
  • Loading branch information
KissPeter committed Oct 2, 2019
2 parents b9137d3 + 389e20d commit 8cda1f3
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions apifuzzer/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from logging import Formatter
from logging.handlers import SysLogHandler
from apifuzzer.custom_fuzzers import RandomBitsField
Expand Down Expand Up @@ -33,11 +34,13 @@ def get_sample_data_by_type(param_type):


def set_logger(level='warning'):
syslog = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_LOCAL2)
syslog.setFormatter(Formatter('%(process)d [%(levelname)s] %(name)s: %(message)s'))
handler = logging.StreamHandler()
if os.path.exists('/dev/null/'):
handler = SysLogHandler(address='/dev/log', facility=SysLogHandler.LOG_LOCAL2)
handler.setFormatter(Formatter('%(process)d [%(levelname)s] %(name)s: %(message)s'))
logger = logging.getLogger()
logger.setLevel(level=level.upper())
logger.addHandler(syslog)
logger.addHandler(handler)
return logger


Expand Down

0 comments on commit 8cda1f3

Please sign in to comment.