Use UID in message if user name cannot be retrieved

This commit is contained in:
allegroai 2020-04-26 23:22:46 +03:00
parent 7085a2bb74
commit 6746144803

View File

@ -24,9 +24,26 @@ from ..debugging.log import get_logger
def make_message(s, **kwargs): def make_message(s, **kwargs):
# noinspection PyBroadException
try:
user = getpass.getuser()
except Exception:
# noinspection PyBroadException
try:
import os
user = '{}'.format(os.getuid())
except Exception:
user = 'unknown'
# noinspection PyBroadException
try:
host = gethostname()
except Exception:
host = 'localhost'
args = dict( args = dict(
user=getpass.getuser(), user=user,
host=gethostname(), host=host,
time=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') time=datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
) )
args.update(kwargs) args.update(kwargs)