Logging Best Practices
Hi. I'm working on my first Actor, to understand capabilities of the platform before I build some real Actors. Can someone explain some recommendations around logging? I have my docker container that writes to console. I can see that in Apify so all good. But, for example, if a customer runs my Actor, will they always see exactly the same output I see? I would expect public runs to not include sensitive data, but I would like to see that when I run myself. E.g an exception thrown or error returned by a library I use. I do not want sensitive error details, code/files/line numbers or internal details in the customer's logs, but I would expect them in mine. Can I enforce different log levels for customers vs myself? Maybe this all comes down to: can I configure different environment variables for customers vs myself that can't be overridden by the customer?
3 Replies
I can see the 'APIFY_USER_ID' env variable. That would let me distinguish me vs not-me, but seems like a bit of a hack
You can use different log.level:
https://crawlee.dev/js/api/core/class/Log?_gl=1*2l9icz*_gcl_au*MTczNDkyMTA0MS4xNzQ1ODMzMjQzLjMzMDUzNDIyMS4xNzQ4ODg4MjA4LjE3NDg4ODgyMDg.*_ga*MTI0OTIwNDkwLjE3MzgwNTcyNDA.*_ga_62P18XN9NS*czE3NDk1NjQ4MDEkbzQ2NiRnMSR0MTc0OTU2NDgyMyRqMzgkbDEkaDIwNDcwNzQzMzk.
e.q. log.info() - for some generic "user-friendly" info
log.debug() - for your debugging.
and then control it via var:
https://docs.apify.com/sdk/js/docs/guides/environment-variables#apify_log_level
OK thanks. So the idea here would be to manually change the log level env variable to Debug when I run it myself, if I want extra details. And a customer would be unable to set that variable. That could work except I was hoping to automatically have a different log level for myself, without the manual step. Thanks for the help 👍