Add support for structured logging

Update Logback and Log4j2 integrations to support structured logging.
Support for the ECS and Logstash JSON formats is provided out-of-the-box
and the `StructuredLogFormatter` interface may be used to if further
custom formats need to be supported.

Closes gh-5479

Co-authored-by: Phillip Webb <phil.webb@broadcom.com>
This commit is contained in:
Moritz Halbritter
2024-07-15 11:24:51 +01:00
committed by Phillip Webb
parent 89f3052f6e
commit bf2950c045
47 changed files with 2699 additions and 26 deletions

View File

@@ -0,0 +1,30 @@
/*
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.docs.features.logging.structured.customformat;
import ch.qos.logback.classic.spi.ILoggingEvent;
import org.springframework.boot.logging.structured.StructuredLogFormatter;
class MyCustomFormat implements StructuredLogFormatter<ILoggingEvent> {
@Override
public String format(ILoggingEvent event) {
return "time=" + event.getInstant() + " level=" + event.getLevel() + " message=" + event.getMessage() + "\n";
}
}