Viewing logs
Logging can help you troubleshoot issues in IBM Cloud® Code Engine. You can view logs by using the console or by using the CLI.
As of 28 March 2024, the IBM Log Analysis service is deprecated and will no longer be supported as of 30 March 2025. Customers will need to migrate to IBM Cloud Logs before 30 March 2025. During the migration period, customers can use IBM Log Analysis along with IBM Cloud Logs. Logging is the same for both services. For information about migrating from IBM Log Analysis to IBM Cloud Logs and running the services in parallel, see migration planning.
Viewing logs from the console
When you work with Code Engine apps, jobs, functions, or builds in the console with logging enabled, logs are forwarded to an IBM Cloud Logs service where they are indexed, enabling full-text search through all generated messages and convenient querying based on specific fields.
To view logs for your app, job, or build in the Code Engine console, you must create an IBM Cloud Logs instance in the same region as your Code Engine project. You are not required to create this instance before you work with your Code Engine component. From your Code Engine app, job, function, or build page in the console, you can add logging capabilities.
You need to enable logging for Code Engine only one time per region, per account.
Considerations for viewing logs from the console
When you want to use logging from the console, you must first configure IBM Cloud Logs platform logs to receive Code Engine logging data. To check for active IBM Cloud Logs instances, see the Observability dashboard.
Review the IBM Cloud Logs service plan information as you consider retention, search, and log analysis needs.
When you view log data for Code Engine applications, runs of your job, or runs of your build, delays can occur before the data is available in IBM Cloud Logs. For example, it might take around 5 to 10 minutes for your log data to show in IBM
Cloud Logs, especially if you are using the Store and search
data pipeline.
Review the documentation on Data Pipelines to learn about options to balance log latency and cost for your IBM Cloud Logs instances.
When you use logging with the CLI, you do not need to configure IBM Cloud Logs platform logs, as the Code Engine CLI logging fetches its data differently.
The logging capabilities offered through the CLI are limited and should only be considered for development purposes. When running production workload, you should always use an IBM Cloud Logs instance, which offers log retention, filter and search capabilities.
Can I apply filters on IBM Cloud Logs data?
Yes! You can modify and scope the filter to display log data at a specific level or a more granular level to a specific application revision, job run, or build run from the IBM Cloud Logs page, based on your needs.
-
If
message.serviceName:"codeengine"
is set, then only Code Engine logs are displayed. -
If
label.Project:'<project_name>'
is set, then only logs from a specific project are displayed. -
If
message._app:'<your_component_name>'
is set, then only logs from the specified component (application, job, or build) are displayed. If your Code Engine components share the same name, the filter includes logs from these components. For example,- The filter
message.serviceName:"codeengine" AND message._app:"myapp"
scopes the logs to themyapp
application level. - The filter
message.serviceName:"codeengine" AND message._app:"myapp\-00002"
scopes the logs to themyapp-0002
application revision level. - The filter
message.serviceName:"codeengine" AND message._app:"myjob"
scopes the logs to the specificmyjob
job level. - The filter
message.serviceName:"codeengine" AND message._app:"myjob\-jobrun\-t6m7l"
scopes the logs to the specificmyjob-jobrun-t6m7l
job run level. - The filter
message.serviceName:"codeengine" AND message._app:"mybuild"
scopes the logs to the specificmybuild
build level. - The filter
message.serviceName:"codeengine" AND message._app:"mybuild\-run\-121212"
scopes the logs to the specificmybuild-run-121212
build run level.
- The filter
For more information about configuring and starting logging in the console, see viewing app, job, or function logs from the console.
What if my log data is multi-line?
Every log line must contain log level and timestamp information to appear correctly in IBM Cloud Logs. If your log lines span multiple lines, change how you format and output your logs so that they are in a single line. Use the JSONL format for your logs with IBM Cloud Logs. Your logs must also conform to limits for IBM Cloud Logs. After you make log formatting changes, you can take advantage of IBM Cloud Logs search and formatting features.
Viewing app, job, or function logs from the console
You can view logs for apps, jobs, or functions. The steps to view any of these from the console are very similar.
After you select the project that you want to work with, you can add logging capabilities from the Code Engine Overview page or one of its child pages such as the Applications, Jobs, or Functions page; or from the page that is specific to your application, job, or function. The following steps assume that you are working from a specific Code Engine page.
- Go to an app, job, or function that you created and deployed. From the Projects page on the Code Engine console, select your project and then select Applications, Jobs, or Functions as appropriate. Select the app, job, or function with which you want to work.
- If you previously created an IBM Cloud Logs instance, click Logging, to open the IBM Cloud Logs service.
- Add and configure logging capabilities:
- From the Test application, Submit job, or Test function options menu, click Add logging to create the IBM Cloud Logs instance. This action opens the IBM Cloud Logs service.
- From the IBM Cloud Logs service, create your logging instance. To confirm that your logging instance is created, check the Observability dashboard.
- From your Code Engine app, job, or function page, click Add logging from the Test application, Submit job, or Test function options menu. This time, select an IBM Cloud Logs instance to receive platform logs. Choose the logging instance that you created in the prior step. Click Select. Code Engine requires enabled platform logs to receive Code Engine logging data. When you complete this action, Code Engine enables platform logging for you.
- Now that platform logs are configured, from your Code Engine app, job, or function page, click Logging from the Test application, Submit job, or Test function options menu to open your platform logs window. To confirm that platform logs are set for your region, check the Observability dashboard.
- (optional) Refine the filter for your search, if needed.
- Verify your configuration by doing one of the following steps:
- For an application or a function, test it: click Test application or Test function as appropriate, and then click Send request. To open the application or function in a web page, click Application URL or Function URL. You can view platform logs from the test in the platform logs window.
- For a job, run it: from the Job runs area, click Submit job to run your job. Provide the job run configuration values or you can take the default values. Click Submit job to run your job. You can view platform logs from the job run in the platform logs window.
Your IBM Cloud Logs instance is now configured such that it can receive platform logging for your Code Engine app, job, or function.
Alternatively, you can configure an IBM Cloud Logs instance by using the Observability dashboard to create the instance, and then by configuring platform logs routing.
Viewing build logs from the console
You can display logs for specific build run instances from the console.
- Go to the Code Engine dashboard.
- Select a project (or create one).
- From the project page, click Image builds.
- From the Image build tab, click the name of your image build to open the build page for a defined build, or create a build.
- From the build page for your defined build, click the name of the instance of your build run in the Build runs section. You might need to click Submit build to create a build run. You can view platform logs from the build run in the platform logs window. Alternatively, you can also view build log information for the build step details from the build run instance page. Expand the build steps for specific build step log data. You can optionally refine the filter for your search, if needed.
Viewing logs with the CLI
To view logging output with the CLI, you must have a running instance of your app or job. If an app is scaled to zero or a job run instance is completed, the output for the ibmcloud ce app logs
and ibmcloud ce jobrun logs
commands does not have log data. Alternatively, you can use the IBM Cloud Logs service to view log data.
Viewing application logs with the CLI
To view app logs for a specific app with the CLI, use the application logs
command. You can display logs of all the instances of an app or display logs of a specific instance of an app. The app get
command displays
details about your app, including the running instances of the app.
-
To view the logs for all instances of the
myapp
app, specify the name of the app with the--app
option; for example,ibmcloud ce app logs --app myapp
Example output
Getting logs for all instances of application 'myapp'... OK myapp-ii18y-2-deployment-7657c5f4f9-dgk5f: Server running at http://0.0.0.0:8080/
-
To view the logs for a specific instance of the app, specify the name of the specific instance of the app with the
--instance
option; for example,ibmcloud ce app logs --instance myapp-ii18y-2-deployment-7657c5f4f9-dgk5f
Example output
Getting logs for application instance 'myapp-a5yp2-2-deployment-65766594d4-hj6c5'... OK myapp-a5yp2-2-deployment-65766594d4-hj6c5: Server running at http://0.0.0.0:8080/
Viewing job logs with the CLI
To view logs for a specific job run with the CLI, use the jobrun logs
command. You can display logs of all the instances of a job run or display logs of a specific instance of a job run. The jobrun get
command displays
details about your job run, including the instances of the job run.
-
To view the logs for all instances of the
testjobrun
job run, specify the name of the job run with the--jobrun
option; for example,ibmcloud ce jobrun logs --jobrun testjobrun
Example output
Getting jobrun 'testjobrun'... Getting instances of jobrun 'testjobrun'... Getting logs for all instances of job run 'testjobrun'... OK testjobrun-1-0: Hello World! testjobrun-2-0: Hello World! testjobrun-3-0: Hello World! testjobrun-4-0: Hello World! testjobrun-5-0: Hello World!
-
To view the logs for the
testjobrun-1-0
job run instance, specify the name of a specific instance of the job run with the--instance
option; for example,ibmcloud ce jobrun logs --instance testjobrun-1-0
Example output
Getting logs for job run instance 'testjobrun-1-0'... OK testjobrun-1-0: Hello World!
Viewing build logs with the CLI
To view build logs for a specific build run with the CLI, use the buildrun logs
command. You can display logs of all the instances of a build run based on the name of the build run.
To view the logs for all instances of the mybuildrun
build run, specify the name of the build run with the --name
option; for example,
ibmcloud ce buildrun logs --name mybuildrun
Example output
Getting build run 'mybuildrun'...
Getting instances of build run 'mybuildrun'...
Getting logs for build run 'mybuildrun'...
OK
mybuildrun-zg5rj-pod-z5gzb/step-git-source-source-r9fcf:
{"level":"info","ts":1614363665.8331757,"caller":"git/git.go:169","msg":"Successfully cloned https://github.com/IBM/CodeEngine @ 8b514ce871e50d67cfea3e344b90cade4bd26e90 (grafted, HEAD, origin/main) in path /workspace/source"}
{"level":"info","ts":1614363666.82988,"caller":"git/git.go:207","msg":"Successfully initialized and updated submodules in path /workspace/source"}
mybuildrun-zg5rj-pod-z5gzb/step-build-and-push:
INFO[0002] Retrieving image manifest node:12-alpine
INFO[0002] Retrieving image node:12-alpine
INFO[0003] Retrieving image manifest node:12-alpine
INFO[0003] Retrieving image node:12-alpine
INFO[0003] Built cross stage deps: map[]
INFO[0003] Retrieving image manifest node:12-alpine
INFO[0003] Retrieving image node:12-alpine
INFO[0004] Retrieving image manifest node:12-alpine
INFO[0004] Retrieving image node:12-alpine
INFO[0004] Executing 0 build triggers
INFO[0004] Unpacking rootfs as cmd RUN npm install requires it.
INFO[0008] RUN npm install
INFO[0008] Taking snapshot of full filesystem...
INFO[0010] cmd: /bin/sh
INFO[0010] args: [-c npm install]
INFO[0010] Running: [/bin/sh -c npm install]
npm WARN saveError ENOENT: no such file or directory, open '/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/package.json'
npm WARN !invalid#2 No description
npm WARN !invalid#2 No repository field.
npm WARN !invalid#2 No README data
npm WARN !invalid#2 No license field.
up to date in 0.267s
found 0 vulnerabilities
INFO[0011] Taking snapshot of full filesystem...
INFO[0011] COPY server.js .
INFO[0011] Taking snapshot of files...
INFO[0011] EXPOSE 8080
INFO[0011] cmd: EXPOSE
INFO[0011] Adding exposed port: 8080/tcp
INFO[0011] CMD [ "node", "server.js" ]
mybuildrun-zg5rj-pod-z5gzb/step-image-digest-exporter-ngl6j:
2021/02/26 18:21:02 warning: unsuccessful cred copy: ".docker" from "/tekton/creds" to "/tekton/home": unable to open destination: open /tekton/home/.docker/config.json: permission denied
{"severity":"INFO","timestamp":"2021-02-26T18:21:26.372494581Z","caller":"logging/config.go:116","message":"Successfully created the logger."}
{"severity":"INFO","timestamp":"2021-02-26T18:21:26.372621756Z","caller":"logging/config.go:117","message":"Logging level set to: info"}