зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1016916 - Add a 'structlog format' command for formatting logfiles, r=wlach
This replaces the __main__ sections in the formatters
This commit is contained in:
Родитель
557fbefc57
Коммит
104b8ea183
|
@ -159,9 +159,3 @@ class HTMLFormatter(base.BaseFormatter):
|
|||
html.tbody(self.result_rows, id='results-table-body')], id='results-table'))))
|
||||
|
||||
return doc.unicode(indent=2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
base.format_file(sys.stdin,
|
||||
handlers.StreamHandler(stream=sys.stdout,
|
||||
formatter=HTMLFormatter()))
|
||||
|
|
|
@ -170,8 +170,3 @@ class MachTerminalFormatter(BaseMachFormatter):
|
|||
result = s
|
||||
|
||||
return result
|
||||
|
||||
if __name__ == "__main__":
|
||||
base.format_file(sys.stdin,
|
||||
handlers.StreamHandler(stream=sys.stdout,
|
||||
formatter=MachFormatter()))
|
||||
|
|
|
@ -60,8 +60,3 @@ class UnittestFormatter(base.BaseFormatter):
|
|||
def output_summary(self):
|
||||
return ("Ran %i tests in %.1fs" % (self.tests_run,
|
||||
(self.end_time - self.start_time) / 1000))
|
||||
|
||||
if __name__ == "__main__":
|
||||
base.format_file(sys.stdin,
|
||||
handlers.StreamHandler(stream=sys.stdout,
|
||||
formatter=UnittestFormatter()))
|
||||
|
|
|
@ -95,8 +95,3 @@ class XUnitFormatter(base.BaseFormatter):
|
|||
"time": "%.2f" % (
|
||||
(data["time"] - self.suite_start_time) / 1000)})
|
||||
return ElementTree.tostring(self.root, encoding="utf8")
|
||||
|
||||
if __name__ == "__main__":
|
||||
base.format_file(sys.stdin,
|
||||
handlers.StreamHandler(stream=sys.stdout,
|
||||
formatter=XUnitFormatter()))
|
||||
|
|
|
@ -2,12 +2,14 @@
|
|||
|
||||
import argparse
|
||||
import unstable
|
||||
import format as formatlog
|
||||
|
||||
def get_parser():
|
||||
parser = argparse.ArgumentParser("structlog",
|
||||
description="Tools for dealing with structured logs")
|
||||
|
||||
commands = {"unstable": (unstable.get_parser, unstable.main)}
|
||||
commands = {"unstable": (unstable.get_parser, unstable.main),
|
||||
"format": (formatlog.get_parser, formatlog.main)}
|
||||
|
||||
sub_parser = parser.add_subparsers(title='Subcommands')
|
||||
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
import argparse
|
||||
import sys
|
||||
|
||||
from .. import handlers, commandline, reader
|
||||
|
||||
def get_parser(add_help=True):
|
||||
parser = argparse.ArgumentParser("format",
|
||||
description="Format a structured log stream", add_help=add_help)
|
||||
parser.add_argument("--input", action="store", default=None,
|
||||
help="Filename to read from, defaults to stdin")
|
||||
parser.add_argument("--output", action="store", default=None,
|
||||
help="Filename to write to, defaults to stdout")
|
||||
parser.add_argument("format", choices=commandline.log_formatters.keys(),
|
||||
help="Format to use")
|
||||
return parser
|
||||
|
||||
def main(**kwargs):
|
||||
if kwargs["input"] is None:
|
||||
input_file = sys.stdin
|
||||
else:
|
||||
input_file = open(kwargs["input"])
|
||||
if kwargs["output"] is None:
|
||||
output_file = sys.stdout
|
||||
else:
|
||||
output_file = open(kwargs["output"], "w")
|
||||
|
||||
formatter = commandline.log_formatters[kwargs["format"]][0]()
|
||||
|
||||
handler = handlers.StreamHandler(stream=output_file,
|
||||
formatter=formatter)
|
||||
|
||||
for data in reader.read(input_file):
|
||||
handler(data)
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = get_parser()
|
||||
args = parser.parse_args()
|
||||
kwargs = vars(args)
|
||||
main(**kwargs)
|
Загрузка…
Ссылка в новой задаче