Coretex
coretex.logging.logger.LogHandler Class Reference

Inherits StreamHandler.

Public Member Functions

bool flushLogs (self)
 
None reset (self)
 

Detailed Description

    Custom StreamHandler which intercepts and stores all
    received logs from python std logging module until they
    are all uploaded to Coretex API

Definition at line 90 of file logger.py.

Member Function Documentation

◆ flushLogs()

bool coretex.logging.logger.LogHandler.flushLogs (   self)
    Uploads all currently stored logs to Coretex backend

    Returns
    -------
    bool -> True if the upload is successful, False otherwise

Definition at line 149 of file logger.py.

149  def flushLogs(self) -> bool:
150  """
151  Uploads all currently stored logs to Coretex backend
152 
153  Returns
154  -------
155  bool -> True if the upload is successful, False otherwise
156  """
157 
158  if len(self.__pendingLogs) == 0:
159  return True
160 
161  if self.currentExperimentId is None:
162  self.__pendingLogs.clear()
163  return True
164 
165  snapshot = copy.copy(self.__pendingLogs)
166 
167  response = networkManager.genericJSONRequest(
168  endpoint = "model-queue/add-console-log",
169  requestType = RequestType.post,
170  parameters = {
171  "model_queue_id": self.currentExperimentId,
172  "logs": [log.encode() for log in snapshot]
173  }
174  )
175 
176  # Only clear logs if they were successfully uploaded to coretex
177  if not response.hasFailed():
178  self.__clearLogs(snapshot)
179 
180  return not response.hasFailed()
181 

◆ reset()

None coretex.logging.logger.LogHandler.reset (   self)
    Resets the internal state of the LogHandler
    Clears all pending logs
    Resets the upload worker thread

Definition at line 182 of file logger.py.

182  def reset(self) -> None:
183  """
184  Resets the internal state of the LogHandler
185  Clears all pending logs
186  Resets the upload worker thread
187  """
188 
189  self.currentExperimentId = None
190  self.__pendingLogs.clear()
191  self.__uploadWorker.reset()

The documentation for this class was generated from the following file: