Skip to content

Commit

Permalink
Fix logging to work with python 2.6
Browse files Browse the repository at this point in the history
Python 2.6 has a number of different areas:
o setLevel silently ignores non integers, so strings cannot be used.
o getLogger at the top level needs to be 'root' if submodules are to
  inherit correctly.

Tidied up the library logging definition to follow the root logger.

Addresses Issue: RedHatOfficial#67
  • Loading branch information
NZJourneyMan committed Jul 31, 2017
1 parent 34a43bb commit 77f3ffc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
9 changes: 1 addition & 8 deletions rhsda.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@


# Logging
logging.addLevelName(25, 'NOTICE')
consolehandler = logging.StreamHandler()
consolehandler.setLevel('DEBUG')
consolehandler.setFormatter(logging.Formatter("[%(levelname)-7s] %(name)s: %(message)s"))
logger = logging.getLogger('rhsda')
logger.setLevel('NOTICE')
logger.addHandler(consolehandler)
logger = logging.getLogger(__name__)


# Establish cveFields namespace
Expand Down Expand Up @@ -176,7 +170,6 @@ class ApiClient:
def __init__(self, logLevel='notice'):
self.cfg = Namespace()
self.cfg.apiUrl = 'https://access.redhat.com/labs/securitydataapi'
logger.setLevel(logLevel.upper())

def _get_terminal_width(self):
h, w, hp, wp = struct.unpack('HHHH', fcntl.ioctl(0, termios.TIOCGWINSZ, struct.pack('HHHH', 0, 0, 0, 0)))
Expand Down
16 changes: 11 additions & 5 deletions rhsecapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,21 @@
vers = {}
vers['version'] = '1.0.1'
vers['date'] = '2017/06/27'
logLevels = {
'DEBUG': logging.DEBUG,
'INFO': logging.INFO,
'WARNING': logging.WARNING,
'NOTICE': 25,
'ERROR': logging.ERROR,
}



# Logging
logging.addLevelName(25, 'NOTICE')
logging.addLevelName(logLevels['NOTICE'], 'NOTICE')
consolehandler = logging.StreamHandler()
consolehandler.setLevel('DEBUG')
consolehandler.setFormatter(logging.Formatter("[%(levelname)-7s] %(name)s: %(message)s"))
logger = logging.getLogger('rhsecapi')
logger.setLevel('NOTICE')
logger = logging.getLogger()
logger.addHandler(consolehandler)


Expand Down Expand Up @@ -340,7 +346,7 @@ def parse_args():
o.outFormat = 'jsonpretty'
else:
o.outFormat = 'plaintext'
logger.setLevel(o.loglevel.upper())
logger.setLevel(logLevels[o.loglevel.upper()])
return o


Expand Down

0 comments on commit 77f3ffc

Please sign in to comment.