Merge remote-tracking branch 'origin/pr/386'
* origin/pr/386: log: don't write to qubes.log or vm-*.log, only stderr log: remove unused DBusHandler log: avoid qubesd restart on logrotate log: remove orphaned LOGFILE variable
This commit is contained in:
commit
0605a1197a
@ -5,15 +5,3 @@
|
|||||||
/bin/systemctl restart qubes-qmemman.service >/dev/null 2>/dev/null || true
|
/bin/systemctl restart qubes-qmemman.service >/dev/null 2>/dev/null || true
|
||||||
endscript
|
endscript
|
||||||
}
|
}
|
||||||
|
|
||||||
/var/log/qubes/qubes.log {
|
|
||||||
create 0640 root qubes
|
|
||||||
su root qubes
|
|
||||||
postrotate
|
|
||||||
/bin/systemctl restart qubesd.service >/dev/null 2>/dev/null || true
|
|
||||||
endscript
|
|
||||||
}
|
|
||||||
|
|
||||||
/var/log/qubes/vm-*.log {
|
|
||||||
su root qubes
|
|
||||||
}
|
|
||||||
|
@ -1486,7 +1486,7 @@ class Qubes(qubes.PropertyHolder):
|
|||||||
raise qubes.exc.QubesVMInUseError(
|
raise qubes.exc.QubesVMInUseError(
|
||||||
vm,
|
vm,
|
||||||
'Domain is in use: {!r};'
|
'Domain is in use: {!r};'
|
||||||
'see /var/log/qubes/qubes.log in dom0 for '
|
"see 'journalctl -u qubesd -e' in dom0 for "
|
||||||
'details'.format(
|
'details'.format(
|
||||||
vm.name))
|
vm.name))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
95
qubes/log.py
95
qubes/log.py
@ -24,58 +24,23 @@ See also: :py:attr:`qubes.vm.qubesvm.QubesVM.log`
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
|
||||||
import sys
|
import sys
|
||||||
import fcntl
|
|
||||||
|
|
||||||
import dbus
|
|
||||||
|
|
||||||
FORMAT_CONSOLE = '%(message)s'
|
class Formatter(logging.Formatter):
|
||||||
FORMAT_LOG = '%(asctime)s %(message)s'
|
def __init__(self, *args, debug=False, **kwargs):
|
||||||
FORMAT_DEBUG = '%(asctime)s ' \
|
|
||||||
'[%(processName)s %(module)s.%(funcName)s:%(lineno)d] %(name)s: %(message)s'
|
|
||||||
LOGPATH = '/var/log/qubes'
|
|
||||||
LOGFILE = os.path.join(LOGPATH, 'qubes.log')
|
|
||||||
|
|
||||||
formatter_console = logging.Formatter(FORMAT_CONSOLE)
|
|
||||||
formatter_log = logging.Formatter(FORMAT_LOG)
|
|
||||||
formatter_debug = logging.Formatter(FORMAT_DEBUG)
|
|
||||||
|
|
||||||
class DBusHandler(logging.Handler):
|
|
||||||
'''Handler which displays records as DBus notifications'''
|
|
||||||
|
|
||||||
#: mapping of loglevels to icons
|
|
||||||
app_icons = {
|
|
||||||
logging.ERROR: 'dialog-error',
|
|
||||||
logging.WARNING: 'dialog-warning',
|
|
||||||
logging.NOTSET: 'dialog-information',
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
self.debug = debug
|
||||||
|
|
||||||
self._notify_object = dbus.SessionBus().get_object(
|
def formatMessage(self, record):
|
||||||
'org.freedesktop.Notifications', '/org/freedesktop/Notifications')
|
fmt = ''
|
||||||
|
if self.debug:
|
||||||
|
fmt += '[%(processName)s %(module)s.%(funcName)s:%(lineno)d] '
|
||||||
|
if self.debug or record.name.startswith('vm.'):
|
||||||
|
fmt += '%(name)s: '
|
||||||
|
fmt += '%(message)s'
|
||||||
|
|
||||||
|
return fmt % record.__dict__
|
||||||
def emit(self, record):
|
|
||||||
app_icon = self.app_icons[
|
|
||||||
max(level for level in self.app_icons if level <= record.levelno)]
|
|
||||||
|
|
||||||
try:
|
|
||||||
# https://developer.gnome.org/notification-spec/#command-notify
|
|
||||||
self._notify_object.Notify(
|
|
||||||
'Qubes', # STRING app_name
|
|
||||||
0, # UINT32 replaces_id
|
|
||||||
app_icon, # STRING app_icon
|
|
||||||
record.msg, # STRING summary
|
|
||||||
'', # STRING body
|
|
||||||
(), # ARRAY actions
|
|
||||||
{}, # DICT hints
|
|
||||||
0, # INT32 timeout
|
|
||||||
dbus_interface='org.freedesktop.Notifications')
|
|
||||||
except dbus.DBusException:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def enable():
|
def enable():
|
||||||
@ -93,24 +58,9 @@ def enable():
|
|||||||
return
|
return
|
||||||
|
|
||||||
handler_console = logging.StreamHandler(sys.stderr)
|
handler_console = logging.StreamHandler(sys.stderr)
|
||||||
handler_console.setFormatter(formatter_console)
|
handler_console.setFormatter(Formatter())
|
||||||
logging.root.addHandler(handler_console)
|
logging.root.addHandler(handler_console)
|
||||||
|
|
||||||
if os.path.exists('/var/log/qubes'):
|
|
||||||
log_path = '/var/log/qubes/qubes.log'
|
|
||||||
else:
|
|
||||||
# for tests, travis etc
|
|
||||||
log_path = '/tmp/qubes.log'
|
|
||||||
old_umask = os.umask(0o007)
|
|
||||||
try:
|
|
||||||
handler_log = logging.FileHandler(log_path, 'a', encoding='utf-8')
|
|
||||||
fcntl.fcntl(handler_log.stream.fileno(),
|
|
||||||
fcntl.F_SETFD, fcntl.FD_CLOEXEC)
|
|
||||||
finally:
|
|
||||||
os.umask(old_umask)
|
|
||||||
handler_log.setFormatter(formatter_log)
|
|
||||||
logging.root.addHandler(handler_log)
|
|
||||||
|
|
||||||
logging.root.setLevel(logging.INFO)
|
logging.root.setLevel(logging.INFO)
|
||||||
|
|
||||||
def enable_debug():
|
def enable_debug():
|
||||||
@ -120,10 +70,11 @@ def enable_debug():
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
enable()
|
enable()
|
||||||
logging.root.setLevel(logging.DEBUG)
|
|
||||||
|
|
||||||
for handler in logging.root.handlers:
|
for handler in logging.root.handlers:
|
||||||
handler.setFormatter(formatter_debug)
|
handler.setFormatter(Formatter(debug=True))
|
||||||
|
|
||||||
|
logging.root.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
def get_vm_logger(vmname):
|
def get_vm_logger(vmname):
|
||||||
'''Initialise logging for particular VM name
|
'''Initialise logging for particular VM name
|
||||||
@ -132,18 +83,4 @@ def get_vm_logger(vmname):
|
|||||||
:rtype: :py:class:`logging.Logger`
|
:rtype: :py:class:`logging.Logger`
|
||||||
'''
|
'''
|
||||||
|
|
||||||
logger = logging.getLogger('vm.' + vmname)
|
return logging.getLogger('vm.' + vmname)
|
||||||
if logger.handlers:
|
|
||||||
return logger
|
|
||||||
old_umask = os.umask(0o007)
|
|
||||||
try:
|
|
||||||
handler = logging.FileHandler(
|
|
||||||
os.path.join(LOGPATH, 'vm-{}.log'.format(vmname)))
|
|
||||||
fcntl.fcntl(handler.stream.fileno(),
|
|
||||||
fcntl.F_SETFD, fcntl.FD_CLOEXEC)
|
|
||||||
finally:
|
|
||||||
os.umask(old_umask)
|
|
||||||
handler.setFormatter(formatter_log)
|
|
||||||
logger.addHandler(handler)
|
|
||||||
|
|
||||||
return logger
|
|
||||||
|
@ -105,8 +105,6 @@ try:
|
|||||||
in_git = subprocess.check_output(
|
in_git = subprocess.check_output(
|
||||||
['git', 'rev-parse', '--show-toplevel'], stderr=subprocess.DEVNULL
|
['git', 'rev-parse', '--show-toplevel'], stderr=subprocess.DEVNULL
|
||||||
).decode().strip()
|
).decode().strip()
|
||||||
qubes.log.LOGPATH = '/tmp'
|
|
||||||
qubes.log.LOGFILE = '/tmp/qubes.log'
|
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
# git returned nonzero, we are outside git repo
|
# git returned nonzero, we are outside git repo
|
||||||
pass
|
pass
|
||||||
|
Loading…
Reference in New Issue
Block a user