Renders the iterator of log events into text or html.
(log_events, color=False, html=False)
| 128 | print("File %s could not be opened. Continuing without it." % logfile, file=sys.stderr) |
| 129 | |
| 130 | def print_logs(log_events, color=False, html=False): |
| 131 | """Renders the iterator of log events into text or html.""" |
| 132 | if not html: |
| 133 | colors = defaultdict(lambda: '') |
| 134 | if color: |
| 135 | colors["test"] = "\033[0;36m" # CYAN |
| 136 | colors["node0"] = "\033[0;34m" # BLUE |
| 137 | colors["node1"] = "\033[0;32m" # GREEN |
| 138 | colors["node2"] = "\033[0;31m" # RED |
| 139 | colors["node3"] = "\033[0;33m" # YELLOW |
| 140 | colors["reset"] = "\033[0m" # Reset font color |
| 141 | |
| 142 | for event in log_events: |
| 143 | lines = event.event.splitlines() |
| 144 | print("{0} {1: <5} {2} {3}".format(colors[event.source.rstrip()], event.source, lines[0], colors["reset"])) |
| 145 | if len(lines) > 1: |
| 146 | for line in lines[1:]: |
| 147 | print("{0}{1}{2}".format(colors[event.source.rstrip()], line, colors["reset"])) |
| 148 | |
| 149 | else: |
| 150 | try: |
| 151 | import jinja2 |
| 152 | except ImportError: |
| 153 | print("jinja2 not found. Try `pip install jinja2`") |
| 154 | sys.exit(1) |
| 155 | print(jinja2.Environment(loader=jinja2.FileSystemLoader('./')) |
| 156 | .get_template('combined_log_template.html') |
| 157 | .render(title="Combined Logs from testcase", log_events=[event._asdict() for event in log_events])) |
| 158 | |
| 159 | if __name__ == '__main__': |
| 160 | main() |