C3.logger for python code

Is there an equivalent of C3.logger or C3.log for python environment code?


Yes, you can use native python logging library. (https://docs.python.org/3.6/library/logging.html)

import logging
logger = logging.getLogger('name_of_your_logger')

followed later in your code by statements like

logger.info("Just did something awesome")

Similar to any language, in case you log the content of an object, be mindful that:

  1. The logger can raise an Exception that will break the execution of your code
  2. If the thing you want to log requires heavy processing (a large object to serialize, or whatever), you should protect your logger with a check on its level
if logger.isEnabledFor('DEBUG'): 
    logger.debug("A big object: {}".format(myObj.toJson()))
1 Like

I think this is only part of the solution, how can I see the log after a python method execution?
Is it available on Splunk? If so I’m not able to find it.

yes, for example you can find the output for the logger defined above using: logger=c.e.a.PythonActionEngine name_of_your_logger

1 Like

@Nicola can you provide the logger you have defined ? I’m afraid your user do not have permission to see some logs.
Get in touch via mail so I can check if I see your logs - it this is the case then you have to add some in your log string like below

log.info("t_tenant="+ c3Context().tenant + " t_tag="+ c3Context().tag + "dhkahdahdakdhksjdh" )

Hi Marco, I’ll try adding that string.
I realized that I’m having an error when importing the logging library in Python that breaks the execution.
I’m importing at the beginning of the .py file, outside of the methods implementation:

import logging
logger = logging.getLogger('LogUseCaseClc_v1')

and then inside a method:

logger.info('Test Message 1' )

Hi Nicola,

The error comes from
which should in fact be

Whenever you encounter such error message No output from python for action, it probably means that there is a typo in the python code.


1 Like


what is the corresponding instruction in Python for it?
I have tried this:
log.info(“t_tenant=”+ c3Context().tenant + " t_tag="+ c3Context().tag + “dhkahdahdakdhksjdh” )
and this:
log.info(“t_tenant=”+ c3.c3Context().tenant + " t_tag="+ c3.c3Context().tag + “dhkahdahdakdhksjdh” )

but these instruction didn’t work.

Thank you in advance,