diff --git a/confluent_client/bin/nodeconsole b/confluent_client/bin/nodeconsole index 4dc0d5f4..a7f5a501 100755 --- a/confluent_client/bin/nodeconsole +++ b/confluent_client/bin/nodeconsole @@ -42,6 +42,10 @@ argparser.add_option('-t', '--tile', action='store_true', default=False, help='Tile console windows in the terminal') argparser.add_option('-l', '--log', action='store_true', default=False, help='Enter log replay mode instead of showing a live console') + +argparser.add_option('-d', '--dump', action='store_true', default=False, + help= 'Dump log in stdout with timestamps') + argparser.add_option('-w','--windowed', action='store_true', default=False, help='Open terminal windows for each node. The ' 'environment variable NODECONSOLE_WINDOWED_COMMAND ' @@ -92,6 +96,16 @@ if options.log: logreader.replay_to_console(logname) sys.exit(0) +if options.dump: + logname = args[0] + if not os.path.exists(logname) and logname[0] != '/': + logname = os.path.join('/var/log/confluent/consoles', logname) + if not os.path.exists(logname): + sys.stderr.write('Unable to locate {0} on local system\n'.format(logname)) + sys.exit(1) + logreader.dump_to_console(logname) + sys.exit(0) + def kill(noderange): sess = client.Command() envstring=os.environ.get('NODECONSOLE_WINDOWED_COMMAND') diff --git a/confluent_client/confluent/logreader.py b/confluent_client/confluent/logreader.py index 5bb14892..d1a86fa3 100644 --- a/confluent_client/confluent/logreader.py +++ b/confluent_client/confluent/logreader.py @@ -296,5 +296,47 @@ def replay_to_console(txtfile): sys.exit(1) _replay_to_console(txtfile, binfile) +def dump_to_console(txtfile): + if os.path.exists(txtfile + '.cbl'): + binfile = txtfile + '.cbl' + elif '.' not in txtfile: + if '/' not in txtfile: + txtfile = os.getcwd() + '/' + txtfile + sys.stderr.write('Unable to locate cbl file: "{0}"\n'.format(txtfile + '.cbl')) + sys.exit(1) + else: + fileparts = txtfile.split('.') + prefix = '.'.join(fileparts[:-1]) + binfile = prefix + '.cbl.' + fileparts[-1] + if not os.path.exists(binfile): + sys.stderr.write('Unable to locate cbl file: "{0}"\n'.format(binfile)) + sys.exit(1) + replay = LogReplay(txtfile, binfile) + quitit = False + writeout('\x1b[2J\x1b[;H') + prepend = '' + try: + while not quitit: + newdata, delay = replay.get_output(False) + if newdata: + if prepend: + newdata = prepend + newdata + prepend = b'' + writeout(newdata.replace(b'\r\n', '\r\n[ {0} ] '.format(time.strftime('%m/%d %H:%M:%S', time.localtime(replay.laststamp))).encode('utf8'))) + newdata = '' + try: + if hasattr(sys.stdout, 'buffer'): + sys.stdout.buffer.flush() + else: + sys.stdout.flush() + except IOError: + pass + else: + break + except Exception: + writeout('\x1b[m\x1b[?25h\n') + raise + writeout('\x1b[m\x1b[?25h\n') + if __name__ == '__main__': replay_to_console(sys.argv[1])