@@ -196,18 +196,21 @@ class LogHandlerConf:
196196 """Dataclass that holds the various streams and relevant handlers.
197197
198198 Attributes:
199+ init_ers: If True, automatically initializes ERS configuration during construction.
199200 _BASE_HANDLERS: Private class variable for default base handlers
200201 _OPMON_HANDLERS: Private class variable for opmon handlers
201202 BASE_CONFIG: Class variable for base stream configuration
202203 OPMON_CONFIG: Class variable for opmon stream configuration
203204 ERS: Instance field for ERS configuration (loaded from environment)
204205 """
206+ init_ers : bool = False
205207
206208 _BASE_HANDLERS : ClassVar [set ] = {HandlerType .Stream , HandlerType .Rich ,
207209 HandlerType .File
208210 }
209211 _OPMON_HANDLERS : ClassVar [set ] = {HandlerType .Rich , HandlerType .Stream ,
210212 HandlerType .File }
213+ _ERS : object = None
211214
212215 Base : ClassVar [dict ] = {
213216 "handlers" : _BASE_HANDLERS ,
@@ -219,12 +222,43 @@ class LogHandlerConf:
219222 "stream" : StreamType .OPMON
220223 }
221224
222- ERS : dict = field (default_factory = lambda :
223- {
224- "ers_handlers" : LogHandlerConf ._get_oks_conf (),
225- "stream" : StreamType .ERS
226- }
227- )
225+ def __post_init__ (self ):
226+ """Initialize ERS configuration if init_ers field is True.
227+
228+ This method is called automatically after dataclass initialization.
229+ If the init_ers attribute was set to True, it triggers the complete
230+ ERS initialization.
231+ """
232+ if self .init_ers :
233+ self .init_ERS ()
234+
235+ @property
236+ def ERS (self ):
237+ """Get the ERS configuration dictionary.
238+
239+ Returns:
240+ dict: Contains 'ers_handlers' and 'stream' configuration for ERS
241+
242+ Raises:
243+ AttributeError: If ERS has not been initialized (call init_ERS() first)
244+ """
245+ if not self ._ERS :
246+ raise AttributeError ("ERS stream not initialised. Call init_ERS() first" )
247+ return self ._ERS
248+
249+ def init_ERS (self ):
250+ """Initialize ERS configuration from environment variables.
251+
252+ Loads ERS configuration from OKS environment variables and populates
253+ the _ERS dict with handlers and stream information.
254+
255+ Called automatically during construction if init_ers=True, or can be
256+ called manually afterwards.
257+ """
258+ self ._ERS = {
259+ "ers_handlers" : LogHandlerConf ._get_oks_conf (),
260+ "stream" : StreamType .ERS
261+ }
228262
229263 @staticmethod
230264 def _convert_str_to_handlertype (handler_str : str ) -> tuple [HandlerType ,
0 commit comments