Skip to content

Commit

Permalink
Add signal handler to change debug level. (sonic-net#96)
Browse files Browse the repository at this point in the history
* 	[sonic_ax_impl/__main__.py]: Add signal handler to change debug level.
    Today, We can not alter the log level of already running snmp-subagent.
    Adding a signal handler for signal SIGUSR1 to switch log level for both
    sonic_ax_impl and ax_interface logger.
* [README.md]: Updated the doc for snmp_subagent_signal_handler.
  • Loading branch information
Praveen Chaudhary authored and qiluo-msft committed Jul 19, 2019
1 parent 9a4edea commit 7b8b377
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,17 @@ To run the daemon:
$ python3.5 -m sonic_ax_impl [-d 10]
```


To switch log level of already running snmp-subagent process

1.) Find PID of the process.

```
root 42 1 12 06:37 ? 01:23:46 python3.6 -m sonic_ax_impl
```

2.) Send SIGUSR1 signal to Process
```
root@lnos-x1-a-csw04:/# kill -SIGUSR1 42
```
Sending SIGUSR1 signal to process again will reset the log level.
16 changes: 16 additions & 0 deletions src/sonic_ax_impl/__main__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from signal import signal, SIGUSR1
import logging.handlers
import os
import shutil
Expand All @@ -11,6 +12,21 @@

LOG_FORMAT = "snmp-subagent [%(name)s] %(levelname)s: %(message)s"

# set signal handlers to switch log level
def signal_handler_sigusr1(signal, frame):
# set log level to debug or revert if set already
if sonic_ax_impl.logger.getEffectiveLevel() != logging.DEBUG:
sonic_ax_impl.logger.info("signal_handler_sigusr1(): Setting logger level to debug")
sonic_ax_impl.logger.setLevel(logging.DEBUG)
ax_interface.logger.setLevel(logging.DEBUG)
else:
sonic_ax_impl.logger.info("signal_handler_sigusr1(): Revert logger level to info")
sonic_ax_impl.logger.setLevel(logging.INFO)
ax_interface.logger.setLevel(logging.INFO)
return

signal(SIGUSR1, signal_handler_sigusr1)
# end signal handlers

def install_file(src_filename, dest_dir, executable=False):
dest_file = shutil.copy(src_filename, dest_dir)
Expand Down

0 comments on commit 7b8b377

Please sign in to comment.