derek-thomas HF staff commited on
Commit
f3e3a3c
1 Parent(s): 779c2fa

Updating for better logging

Browse files
Files changed (1) hide show
  1. src/visualize_logs.py +7 -4
src/visualize_logs.py CHANGED
@@ -1,15 +1,17 @@
 
 
 
1
  from bs4 import BeautifulSoup
2
  from rich.console import Console
3
  from rich.syntax import Syntax
4
- from pathlib import Path
5
 
6
  proj_dir = Path(__file__).parents[1]
7
 
 
8
  def log_file_to_html_string():
9
- log_file = proj_dir/"mylog.log"
10
  num_lines_visualize = 50
11
 
12
- console = Console(record=True, width=150, style="#272822")
13
  with open(log_file, "rt") as f:
14
  # Seek to the end of the file minus 300 lines
15
  # Read the last 300 lines of the file
@@ -20,7 +22,8 @@ def log_file_to_html_string():
20
  output = "".join(lines)
21
  syntax = Syntax(output, "python", theme="monokai", word_wrap=True)
22
 
23
- console.print(syntax);
 
24
  html_content = console.export_html(inline_styles=True)
25
 
26
  # Parse the HTML content using BeautifulSoup
 
1
+ from io import StringIO
2
+ from pathlib import Path
3
+
4
  from bs4 import BeautifulSoup
5
  from rich.console import Console
6
  from rich.syntax import Syntax
 
7
 
8
  proj_dir = Path(__file__).parents[1]
9
 
10
+
11
  def log_file_to_html_string():
12
+ log_file = proj_dir / "mylog.log"
13
  num_lines_visualize = 50
14
 
 
15
  with open(log_file, "rt") as f:
16
  # Seek to the end of the file minus 300 lines
17
  # Read the last 300 lines of the file
 
22
  output = "".join(lines)
23
  syntax = Syntax(output, "python", theme="monokai", word_wrap=True)
24
 
25
+ console = Console(record=True, width=150, style="#272822", file=StringIO())
26
+ console.print(syntax)
27
  html_content = console.export_html(inline_styles=True)
28
 
29
  # Parse the HTML content using BeautifulSoup