4
4
import shlex
5
5
import shutil
6
6
import tempfile
7
+ from enum import Enum
7
8
from typing import Any , List , Optional , Set , Type
8
9
9
10
from loguru import logger
18
19
)
19
20
20
21
22
+ class TLogCondition (str , Enum ):
23
+ """When to write tlog files."""
24
+
25
+ Always = "always"
26
+ WhileArmed = "while_armed"
27
+
28
+
21
29
class AbstractRouter (metaclass = abc .ABCMeta ):
22
30
def __init__ (self ) -> None :
23
31
self ._endpoints : Set [Endpoint ] = set ()
@@ -28,6 +36,7 @@ def __init__(self) -> None:
28
36
# to avoid any problem in __del__
29
37
self ._binary = shutil .which (self .binary_name ())
30
38
self ._logdir = pathlib .Path (tempfile .gettempdir ())
39
+ self ._tlog_condition = TLogCondition .WhileArmed
31
40
self ._version = self ._get_version ()
32
41
33
42
@staticmethod
@@ -182,6 +191,12 @@ def set_logdir(self, directory: pathlib.Path) -> None:
182
191
raise ValueError (f"Logging directory { directory } does not exist." )
183
192
self ._logdir = directory
184
193
194
+ def tlog_condition (self ) -> TLogCondition :
195
+ return self ._tlog_condition
196
+
197
+ def set_tlog_condition (self , tlog_condition : TLogCondition ) -> None :
198
+ self ._tlog_condition = tlog_condition
199
+
185
200
def add_endpoint (self , endpoint : Endpoint ) -> None :
186
201
self ._validate_endpoint (endpoint )
187
202
0 commit comments