Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reduce logging level #13

Open
vladns opened this issue Dec 21, 2023 · 1 comment
Open

How to reduce logging level #13

vladns opened this issue Dec 21, 2023 · 1 comment

Comments

@vladns
Copy link

vladns commented Dec 21, 2023

The log is filled with messages like these:

дек 21 22:51:15 home-nas afancontrol[654]: ВНИМАНИЕ: (см. опции --help, --debug и --drivebase).
дек 21 22:51:15 home-nas afancontrol[654]: /dev/sdf: SPCC Solid State Disk:  нет датчика
дек 21 22:51:20 home-nas afancontrol[654]: WARNING:afancontrol:Shell command '/usr/bin/hddtemp -n -u C -- /dev/sd?' execute>
дек 21 22:51:20 home-nas afancontrol[654]: ВНИМАНИЕ: Диск /dev/sdf не дает показания температурного датчика.
дек 21 22:51:20 home-nas afancontrol[654]: ВНИМАНИЕ: Это еще не значит, что у него его нет.
дек 21 22:51:20 home-nas afancontrol[654]: ВНИМАНИЕ: Если вы точно знаете, что датчик есть, напишите [email protected]
дек 21 22:51:20 home-nas afancontrol[654]: ВНИМАНИЕ: (см. опции --help, --debug и --drivebase).
дек 21 22:51:20 home-nas afancontrol[654]: /dev/sdf: SPCC Solid State Disk:  нет датчика
дек 21 22:51:25 home-nas afancontrol[654]: WARNING:afancontrol:Shell command '/usr/bin/hddtemp -n -u C -- /dev/sd?' execute>
дек 21 22:51:25 home-nas afancontrol[654]: ВНИМАНИЕ: Диск /dev/sdf не дает показания температурного датчика.
дек 21 22:51:25 home-nas afancontrol[654]: ВНИМАНИЕ: Это еще не значит, что у него его нет.
дек 21 22:51:25 home-nas afancontrol[654]: ВНИМАНИЕ: Если вы точно знаете, что датчик есть, напишите [email protected]
дек 21 22:51:25 home-nas afancontrol[654]: ВНИМАНИЕ: (см. опции --help, --debug и --drivebase).
дек 21 22:51:25 home-nas afancontrol[654]: /dev/sdf: SPCC Solid State Disk:  нет датчика
дек 21 22:51:30 home-nas afancontrol[654]: WARNING:afancontrol:Shell command '/usr/bin/hddtemp -n -u C -- /dev/sd?' execute>
дек 21 22:51:30 home-nas afancontrol[654]: ВНИМАНИЕ: Диск /dev/sdf не дает показания температурного датчика.
дек 21 22:51:30 home-nas afancontrol[654]: ВНИМАНИЕ: Это еще не значит, что у него его нет.
дек 21 22:51:30 home-nas afancontrol[654]: ВНИМАНИЕ: Если вы точно знаете, что датчик есть, напишите [email protected]
дек 21 22:51:30 home-nas afancontrol[654]: ВНИМАНИЕ: (см. опции --help, --debug и --drivebase).
дек 21 22:51:30 home-nas afancontrol[654]: /dev/sdf: SPCC Solid State Disk:  нет датчика
дек 21 22:51:35 home-nas afancontrol[654]: WARNING:afancontrol:Shell command '/usr/bin/hddtemp -n -u C -- /dev/sd?' execute>
дек 21 22:51:35 home-nas afancontrol[654]: ВНИМАНИЕ: Диск /dev/sdf не дает показания температурного датчика.
дек 21 22:51:35 home-nas afancontrol[654]: ВНИМАНИЕ: Это еще не значит, что у него его нет.
дек 21 22:51:35 home-nas afancontrol[654]: ВНИМАНИЕ: Если вы точно знаете, что датчик есть, напишите [email protected]
дек 21 22:51:35 home-nas afancontrol[654]: ВНИМАНИЕ: (см. опции --help, --debug и --drivebase).
дек 21 22:51:35 home-nas afancontrol[654]: /dev/sdf: SPCC Solid State Disk:  нет датчика
дек 21 22:51:40 home-nas afancontrol[654]: WARNING:afancontrol:Shell command '/usr/bin/hddtemp -n -u C -- /dev/sd?' execute>
дек 21 22:51:40 home-nas afancontrol[654]: ВНИМАНИЕ: Диск /dev/sdf не дает показания температурного датчика.
дек 21 22:51:40 home-nas afancontrol[654]: ВНИМАНИЕ: Это еще не значит, что у него его нет.
дек 21 22:51:40 home-nas afancontrol[654]: ВНИМАНИЕ: Если вы точно знаете, что датчик есть, напишите [email protected]
дек 21 22:51:40 home-nas afancontrol[654]: ВНИМАНИЕ: (см. опции --help, --debug и --drivebase).
дек 21 22:51:40 home-nas afancontrol[654]: /dev/sdf: SPCC Solid State Disk:  нет датчика

If you comment out the option “logfile = /var/log/afancontrol.log”, it stops writing to this file, but still writes to the system log.

@KostyaEsmukov
Copy link
Owner

I may suggest you the following options:

  1. You may try adding the hddtemp's --quiet option, like this, although I'm not sure that it would work in this case:
    diff --git a/src/afancontrol/temp/hdd.py b/src/afancontrol/temp/hdd.py
    index b554959..1cdfba7 100644
    --- a/src/afancontrol/temp/hdd.py
    +++ b/src/afancontrol/temp/hdd.py
    @@ -98,5 +98,5 @@ class HDDTemp(Temp):
     
         def _call_hddtemp(self) -> str:
             # `disk_path` might be a glob, so it has to be executed with a shell.
    -        shell_command = "%s -n -u C -- %s" % (self._hddtemp_bin, self._disk_path)
    +        shell_command = "%s --quiet -n -u C -- %s" % (self._hddtemp_bin, self._disk_path)
             return exec_shell_command(shell_command, timeout=10)
    
  2. You may prepare your own little script collecting the disk temperatures (which wouldn't produce the noisy output) and use that with type = exec kind of temperature config instead of type = hdd.
  3. You may opt for ignoring the stderr output from all child commands completely:
    diff --git a/src/afancontrol/exec.py b/src/afancontrol/exec.py
    index 482541f..325fac7 100644
    --- a/src/afancontrol/exec.py
    +++ b/src/afancontrol/exec.py
    @@ -29,12 +29,12 @@ def exec_shell_command(shell_command: str, timeout: int = 5) -> str:
             )
             out = p.stdout.decode("ascii")
             err = p.stderr.decode().strip()
    -        if err:
    -            logger.warning(
    -                "Shell command '%s' executed successfully, but printed to stderr:\n%s",
    -                shell_command,
    -                err,
    -            )
    +        # if err:
    +        #     logger.warning(
    +        #         "Shell command '%s' executed successfully, but printed to stderr:\n%s",
    +        #         shell_command,
    +        #         err,
    +        #     )
             return out
         except subprocess.CalledProcessError as e:
             ec = e.returncode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants