35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
from django.core.management.base import BaseCommand, CommandError
|
|
from logtracker.journal.models import Entry
|
|
import os
|
|
import textwrap
|
|
|
|
|
|
def bold(txt):
|
|
bold = "\033[1m"
|
|
end = "\033[0m"
|
|
return bold + txt + end
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Print entries"
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument("--full", action="store_true")
|
|
parser.add_argument("-n", "--lines", default=100)
|
|
|
|
def handle(self, *args, **options):
|
|
_, columns = os.popen("stty size", "r").read().split()
|
|
for entry in Entry.objects.dump(lines=options['lines']):
|
|
line = "%s %s %s %s" % (
|
|
entry.timestamp.astimezone().strftime("%b %d %X"),
|
|
entry.host,
|
|
entry.unit,
|
|
entry.data.get("MESSAGE"),
|
|
)
|
|
priority = entry.data.get("PRIORITY")
|
|
if not options.get("full"):
|
|
line = textwrap.shorten(line, int(columns))
|
|
if priority and int(priority) < 4:
|
|
line = bold(line)
|
|
print(line)
|