-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] update python 3.0 for vsc-base #258
Changes from 1 commit
6661251
84fd379
ec0b31b
6e0638d
36cd0f7
f0d7d53
3d28c90
90e2abc
9d9be9f
3aefc93
a8bd01f
ac6bc50
87aba51
a3932a8
34123cb
9b47ca1
be0316e
c77d2bf
04df6be
3cc6fa5
161be5b
5f8ad23
2bc5387
1d68791
aee8e1d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -187,10 +187,12 @@ def _env_to_boolean(varname, default=False): | |
APOCALYPTIC = 'APOCALYPTIC' | ||
# register new loglevelname | ||
logging.addLevelName(logging.CRITICAL * 2 + 1, APOCALYPTIC) | ||
|
||
# register QUIET, EXCEPTION and FATAL alias | ||
logging._levelNames['EXCEPTION'] = logging.ERROR | ||
logging._levelNames['FATAL'] = logging.CRITICAL | ||
logging._levelNames['QUIET'] = logging.WARNING | ||
if hasattr(logging,'_levelNames'): | ||
logging._levelNames['EXCEPTION'] = logging.ERROR | ||
logging._levelNames['FATAL'] = logging.CRITICAL | ||
logging._levelNames['QUIET'] = logging.WARNING | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't find this in the logging 3.0 docs, so I'm guessing it is relevant only to some older version and we can just check and pass over if the data structure doesn't exist? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Python 2.7, there's this:
We are defining additional log levels here, which we are injecting in the I guess we'll need to figure out what the equivalent approach is in Python 3? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we want this https://docs.python.org/3/library/logging.html#logging.addLevelName and with the print you gave me above, I think all I need is that (the name and the level) for each of the new levels. Let me test it out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Python 3 has
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In [1]: import logging
In [2]: logging._levelToName
Out[2]:
{0: 'NOTSET',
10: 'DEBUG',
20: 'INFO',
30: 'WARNING',
40: 'ERROR',
50: 'CRITICAL'}
In [3]: logging.addLevelName(logging.CRITICAL,'PINKYANDTHEBRAIN')
In [4]: logging._levelToName
Out[4]:
{0: 'NOTSET',
10: 'DEBUG',
20: 'INFO',
30: 'WARNING',
40: 'ERROR',
50: 'PINKYANDTHEBRAIN'} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to replace it, which isn't what we want. I'm going to look into adding a custom level. |
||
|
||
# mpi rank support | ||
|
@@ -326,7 +328,7 @@ def raiseException(self, message, exception=None, catch=False): | |
exception = self.RAISE_EXCEPTION_CLASS | ||
|
||
self.RAISE_EXCEPTION_LOG_METHOD(fullmessage) | ||
raise exception, message, tb | ||
raise exception(message) | ||
|
||
# pylint: disable=unused-argument | ||
def deprecated(self, msg, cur_ver, max_ver, depth=2, exception=None, log_callback=None, *args, **kwargs): | ||
|
@@ -477,12 +479,12 @@ def getLogger(name=None, fname=False, clsname=False, fancyrecord=None): | |
l = logging.getLogger(fullname) | ||
l.fancyrecord = fancyrecord | ||
if _env_to_boolean('FANCYLOGGER_GETLOGGER_DEBUG'): | ||
print 'FANCYLOGGER_GETLOGGER_DEBUG', | ||
print 'name', name, 'fname', fname, 'fullname', fullname, | ||
print "getRootLoggerName: ", getRootLoggerName() | ||
print('FANCYLOGGER_GETLOGGER_DEBUG'), | ||
print('name', name, 'fname', fname, 'fullname', fullname), | ||
print("getRootLoggerName: ", getRootLoggerName()) | ||
if hasattr(l, 'get_parent_info'): | ||
print 'parent_info verbose' | ||
print "\n".join(l.get_parent_info("FANCYLOGGER_GETLOGGER_DEBUG")) | ||
print('parent_info verbose') | ||
print("\n".join(l.get_parent_info("FANCYLOGGER_GETLOGGER_DEBUG"))) | ||
sys.stdout.flush() | ||
return l | ||
|
||
|
@@ -585,7 +587,7 @@ def logToFile(filename, enable=True, filehandler=None, name=None, max_bytes=MAX_ | |
os.makedirs(directory) | ||
except Exception as ex: | ||
exc, detail, tb = sys.exc_info() | ||
raise exc, "Cannot create logdirectory %s: %s \n detail: %s" % (directory, ex, detail), tb | ||
raise exc("Cannot create logdirectory %s: %s \n detail: %s" % (directory, ex, detail)) | ||
|
||
return _logToSomething( | ||
logging.handlers.RotatingFileHandler, | ||
|
@@ -745,8 +747,8 @@ def setLogLevel(level): | |
|
||
logger.setLevel(level) | ||
if _env_to_boolean('FANCYLOGGER_LOGLEVEL_DEBUG'): | ||
print "FANCYLOGGER_LOGLEVEL_DEBUG", level, logging.getLevelName(level) | ||
print "\n".join(logger.get_parent_info("FANCYLOGGER_LOGLEVEL_DEBUG")) | ||
print("FANCYLOGGER_LOGLEVEL_DEBUG", level, logging.getLevelName(level)) | ||
print("\n".join(logger.get_parent_info("FANCYLOGGER_LOGLEVEL_DEBUG"))) | ||
sys.stdout.flush() | ||
|
||
|
||
|
@@ -865,8 +867,8 @@ class FancyRootLogger(FancyLogger, logging.RootLogger): | |
lgr[1].parent = root | ||
|
||
if _env_to_boolean('FANCYLOGGER_LOGLEVEL_DEBUG'): | ||
print "FANCYLOGGER_LOGLEVEL_DEBUG SETROOT ", lvl, logging.getLevelName(lvl) | ||
print "\n".join(root.get_parent_info("FANCYLOGGER_LOGLEVEL_DEBUG SETROOT ")) | ||
print("FANCYLOGGER_LOGLEVEL_DEBUG SETROOT ", lvl, logging.getLevelName(lvl)) | ||
print("\n".join(root.get_parent_info("FANCYLOGGER_LOGLEVEL_DEBUG SETROOT "))) | ||
sys.stdout.flush() | ||
|
||
# silence the root logger | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line, specifically the 01
wasn't clear to me why it would be used instead of 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there's a good reason for the
01
, it's exactly the same as1
...Maybe because this refers to 1st day of the month? Dunno, but changing it to
1
seems fine to me.We could double-check that this is covered by the tests to make sure changing it is OK, but I don't see how it could have any impact (famous last words!).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In python2 01 is the octal representation for 1, this is deprecated in python3 (should be 0o1)
If the 01 is needed for programatic reasons here, replace it with 0o1 instead of 1 (but I can't see a reason why it would make a difference)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh interesting! I didn't know this, but it looks like the 1 should be equivalent to 0o1 (see here https://bugs.python.org/issue1715302). And here is a confirmation (in Python 3) that the two produce the same result: