Search code examples
ibm-cloudserverlessibm-cloud-code-engine

IBM Cloud Code Engine: How to check logs when app not active?


I have deployed an app to IBM Cloud Code Engine. It has the minimum instances configured to zero, so truly serverless and only active on demand. Now I wanted to check the logs from the CLI with

ibmcloud ce app logs --name myapp --all

it comes back with this message:

FAILED No instances running for application 'myapp'. Verify that the application name is correct and it is running

How can I check the application logs after it has run?


Solution

  • The Code Engine application (and job) logs can be seen once Application Logging has been enabled. The logs are then available in a separate IBM Cloud Logging dashboard.

    I also found this old blog post exlaining how to enable CLI access to those logs. After enabling it I was able to retrieve the app logs using my CLI / development environment.

    show JSON log records on CLI

    Depending on what I am after, I am using one of these three lines to get to the log data / lines:

    python3 searchLogDNA.py myconfig.json 12 "search term" | jq
    

    for pretty printing, or

    python3 searchLogDNA.py myconfig.json 12 "search term" | jq "._line"
    

    to extract the actual log line from the record, or

    python3 searchLogDNA.py myconfig.json 12 "search term" | jq "._line | fromjson`"
    

    to turn the string with JSON data in the log line to actual JSON output.