From 096de7c4be93f65372a38cc0ec87a8bb9e947f0c Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Sat, 19 Feb 2022 15:14:23 +0100 Subject: vidhar: ... --- modules/zfssnap/default.nix | 6 +++--- modules/zfssnap/zfssnap.py | 16 +++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/modules/zfssnap/default.nix b/modules/zfssnap/default.nix index 9ff0157b..35eea776 100644 --- a/modules/zfssnap/default.nix +++ b/modules/zfssnap/default.nix @@ -11,7 +11,7 @@ let buildInputs = with pkgs; [makeWrapper]; - python = pkgs.python39.withPackages (ps: with ps; [pyxdg pytimeparse dateutil systemd]); + python = pkgs.python39.withPackages (ps: with ps; [pyxdg pytimeparse dateutil]); buildPhase = '' substitute $src zfssnap \ @@ -67,7 +67,7 @@ in { before = [ "zfssnap-prune.service" ]; serviceConfig = { Type = "oneshot"; - ExecStart = "${zfssnap}/bin/zfssnap --no-stderr -vv"; + ExecStart = "${zfssnap}/bin/zfssnap -vv"; }; }; systemd.services."zfssnap-prune" = { @@ -78,7 +78,7 @@ in { ExecStart = let mkSectionName = name: strings.escape [ "[" "]" ] (strings.toUpper name); zfssnapConfig = generators.toINI { inherit mkSectionName; } cfg.config; - in "${zfssnap}/bin/zfssnap --no-stderr -vv prune --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig}"; + in "${zfssnap}/bin/zfssnap -vv prune --config=${pkgs.writeText "zfssnap.ini" zfssnapConfig}"; }; }; diff --git a/modules/zfssnap/zfssnap.py b/modules/zfssnap/zfssnap.py index e411168c..9e8881d0 100644 --- a/modules/zfssnap/zfssnap.py +++ b/modules/zfssnap/zfssnap.py @@ -25,8 +25,6 @@ from functools import cache from math import floor -from systemd import journal - @cache def _now(): @@ -217,7 +215,11 @@ def autosnap(): def main(): global logger logger = logging.getLogger(__name__) - systemd_handler = journal.JournalHandler() + console_handler = logging.StreamHandler() + console_handler.setFormatter( logging.Formatter('[%(levelname)s](%(name)s): %(message)s') ) + if sys.stderr.isatty(): + console_handler.setFormatter( logging.Formatter('%(asctime)s [%(levelname)s](%(name)s): %(message)s') ) + logger.addHandler(console_handler) # log uncaught exceptions def log_exceptions(type, value, tb): @@ -230,7 +232,6 @@ def main(): parser = argparse.ArgumentParser(prog='zfssnap') parser.add_argument('--verbose', '-v', action='count', default=0) - parser.add_argument('--no-stderr', dest='stderr', action='store_false', default=True) subparsers = parser.add_subparsers() parser.set_defaults(cmd=autosnap) rename_parser = subparsers.add_parser('rename') @@ -242,13 +243,6 @@ def main(): prune_parser.set_defaults(cmd=prune) args = parser.parse_args() - if args.stderr: - console_handler = logging.StreamHandler() - console_handler.setFormatter( logging.Formatter('[%(levelname)s](%(name)s): %(message)s') ) - if sys.stderr.isatty(): - console_handler.setFormatter( logging.Formatter('%(asctime)s [%(levelname)s](%(name)s): %(message)s') ) - logger.addHandler(console_handler) - if args.verbose <= 0: logger.setLevel(logging.WARNING) elif args.verbose <= 1: -- cgit v1.2.3