diff options
author | Kali Kaneko (leap communications) <kali@leap.se> | 2016-10-05 12:18:02 -0400 |
---|---|---|
committer | Kali Kaneko (leap communications) <kali@leap.se> | 2016-10-07 10:22:36 -0400 |
commit | 4a471fb8b434d3df07c5de42fc41590b5d9fc5f5 (patch) | |
tree | ca72e66088ac8fea08c74e80405006afa66788c5 /src/leap/bitmask/cli/logs.py | |
parent | 01ff6420b503ed98cc04f295fec1d803d31b97fb (diff) |
[feature] logs watch command
Diffstat (limited to 'src/leap/bitmask/cli/logs.py')
-rw-r--r-- | src/leap/bitmask/cli/logs.py | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/src/leap/bitmask/cli/logs.py b/src/leap/bitmask/cli/logs.py index 59ed64d..0976ebc 100644 --- a/src/leap/bitmask/cli/logs.py +++ b/src/leap/bitmask/cli/logs.py @@ -21,6 +21,7 @@ import argparse import commands import os.path import sys +import time from colorama import Fore @@ -39,6 +40,7 @@ Bitmask Log Handling SUBCOMMANDS: send Send last bitmaskd log + watch Display logs stream '''.format(name=command.appname) def send(self, raw_args): @@ -46,14 +48,34 @@ SUBCOMMANDS: if not _bin: error('pastebinit not found. install it to upload logs.') return defer.succeed(None) - log_path = os.path.abspath( - os.path.join(get_path_prefix(), 'leap', 'bitmaskd.log')) output = commands.getoutput('{0} -b {1} {2}'.format( - _bin[0], 'paste.debian.net', log_path)) + _bin[0], 'paste.debian.net', _log_path)) uri = output.replace('debian.net/', 'debian.net/plain/') success(uri) return defer.succeed(None) + def watch(self, raw_args): + def tail(_file): + _file.seek(0,2) # Go to the end of the file + while True: + line = _file.readline() + if not line: + time.sleep(0.1) + continue + yield line + + _file = open(_log_path, 'r') + print (Fore.GREEN + '[bitmask] ' + + Fore.RESET + 'Watching log file %s' % _log_path ) + for line in _file.readlines(): + print line, + for line in tail(_file): + print line, + + +_log_path = os.path.abspath( + os.path.join(get_path_prefix(), 'leap', 'bitmaskd.log')) + def error(msg): print Fore.RED + msg + Fore.RESET |