Write the flow to the stream, but first check if we need to rotate to a new file.
(self, flow: flow.Flow)
| 102 | self.current_path = path |
| 103 | |
| 104 | def save_flow(self, flow: flow.Flow) -> None: |
| 105 | """ |
| 106 | Write the flow to the stream, but first check if we need to rotate to a new file. |
| 107 | """ |
| 108 | if not self.stream: |
| 109 | return |
| 110 | try: |
| 111 | self.maybe_rotate_to_new_file() |
| 112 | self.stream.add(flow) |
| 113 | except OSError as e: |
| 114 | # If we somehow fail to write flows to a logfile, we really want to crash visibly |
| 115 | # instead of letting traffic through unrecorded. |
| 116 | # No normal logging here, that would not be triggered anymore. |
| 117 | sys.stderr.write(f"Error while writing to {self.current_path}: {e}") |
| 118 | sys.exit(1) |
| 119 | else: |
| 120 | self.active_flows.discard(flow) |
| 121 | |
| 122 | def done(self) -> None: |
| 123 | if self.stream: |
no test coverage detected