fixup! wcfs: py: Log with date and time present
Thomas reports that wcfs crashes in glog.basicConfig on py2 and indeed checking things it looks like this:
wendelin.core/D$ python --version
Python 2.7.18
wendelin.core/D$ wcfs status file://`pwd`/1.fs
Traceback (most recent call last):
File "/home/kirr/src/wendelin/venv/z-dev/bin/wcfs", line 11, in <module>
load_entry_point('wendelin.core', 'console_scripts', 'wcfs')()
File "<decorator-gen-42>", line 2, in main
File "/home/kirr/src/tools/go/pygolang/golang/__init__.py", line 166, in _goframe
return f(*argv, **kw)
File "/home/kirr/src/wendelin/wendelin.core/wcfs/__init__.py", line 1108, in main
glog.basicConfig(stream=sys.stderr, level=logging.INFO)
File "/home/kirr/src/wendelin/wendelin.core/wcfs/internal/glog.py", line 36, in basicConfig
logging.setLogRecordFactory(LogRecord)
AttributeError: 'module' object has no attribute 'setLogRecordFactory'
This happens because while py3 logging has setLogRecordFactory py2 logging does not.
-> Fix that by changing logging.LogRecord on py2 directly.
However fresh review of glog.py module reveals more problems:
On py2 there is no Formatter.formatMessage and so any logging attempt crashes with
Traceback (most recent call last):
File "/usr/lib/python2.7/logging/__init__.py", line 868, in emit
msg = self.format(record)
File "/usr/lib/python2.7/logging/__init__.py", line 741, in format
return fmt.format(record)
File "/usr/lib/python2.7/logging/__init__.py", line 469, in format
s = self._fmt % record.__dict__
KeyError: 'levelchar'
-> Fix that by moving .levelchar initialization to LogRecord constructor.
Another problem is that glog.basicConfig was ignoring level argument. This way even if the user code from wcfs was invoking it with level=logging.INFO (see f9a40d36 "wcfs: py: Switch loglevel from WARNING -> INFO for wcfs.py commands") no log messages from info level were logged.
-> Fix that by setting root's logger level as instructed.
I'm not sure how I missed all those problem when preparing original patch.
After hereby patch wcfs.py logging is hopefully back to be working properly on both py2 and py3.
/fixes e51bef0d (wcfs: py: Log with date and time present)
/cc @levin.zimmermann
/reported-by @tomo
/reported-on slapos!1815 (comment 236620)