Skip to content

Structured logging not working #2252

Closed
Closed
@deman-Innotractor

Description

@deman-Innotractor

Expected behavior

Want to see structured logging in Azure.

Actual behavior

No structured logging at all, only the information. Maybe it is related to #2251

To Reproduce

@slf4j
log.info("Test {}, {}", kv("test1", "a"), v("test2", "b"));

Sample Application

If applicable, provide a sample application which reproduces the issue.

System information

Please provide the following information:

  • SDK Version: 3.2.11 (also 3.2.10)
  • OS type and version: Windows 11
  • Application Server type and version (if applicable): (local)
  • Using spring-boot? yes
  • Additional relevant libraries (with version, if applicable): Lombok.

POM.xml

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.6.7</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
            <version>2.6.7</version>
        </dependency>
        <dependency>
            <groupId>com.microsoft.azure</groupId>
            <artifactId>applicationinsights-core</artifactId>
            <version>2.6.4</version>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-api</artifactId>
            <version>1.10.0</version>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-extension-annotations</artifactId>
            <version>1.10.0</version>
        </dependency>
        <dependency>
            <groupId>io.opentelemetry</groupId>
            <artifactId>opentelemetry-semconv</artifactId>
            <version>1.10.0-alpha</version>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
            <version>1.8.5</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.2.11</version>
        </dependency>
        <dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>7.1.1</version>
        </dependency>

Logs

logback-spring.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
	<springProfile name="default">
		<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
			<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
				<providers>
					<timestamp>
						<fieldName>timestamp</fieldName>
						<timeZone>UTC</timeZone>
					</timestamp>
					<loggerName>
						<fieldName>logger</fieldName>
					</loggerName>
					<logLevel>
						<fieldName>level</fieldName>
					</logLevel>
					<threadName>
						<fieldName>thread</fieldName>
					</threadName>
					<nestedField>
						<fieldName>mdc</fieldName>
						<providers>
							<mdc />
						</providers>
					</nestedField>
					<stackTrace>
						<fieldName>stackTrace</fieldName>
						<!-- maxLength - limit the length of the stack trace -->
						<throwableConverter class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
							<maxDepthPerThrowable>200</maxDepthPerThrowable>
							<maxLength>14000</maxLength>
							<rootCauseFirst>true</rootCauseFirst>
						</throwableConverter>
					</stackTrace>
					<message />
					<throwableClassName>
						<fieldName>exceptionClass</fieldName>
					</throwableClassName>
				</providers>
			</encoder>
		</appender>
	</springProfile>
	<root level="INFO">
		<appender-ref ref="stdout" />
	</root>

</configuration>

Console log:

{"timestamp":"2022-04-29T10:32:47.099Z","logger":"com.innotractor.leshan.server.LeshanInnoInstance","level":"INFO","thread":"restartedMain","mdc":{},"message":"Test test1=a, b"}

Screenshots

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions