If you are creating a new function, see the Console Quickstart on Cloud Run. The content on this page only applies to existing legacy functions created with the Cloud Functions v1 API.
Stay organized with collections
Save and categorize content based on your preferences.
Java Logging
In the Java runtime, any output to STDOUT or STDERR is propagated to Cloud
Logging. However, granular log severity
level is not propagated. Use the standard Java Logging API (JUL) to log messages and propagate the
correct log severity levels to Cloud Logging.
If you use a different logging framework, such as SLF4J, Log4j 2, or Apache Commons Logging, you can propagate the correct log
severity level in one of the following ways:
Format the log messages in the
Structured Logging JSON format so that the
severity level is propagated to Cloud Logging.
Use a bridge/adapter to send log messages to the Java Logging API, which
already propagates the log messages in the correct format. If you take this
approach, make sure there is not an existing adapter that already routes from
the Java Logging API to the logging framework.
If your function uses different libraries and the libraries use different
logging frameworks, then you'll need to configure each of the logging frameworks
used. The following sections cover some of the various options.
Spring Cloud Run function
If you use Spring Cloud Run function with the Spring Cloud Run functions
Google Cloud Adapter, you can output the log in the right format using the
Spring Cloud's Google Cloud Logging Starter and the
CONSOLE_JSON appender
to output the log in the JSON format. Spring uses SLF4J and Logback by
default—but you can also route SLF4J logs to the Java Logging API. See the
SLF4J section for details.
Java Logging API (JUL)
All supported
Cloud Run functions Java
environments
include Java Logging with a JSON handler that outputs the log in the correct
format. Some Java frameworks may add additional components to bridge JUL to a
different logging framework (such as jul-to-slf4j bridge or Log4j JDK Logging Adapter), in which case those log
messages will no longer be formatted correctly. If your log messages do not have
correct severity levels, make sure those bridges are removed.
SLF4J
SLF4J can write logs to the
Java Logging API by using the slf4j-jdk14 logging framework binding. See the
SLF4J
documentation for details. Make sure you don't have the jul-to-slf4j
bridge.
Logback
Logback does not have an
appender that routes log messages to the Java Logging API. However, Logback is
usually used with the SFL4J API, so you can switch the
SLF4J logger implementation to the Java Logging API.
Log4j 2
Log4j 2
does not have a direct adapter that routes log messages to the Java Logging API.
If you are using Log4j 2, then you need to first route messages to SLF4J using
the Log4J 2 to SLF4J Adapter, then configure SLF4J to use the
Java Logging API implementation. Make sure you do not
have the Log4j JDK Logging Adapter.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["\u003cp\u003eJava's standard output and error streams are propagated to Cloud Logging, but without granular severity levels.\u003c/p\u003e\n"],["\u003cp\u003eThe Java Logging API (JUL) should be used to ensure correct log severity levels are propagated to Cloud Logging.\u003c/p\u003e\n"],["\u003cp\u003eOther logging frameworks like SLF4J, Log4j 2, and Apache Commons Logging require specific configurations, either via structured JSON formatting or bridges/adapters, to achieve proper severity level propagation.\u003c/p\u003e\n"],["\u003cp\u003eSpring Cloud Run functions using the Google Cloud Adapter can utilize the \u003ccode\u003eCONSOLE_JSON\u003c/code\u003e appender for correct log formatting and utilize SLF4J with Logback which can be routed to Java Logging API.\u003c/p\u003e\n"],["\u003cp\u003eWhen using alternative logging frameworks, it is crucial to remove any existing bridges that may interfere with the correct formatting of log messages and severity levels.\u003c/p\u003e\n"]]],[],null,["# Java Logging\n============\n\nIn the Java runtime, any output to `STDOUT` or `STDERR` is propagated to [Cloud\nLogging](/functions/1stgendocs/monitoring/logging). However, granular log severity\nlevel is not propagated. Use the standard [Java Logging API (JUL)](https://docs.oracle.com/javase/10/core/java-logging-overview.htm/) to log messages and propagate the\ncorrect log severity levels to Cloud Logging.\n\nIf you use a different logging framework, such as [SLF4J](http://www.slf4j.org/), [Log4j 2](https://logging.apache.org/log4j/2.x/), or [Apache Commons Logging](https://commons.apache.org/proper/commons-logging/), you can propagate the correct log\nseverity level in one of the following ways:\n\n- Format the log messages in the [Structured Logging JSON format](/logging/docs/structured-logging) so that the severity level is propagated to Cloud Logging.\n- Use a bridge/adapter to send log messages to the Java Logging API, which already propagates the log messages in the correct format. If you take this approach, make sure there is not an existing adapter that already routes from the Java Logging API to the logging framework.\n\nIf your function uses different libraries and the libraries use different\nlogging frameworks, then you'll need to configure each of the logging frameworks\nused. The following sections cover some of the various options.\n\nSpring Cloud Run function\n-------------------------\n\nIf you use Spring Cloud Run function with the Spring Cloud Run functions\nGoogle Cloud Adapter, you can output the log in the right format using the\n[Spring Cloud's Google Cloud Logging Starter](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/tree/main/spring-cloud-gcp-samples/spring-cloud-gcp-logging-sample) and the\n[`CONSOLE_JSON` appender](https://github.com/GoogleCloudPlatform/spring-cloud-gcp/blob/main/spring-cloud-gcp-logging/src/main/resources/com/google/cloud/spring/logging/logback-json-appender.xml)\nto output the log in the JSON format. Spring uses SLF4J and Logback by\ndefault---but you can also route SLF4J logs to the Java Logging API. See the\n[SLF4J](#slf4j) section for details.\n\nJava Logging API (JUL)\n----------------------\n\nAll supported\nCloud Run functions [Java\nenvironments](/functions/1stgendocs/runtime-support#java)\ninclude Java Logging with a JSON handler that outputs the log in the correct\nformat. Some Java frameworks may add additional components to bridge JUL to a\ndifferent logging framework (such as [jul-to-slf4j bridge](http://www.slf4j.org/legacy.html#jul-to-slf4j) or [Log4j JDK Logging Adapter](https://logging.apache.org/log4j/2.0/log4j-jul.html)), in which case those log\nmessages will no longer be formatted correctly. If your log messages do not have\ncorrect severity levels, make sure those bridges are removed.\n\nSLF4J\n-----\n\n[SLF4J](http://www.slf4j.org/) can write logs to the\nJava Logging API by using the `slf4j-jdk14` logging framework binding. See the\n[SLF4J\ndocumentation](http://www.slf4j.org/docs.html) for details. Make sure you don't have the `jul-to-slf4j`\nbridge.\n\nLogback\n-------\n\n[Logback](http://logback.qos.ch/) does not have an\nappender that routes log messages to the Java Logging API. However, Logback is\nusually used with the SFL4J API, so you can switch the\nSLF4J logger implementation to the [Java Logging API](#java_logging_api_jul).\n\nLog4j 2\n-------\n\n[Log4j 2](https://logging.apache.org/log4j/2.x/)\ndoes not have a direct adapter that routes log messages to the Java Logging API.\nIf you are using Log4j 2, then you need to first route messages to SLF4J using\nthe [Log4J 2 to SLF4J Adapter](https://logging.apache.org/log4j/log4j-2.2/log4j-to-slf4j/index.html), then configure SLF4J to use the\n[Java Logging API](#java_logging_api_jul) implementation. Make sure you do not\nhave the Log4j JDK Logging Adapter.\n\nApache Commons Logging (JCL)\n----------------------------\n\n[Apache Commons Logging](https://commons.apache.org/proper/commons-logging/) has a Java Logging API adapter.\nConfigure Commons Logging to use the [Jdk14Logger](http://commons.apache.org/proper/commons-logging/apidocs/org/apache/commons/logging/impl/Jdk14Logger.html). See the [Apache Commons Logging configuration](http://commons.apache.org/proper/commons-logging/guide.html#Configuration) page for more\ninformation."]]