fallback to uid when no uname (#68466)

* fallback to uid when no uname

 fixes #68007

Co-Authored-By: Matt Clay <matt@mystile.com>
pull/68531/head
Brian Coca 5 years ago committed by GitHub
parent 835ad75a0a
commit 1570098e86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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