In the logging section within compute modules documentation tab
See image below
Never mind, in the last bullet point, it says SLS not supported but this could be so much clearer. Also please add support for structured logs
import logging
from compute_modules.logging import get_logger, set_internal_log_level
# setup logging
set_internal_log_level(logging.INFO)
logger = get_logger(__name__)
logger.setLevel(logging.INFO)
logger.debug("This message will *not* be emitted in the compute module")
logger.info("This message will be emitted in compute module")
logger.warning("And this")
logger.error("And this")
If you run the code above in Python and then select SLS in your container configuration, everything will be parsed neatly. We are working on updating this documentation.
Note: you could also create a custom log formatter: http://github.com/palantir/python-compute-module?tab=readme-ov-file#applying-your-own-custom-log-formatter-via-the-sdk
Ah thanks! Can I also ask if there’s a way to save filters on the logging received in the compute module? It’s bit of a pain to reapply my filters every time
if there’s a way to save filters on the logging received in the compute module?
Hello. Unfortunately, your filters clear on every page load. We are tracking persisting your log filter settings as a feature request internally.
And also, I’m now using SLS logs but it seems the logs don’t reach Foundry properly. All I get are what look like these rather useless messages about handling the message, but these occur at the times I expect the log outputs.
I believe I followed the instructions alright and the logs work on local debugging but is there some config missing?
This is the sort of thing I get
![]()
Ah no worries - thanks!
The only configuration required is setting the Logs format in the Container configuration. To do this, select the container’s row in the Containers section. This will open a side panel where you can adjust the logging settings to Format = SLS
If you have already done this, can you provide a code snippet showing the logger instantiation and usage?
Yep this is done. Here are the code snippets:
import logging
from compute_modules.logging import get_logger, set_internal_log_level
# Override default minimum logging level
set_internal_log_level(logging.INFO)
# Returns a logging.Logger instance
logger = get_logger(__name__)
# Example usage
...
try:
...
except Exception:
logger.exception("Error processing page %d of %d", page_number, total_pages)
...
import logging
from compute_modules.logging import get_logger, set_internal_log_level
# Override default minimum logging level
set_internal_log_level(logging.INFO)
# Returns a logging.Logger instance
logger = get_logger(__name__)
logger.setLevel(logging.INFO) # <---- this is missing
Could you add the last line to setLevel in your code?
I was able to reproduce the logger.exception not showing up without it and adding the setLevel fixed it.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.