fallback to uid when no uname (#68466)
* fallback to uid when no uname fixes #68007 Co-Authored-By: Matt Clay <matt@mystile.com>
This commit is contained in:
parent
835ad75a0a
commit
1570098e86
2 changed files with 8 additions and 1 deletions
2
changelogs/fragments/fallback_uid.yml
Normal file
2
changelogs/fragments/fallback_uid.yml
Normal file
|
@ -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…
Reference in a new issue