Skip to content

Commit e6680c4

Browse files
committed
function worker to pick level from env variable LOG_LEVEL. Defaults to INFO
1 parent 672f0b9 commit e6680c4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

FunctionWorker/python/FunctionWorker.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ def _set_args(self, args):
187187

188188
self._should_checkpoint = args["should_checkpoint"]
189189

190+
def _get_loglevel(self):
191+
loglevel = logging.INFO
192+
if "LOG_LEVEL" in os.environ and os.environ["LOG_LEVEL"] != None and len(str(os.environ["LOG_LEVEL"])) > 0:
193+
loglevel = logging._nameToLevel.get(str(os.environ["LOG_LEVEL"]).upper(), loglevel)
194+
return loglevel
195+
190196
def _setup_loggers(self):
191197
global LOGGER_HOSTNAME
192198
global LOGGER_CONTAINERNAME
@@ -200,15 +206,16 @@ def _setup_loggers(self):
200206
LOGGER_WORKFLOWNAME = self._workflowname
201207
LOGGER_WORKFLOWID = self._workflowid
202208

209+
logevel = self._get_loglevel()
203210
self._logger = logging.getLogger(self._function_state_name)
204-
self._logger.setLevel(logging.INFO)
211+
self._logger.setLevel(logevel)
205212
self._logger.addFilter(LoggingFilter())
206213

207214
formatter = logging.Formatter("[%(timestamp)d] [%(levelname)s] [%(hostname)s] [%(containername)s] [%(uuid)s] [%(userid)s] [%(workflowname)s] [%(workflowid)s] [%(name)s] [%(asctime)s.%(msecs)03d] %(message)s", datefmt='%Y-%m-%d %H:%M:%S')
208215
logfile = '/opt/mfn/logs/function_'+ self._function_state_name + '.log'
209216

210217
hdlr = logging.FileHandler(logfile)
211-
hdlr.setLevel(logging.INFO)
218+
hdlr.setLevel(logevel)
212219
hdlr.setFormatter(formatter)
213220
self._logger.addHandler(hdlr)
214221

FunctionWorker/python/PublicationUtils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ def _send_remote_message(self, remote_address, message_type, action_data):
319319
while retry <= 6.4:
320320
try:
321321
action_data_str = json.dumps(action_data)
322-
self._logger.debug("Sending remote message (" + message_type + ") : " + action_data_str)
322+
self._logger.debug(f"Sending remote message ({message_type}) to {remote_address}, data: {action_data_str}")
323323
resp = requests.post(remote_address,
324324
params={"async": 1},
325325
json={},
@@ -328,12 +328,12 @@ def _send_remote_message(self, remote_address, message_type, action_data):
328328
"x-mfn-action-data": action_data_str})
329329
break
330330
except Exception as exc:
331-
self._logger.debug("Sending remote message (" + message_type + ") failed: " + str(exc) + "; retrying in: " + str(retry) + "s")
331+
self._logger.warn(f"Failed sending remote message ({message_type}) to {remote_address}, data: {action_data_str}, exception: {str(exc)}; retrying in: {str(retry)}s")
332332
time.sleep(retry)
333333
retry = retry * 2
334334

335335
if retry > 6.4:
336-
self._logger.debug("Could not send remote message (" + message_type + ") due to timeouts.")
336+
self._logger.warn(f"Failed sending remote message ({message_type}) to {remote_address} failed, data: {action_data_str}, due to timeouts")
337337

338338

339339
def _publish_privileged_output(self, function_output, lqcpub):

0 commit comments

Comments
 (0)