자바 런타임에서 STDOUT 또는 STDERR에 대한 출력은 Cloud Logging으로 전파됩니다. 하지만 세분화된 로그 심각도 수준은 전파되지 않습니다. 표준 Java Logging API(JUL)를 사용하여 메시지를 로깅하고 Cloud Logging에 올바른 로그 심각도 수준을 전파합니다.
심각도 수준이 Cloud Logging에 전파되도록 구조화된 로깅 JSON 형식으로 로그 메시지의 형식을 지정합니다.
브리지/어댑터를 사용하여 이미 로그 메시지를 올바른 형식으로 전파하는 Java Logging API로 보냅니다. 이 접근 방식을 사용하는 경우 Java Logging API에서 로깅 프레임워크로 이미 라우팅하는 기존 어댑터가 없는지 확인하세요.
함수가 서로 다른 라이브러리를 사용하고 라이브러리가 서로 다른 로깅 프레임워크를 사용하는 경우 사용되는 각 로깅 프레임워크를 구성해야 합니다. 다음 섹션에서는 다양한 옵션을 다룹니다.
Spring Cloud Run 함수
Spring Cloud Run Functions Google Cloud 어댑터와 함께 Spring Cloud Run 함수를 사용하는 경우 Spring Cloud의 Google Cloud Logging Starter와 CONSOLE_JSON 어펜더를 사용하여 JSON 형식으로 로그를 출력합니다. Spring은 기본적으로 SLF4J 및 Logback을 사용하지만, SLF4J 로그를 Java Logging API로 라우팅할 수도 있습니다. 자세한 내용은 SLF4J 섹션을 참조하세요.
Java Logging API(JUL)
지원되는 모든 Cloud Run Functions 자바 환경에는 올바른 형식으로 로그를 출력하는 JSON 핸들러와 함께 Java Logging이 포함됩니다. 일부 자바 프레임워크는 JUL을 다른 로깅 프레임워크(예: jul-to-slf4j bridge 또는 Log4j JDK Logging 어댑터)와 브리징하기 위해 구성요소를 추가할 수 있으며, 이 로그 메시지의 형식이 더 이상 올바르게 지정되지 않습니다. 로그 메시지의 심각도 수준이 올바르지 않으면 해당 브리지가 삭제되었는지 확인하세요.
SLF4J
SLF4J는 slf4j-jdk14 로깅 프레임워크 바인딩을 사용하여 Java Logging API에 로그를 작성할 수 있습니다. 자세한 내용은 SLF4J 문서를 참조하세요. jul-to-slf4j 브리지가 없는지 확인하세요.
Logback
Logback에는 로그 메시지를 Java Logging API로 라우팅하는 어펜더가 없습니다. 그러나 Logback은 일반적으로 SFL4J API와 함께 사용되므로 SLF4J 로거 구현을 Java Logging API로 전환할 수 있습니다.
Log4j 2
Log4j 2에는 로그 메시지를 Java Logging API로 라우팅하는 직접 어댑터가 없습니다.
Log4j 2를 사용하는 경우 먼저 Log4J 2-SLF4J 어댑터를 사용하여 메시지를 SLF4J로 라우팅한 다음 Java Logging API 구현을 사용하도록 SLF4J를 구성해야 합니다. Log4j JDK Logging 어댑터가 없는지 확인하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-03(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."]]