fallback to uid when no uname (#68466)

* fallback to uid when no uname

 fixes #68007

Co-Authored-By: Matt Clay <matt@mystile.com>
(cherry picked from commit 1570098e86)
pull/68620/merge
Brian Coca 5 years ago committed by Matt Clay
parent 8088ffb853
commit 52d509717e

@ -0,0 +1,2 @@
bugfixes:
- 'for those running uids for invalid users (containers), fallback to uid=<uid> when logging fixes #68007'

@ -62,7 +62,12 @@ class FilterUserInjector(logging.Filter):
This is a filter which injects the current user as the 'user' attribute on each record. We need to add this filter
to all logger handlers so that 3rd party libraries won't print an exception due to user not being defined.
"""
username = getpass.getuser()
try:
username = getpass.getuser()
except KeyError:
# people like to make containers w/o actual valid passwd/shadow and use host uids
username = 'uid=%s' % os.getuid()
def filter(self, record):
record.user = FilterUserInjector.username

Loading…
Cancel
Save