Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from django.conf import settings 

2from django.core.management.base import BaseCommand, CommandParser 

3 

4 

5class Command(BaseCommand): 

6 help = ( 

7 "Simple Django log filter. " 

8 "Finds match and then show the line contents following the matched string." 

9 "Use grep for more complex regular expression matching." 

10 ) 

11 

12 def add_arguments(self, parser: CommandParser): 

13 parser.add_argument("content", type=str) 

14 parser.add_argument("--file", type=str) 

15 

16 def handle(self, *args, **kwargs): 

17 content = kwargs["content"] 

18 file = kwargs["file"] or settings.LOGGING.get("handlers", {}).get("file", {}).get("filename", "") 

19 if not file: 

20 raise Exception("Specify --file or make sure settings.LOGGING['handlers']['file']['filename'] is set") 

21 

22 content_len = len(content) 

23 with open(file, "rt") as fp: 

24 line = fp.readline() 

25 while line: 

26 i = line.find(content) 

27 if i >= 0: 

28 rest = line[i + content_len :].lstrip() 

29 self.stdout.write(rest) 

30 line = fp.readline()