MCPcopy Index your code
hub / github.com/blacklanternsecurity/bbot / log_table

Method log_table

bbot/modules/base.py:1508–1539  ·  view source on GitHub ↗

Logs a table to the console and optionally writes it to a file. This function generates a table using `self.helpers.make_table`, then logs each line of the table as an info-level log. If a table_name is provided, it also writes the table to a file. Args: *args:

(self, *args, **kwargs)

Source from the content-addressed store, hash-verified

1506 return self.name
1507
1508 def log_table(self, *args, **kwargs):
1509 """Logs a table to the console and optionally writes it to a file.
1510
1511 This function generates a table using `self.helpers.make_table`, then logs each line
1512 of the table as an info-level log. If a table_name is provided, it also writes the table to a file.
1513
1514 Args:
1515 *args: Variable length argument list to be passed to `self.helpers.make_table`.
1516 **kwargs: Arbitrary keyword arguments. If 'table_name' is specified, the table will be written to a file.
1517
1518 Returns:
1519 str: The generated table as a string.
1520
1521 Examples:
1522 >>> self.log_table(['Header1', 'Header2'], [['row1col1', 'row1col2'], ['row2col1', 'row2col2']], table_name="my_table")
1523 """
1524 table_name = kwargs.pop("table_name", None)
1525 max_log_entries = kwargs.pop("max_log_entries", None)
1526 table = self.helpers.make_table(*args, **kwargs)
1527 lines_logged = 0
1528 for line in table.splitlines():
1529 if max_log_entries is not None and lines_logged > max_log_entries:
1530 break
1531 self.info(line)
1532 lines_logged += 1
1533 if table_name is not None:
1534 date = self.helpers.make_date()
1535 filename = self.scan.home / f"{self.helpers.tagify(table_name)}-table-{date}.txt"
1536 with open(filename, "w") as f:
1537 f.write(table)
1538 self.verbose(f"Wrote {table_name} to {filename}")
1539 return table
1540
1541 def _is_graph_important(self, event):
1542 return self.preserve_graph and getattr(event, "_graph_important", False) and not getattr(event, "_omit", False)

Callers 4

reportMethod · 0.80
reportMethod · 0.80
reportMethod · 0.80
reportMethod · 0.80

Calls 4

infoMethod · 0.95
verboseMethod · 0.95
openFunction · 0.85
popMethod · 0.80

Tested by

no test coverage detected