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
Draft
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 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,25 @@ 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("{}/syslog*".format(log_path))
else:
files_to_delete = glob.glob("{}/syslog".format(log_path))
if os.path.isfile("{}/syslog.1".format(log_path))
files_to_delete += glob.glob("{}/syslog.1".format(log_path))

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

if __name__ == '__main__':
cli()