Skip to content

Add Command sonic-clear logging #1

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

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
21 changes: 21 additions & 0 deletions clear/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import sys
import click
import glob
import utilities_common.cli as clicommon
import utilities_common.multi_asic as multi_asic_util
from sonic_py_common.general import getstatusoutput_noshell_pipe
Expand Down Expand Up @@ -550,6 +551,26 @@ def route(prefix, vrf, namespace):
helper = util_base.UtilHelper()
helper.load_and_register_plugins(plugins, cli)

@click.option('--all', '-a', is_flag=True, help='Delete also compressed logs')
@cli.command()
def logging(all):
"""Clear logging files"""
if os.path.exists("/var/log.tmpfs"):
log_path = "/var/log.tmpfs"
else:
log_path = "/var/log"

if all:
files_to_delete = glob.glob(f"{log_path}/syslog*")
else:
files_to_delete = [f"{log_path}/syslog"]

if os.path.isfile(f"{log_path}/syslog.1"):
files_to_delete += [f"{log_path}/syslog.1"]

for f in files_to_delete:
cmd = ['sudo', 'rm','-f',f]
run_command(cmd)

if __name__ == '__main__':
cli()