Skip to content

Commit

Permalink
Logging improvements, updated readme and some linting
Browse files Browse the repository at this point in the history
  • Loading branch information
sezanzeb committed Nov 23, 2021
1 parent ef3970f commit 70bc804
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ cd key-mapper && ./scripts/build.sh
sudo apt install ./dist/key-mapper-1.2.1.deb
```

key-mapper is now part of [Debian Testing](https://packages.debian.org/testing/key-mapper)
key-mapper is now part of [Debian Unstable](https://packages.debian.org/sid/key-mapper)

##### pip

Expand Down
9 changes: 5 additions & 4 deletions bin/key-mapper-control
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def communicate(options, daemon):

if daemon is None:
# probably broken tests
logger.error('Daemon missing', options.device)
logger.error('Daemon missing')
sys.exit(1)

if options.config_dir is not None:
Expand Down Expand Up @@ -190,7 +190,8 @@ def internals(options):
def main(options):
if options.debug:
update_verbosity(True)
add_filehandler('/var/log/key-mapper-control')

add_filehandler('/var/log/key-mapper-control')

if options.version:
log_info()
Expand All @@ -205,7 +206,7 @@ def main(options):
# of confusing service logs. And also avoids potential for problems when
# key-mapper-control stresses about evdev, dbus and multiprocessing already
# while the system hasn't even booted completely.
logger.warn('Skipping autoload command without a logged in user')
logger.warning('Skipping autoload command without a logged in user')
return

if options.command is not None:
Expand All @@ -221,7 +222,7 @@ def main(options):
utils(options)

if options.command:
logger.info('Finished')
logger.info('Done')


if __name__ == '__main__':
Expand Down
3 changes: 1 addition & 2 deletions bin/key-mapper-service
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import sys
from argparse import ArgumentParser

from keymapper.logger import update_verbosity, log_info, \
add_filehandler
from keymapper.logger import update_verbosity, log_info, add_filehandler


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion data/99-key-mapper.rules
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# sudo udevadm control --log-priority=debug
# sudo udevadm control --reload-rules
# journalctl -f
ACTION=="add", SUBSYSTEM=="input", RUN+="/bin/key-mapper-control --command autoload --device $env{DEVNAME} -d"
ACTION=="add", SUBSYSTEM=="input", RUN+="/bin/key-mapper-control --command autoload --device $env{DEVNAME}"
2 changes: 1 addition & 1 deletion keymapper/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def __init__(self):

# check privileges
if os.getuid() != 0:
logger.warn("The service usually needs elevated privileges")
logger.warning("The service usually needs elevated privileges")

self.autoload_history = AutoloadHistory()
self.refreshed_devices_at = 0
Expand Down
2 changes: 2 additions & 0 deletions keymapper/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def is_denylisted(device):
if re.match(name, str(device.name), re.IGNORECASE):
return True

return False


def get_unique_key(device):
"""Find a string key that is unique for a single hardware device.
Expand Down
2 changes: 1 addition & 1 deletion keymapper/ipc/shared_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def start(self):
def manage(self):
"""Manage the dictionary, handle read and write requests."""
logger.spam("SharedDict process started")
shared_dict = dict()
shared_dict = {}
while True:
message = self.pipe[0].recv()
logger.spam("SharedDict got %s", message)
Expand Down
8 changes: 3 additions & 5 deletions keymapper/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def format(self, record):
}.get(record.levelno, 0)

if debug:
delta = f"{str(time.time() - start)[:7]}"
delta = datetime.now().strftime("%H:%M:%S.%f")
self._style._fmt = ( # noqa
f"\033[{color}m" # color
f"{os.getpid()} "
Expand Down Expand Up @@ -195,8 +195,6 @@ def update_verbosity(debug):
# since this is optional, just skip all exceptions
if not isinstance(error, ImportError):
logger.debug("Cannot use rich.traceback: %s", error)

logger.debug("Started debug logs at: %s", str(datetime.now()))
else:
logger.setLevel(logging.INFO)

Expand All @@ -214,7 +212,7 @@ def add_filehandler(log_path=LOG_PATH):
if os.path.exists(log_path):
# the logfile should not be too long to avoid overflowing the storage
with open(log_path, "r") as file:
content = file.readlines()[-1000:] + ["\n"]
content = file.readlines()[-1000:]

with open(log_path, "w") as file:
file.truncate(0)
Expand All @@ -224,6 +222,6 @@ def add_filehandler(log_path=LOG_PATH):
file_handler.setFormatter(Formatter())
logger.addHandler(file_handler)

logger.info('Starting logging to "%s" at %s', log_path, str(datetime.now()))
logger.info('Starting logging to "%s"', log_path)
except PermissionError:
logger.debug('No permission to log to "%s"', log_path)
2 changes: 1 addition & 1 deletion keymapper/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def get_abs_range(device, code=ABS_X):
]

if len(absinfo) == 0:
logger.warn(
logger.warning(
'Failed to get ABS info of "%s" for key %d: %s', device, code, capabilities
)
return None
Expand Down
4 changes: 2 additions & 2 deletions readme/pylint.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 70bc804

Please sign in to comment.