Giter Site home page Giter Site logo

quarkus-logging-json's Introduction

Maven Central Sonar Coverage

All Contributors

Quarkus Logging Json

Quarkus logging extension outputting the logging in json.

Version to use

Quarkus Version Use version
3.x.x 3.x.x
2.x.x 1.x.x, 2.x.x

Configuration

The extension is enabled by default for console, when added to the project. Console logging can be disabled using configuration: quarkus.log.json.console.enable=false

To see additional configuration options take a look at Config

Elastic Common Scheme

quarkus.log.json.log-format=ecs

Add additional fields to all log messages

If you want to add a static field to all the log message, that is possible using the configuration.

quarkus.log.json.additional-field.serviceName.value=service-a
# type is by default STRING - Other is INT, LONG, FLOAT, DOUBLE 
quarkus.log.json.additional-field.buildNumber.type=INT
quarkus.log.json.additional-field.buildNumber.value=42

Structured argument

If you want to do structured logging of arguments, then the argument send with your logging, can implement io.quarkiverse.loggingjson.providers.StructuredArgument. Then it is possible to use the JsonGenerator to format the argument in json.

Simple usage

import static io.quarkiverse.loggingjson.providers.KeyValueStructuredArgument.*;
...
log.info("Test log of structured arg", kv("key", "value"));

Custom log handler

If you want to add your own custom way to handle the LogRecords. You can create your own implementations of io.quarkiverse.loggingjson.JsonProvider, and provide it using CDI. Example implementation:

import jakarta.inject.Singleton;
import java.io.IOException;

import io.quarkiverse.loggingjson.JsonProvider;
import io.quarkiverse.loggingjson.JsonGenerator;
import org.jboss.logmanager.ExtLogRecord;

@Singleton
public class MyJsonProvider implements JsonProvider {

    @Override
    public void writeTo(JsonGenerator generator, ExtLogRecord event) throws IOException {
        generator.writeStringField("myCustomField", "and my custom value"); // Will be added to every log, as a field on the json.
    }
}

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Simon Bengtsson

💻 🚧

This project follows the all-contributors specification. Contributions of any kind welcome!

quarkus-logging-json's People

Contributors

actions-user avatar allcontributors[bot] avatar aloubyansky avatar dependabot[bot] avatar dfa1 avatar gastaldi avatar gsmet avatar karlscheibelhofer avatar maxandersen avatar quarkiversebot avatar slyngdk avatar tms0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

quarkus-logging-json's Issues

google cloud platform format

It would be great to have a GCP format https://cloud.google.com/logging/docs/structured-logging
Log4j2 has some support the mappings are documented: https://logging.apache.org/log4j/2.x/manual/json-template-layout.html
sepecifically they say:

GcpLayout.json described by Google Cloud Platform structured logging with additional _thread, _logger and _exception fields. The exception trace, if any, is written to the _exception field as well as the message field – the former is useful for explicitly searching/analyzing structured exception information, while the latter is Google’s expected place for the exception, and integrates with Google Error Reporting.

it would be great if this was somewhat compatible a sample message from log4j2 in GcpLayout:

{
    "timestamp": "2022-05-06T15:11:13.059Z",
    "severity": "ERROR",
    "message": "error abc due to:\nabc.def.ghi.MyException: problem specifics.\nMore details ...",
    "logging.googleapis.com/sourceLocation": {
        "function": "abc.def.ghi.MyClass.recordSendError"
    },
    "logging.googleapis.com/insertId": "1261298",
    "_exception": {
        "class": "org.apache.kafka.common.errors.TimeoutException",
        "message": "problem specifics",
        "stackTrace": "MyException: problem specifics.\nMore details ..."
    },
    "_thread": "mythread-1",
    "_logger": "abc.def.ghi.MyClass"
}

Question about traces

Hi,

First of all, thank you for your effort to have this library in quarkus.

I want to know if there is a way to customize traces. These are the traces if we set the quarkus tracing library:

{"timestamp":"2020-10......,"mdc":{"spanId":"521581a8576ba5b3","traceId":"521581a8576ba5b3","sampled":"false"}}

And I want:

{"timestamp":"2020-10-16T18:16:47.928+02:00", "correlatorId":"521581a8576ba5b3","transactionId":"521581a8576ba5b3"....}

So I want to remove "mdc" object in logs and then, rename the key names.

Is there any way to do that?

Regards.

Is this extension still active?

I just updated to Quarkus 2.8.2 and I get the below build error... So I'm guessing the extension hasn't kept up with the Quarkus updates?

2022-05-06 12:29:19,770 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkiverse.loggingjson.deployment.LoggingJsonProcessor#setUpFormatter threw an exception: java.lang.NoSuchFieldError: JACKSON
	at io.quarkiverse.loggingjson.deployment.LoggingJsonProcessor.setUpFormatter(LoggingJsonProcessor.java:33)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:925)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)

	at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:330)
	at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:252)
	at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:60)
	at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:95)
	at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:485)
	at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:68)
	at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:142)
	at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:97)
	at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:132)
	at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
Caused by: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkiverse.loggingjson.deployment.LoggingJsonProcessor#setUpFormatter threw an exception: java.lang.NoSuchFieldError: JACKSON
	at io.quarkiverse.loggingjson.deployment.LoggingJsonProcessor.setUpFormatter(LoggingJsonProcessor.java:33)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:925)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)

	at io.quarkus.builder.Execution.run(Execution.java:116)
	at io.quarkus.builder.BuildExecutionBuilder.execute(BuildExecutionBuilder.java:79)
	at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:157)
	at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:328)
	... 9 more
Caused by: java.lang.NoSuchFieldError: JACKSON
	at io.quarkiverse.loggingjson.deployment.LoggingJsonProcessor.setUpFormatter(LoggingJsonProcessor.java:33)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:925)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at java.base/java.lang.Thread.run(Thread.java:834)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)


Quarkus versions and quarkus logging versions

Apologies, if it's a basic question, I am very new to Quarkus, and immediately needed this feature, so it's one of the first things I am looking at.

I seem to be having issues getting specific versions of Quarkus working with the right version of quarkiverse logging json.
I have tried a number of permutations, but seem to get different issues depending on the combination/exclusions.

The closest I have is

implementation 'io.quarkiverse.loggingjson:quarkiverse-logging-json:0.2.3'

with Qaurkus version 1.13.7.Final.

I haven't included io.quarkus:quarkus-logging-json currently, as they seem to clash.

In short could a sample dependency set be provided that work together?

Thanks!

Produced ECS log events are invalid

I'm using quarkus-logging-json version 2.0.0 with the following config in my project:

quarkus.log.json.log-format=ecs

This produces output like:

{"@timestamp":"2022-11-18T11:44:56.862+01:00","log.logger":"io.quarkus","log.level":"INFO","process.thread.name":"Quarkus Main Thread","process.thread.id":89,"host.name":"xxx","message":"Profile dev activated. Live Coding activated.","ecs.version":"1.12.1"}

However, "log.logger" is incorrect. The ECS spec states: The document structure should be nested JSON objects. If you use Beats or Logstash, the nesting of JSON objects is done for you automatically. If you’re ingesting to Elasticsearch using the API, your fields must be nested objects, not strings containing dots.

"logger" should be nested inside a "log" object e.g.:

{"@timestamp":"2022-11-18T11:44:56.862+01:00","log":{"logger":"io.quarkus","level":"INFO"}, ...}

The current notation makes it hard / not possible to process in tools like CloudWatch.

ObjectMapper configuration

Hi!

Thanks for the answer on my previous issue, it worked nicely.

I think the extension would be more reusable if it was possible to supply own configuration of: com.fasterxml.jackson.databind.ObjectMapper

In my case usage fails with the following:

org.jboss.resteasy.spi.UnhandledException: javax.ws.rs.ProcessingException: com.fasterxml.jackson.databind.exc.InvalidFormatException:
Cannot deserialize value of type java.util.Date from String "2020-12-11T13:15:23.000 +0100": not a valid representation
(error: Failed to parse Date value '2020-12-11T13:15:23.000 +0100': Cannot parse date
"2020-12-11T13:15:23.000 +0100":
while it seems to fit format 'yyyy-MM-dd'T'HH:mm:ss.SSSX', parsing fails (leniency? null))

If I could apply my own configuration, something like this would solve my case:

@ApplicationScoped public class LogObjectMapper { @Inject ObjectMapper mapper; public ObjectMapper createForLogging() { mapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX")); } }

I think the same configuration would be nice for jsonb also.

Duplicate key in application properties YAML

What if I want to use json=false and additional fields?

In YAML I get duplicate keys error:

      json:
        additional-field:
          INDEX:
            value: "index"
          SOURCETYPE:
            value: "json"
      json: false

cannot disable certain fields

I'm trying to write a custom JsonProvider that have a completely different structure (the normal log event is encapsulated inside a versioned envelop) .

Following the advice of context is #82 I'm trying to disable all
top-level fields:

quarkus.log.console.json.fields.timestamp.enabled=false
quarkus.log.console.json.fields.sequence.enabled=false
quarkus.log.console.json.fields.loggerClassName.enabled=false
quarkus.log.console.json.fields.loggerName.enabled=false
quarkus.log.console.json.fields.level.enabled=false
quarkus.log.console.json.fields.message.enabled=false
quarkus.log.console.json.fields.threadName.enabled=false
quarkus.log.console.json.fields.threadId.enabled=false
quarkus.log.console.json.fields.processId.enabled=false
quarkus.log.console.json.fields.processName.enabled=false
quarkus.log.console.json.fields.hostname.enabled=false
quarkus.log.console.json.fields.mdc.enabled=false
quarkus.log.console.json.fields.ndc.enabled=false
quarkus.log.console.json.fields.stackTrace.enabled=false

But looks like this is not working for some of them:

{"loggerClassName":"org.jboss.logging.Logger","loggerName":"io.quarkus","threadName":"Quarkus Main Thread","threadId":61,"processName":"sample.Main","processId":50047}

Apparently there is a problem with camel case handling?

enabling file logging as well

it is possible to enable logging to a file using this library?

We tried "quarkus.log.file.json" but it not picking up this library at all. Any ideas? /cc @SlyngDK
Now we have a workaround on our side, basically defining a custom processor:

  @BuildStep
  @Record(ExecutionTime.RUNTIME_INIT)
  LogFileFormatBuildItem setUpFormatter(Capabilities capabilities, LoggingJsonRecorder recorder, Config config) {
  ...

please note the use of LogFileFormatBuildItem rather than LogConsoleFormatBuildItem to enable usage of files.

support for quarkus v 2

I tried to use 2.0.0.CR3 and invoked mvn clean install, but go an error.
Are there any plans for upgrading to v2?

Failed to execute goal io.quarkus:quarkus-maven-plugin:2.0.0.CR3:build (default) on project fip-bsf-online: Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[ERROR] [error]: Build step io.quarkiverse.loggingjson.deployment.LoggingJsonProcessor#setUpFormatter threw an exception: java.lang.NoSuchFieldError: JACKSON
[ERROR] at io.quarkiverse.loggingjson.deployment.LoggingJsonProcessor.setUpFormatter(LoggingJsonProcessor.java:33)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[ERROR] at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[ERROR] at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[ERROR] at java.base/java.lang.reflect.Method.invoke(Method.java:566)
[ERROR] at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:820)
[ERROR] at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
[ERROR] at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2442)
[ERROR] at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1476)
[ERROR] at java.base/java.lang.Thread.run(Thread.java:834)
[ERROR] at org.jboss.threads.JBossThread.run(JBossThread.java:501)

Write Log to a file

Thanks for this library.
Is there any way I can use it to write the logs to a log file? Unfortunately, Quarkus does not currently provide a way to write JSON to a log file.

Add fields via application.properties

First, i really want to thanks you for the effort to have structured logging in quarkus.

I have a question (and a possible request). Is there a way to set some constants in the log via application.properties?

something like: quarkis.logging.json."serviceName".value=test

Log:

{ serviceName: "test" , message:"message"}

Regards

Improvement of custom JsonLoggingProvider docs

Hello there,

we needed a lot of time unfortunately to figure out why our custom json provider was not used and found out eventually, that it was removed because of a quarkus optimization:

https://quarkus.io/blog/quarkus-dependency-injection/#removing-unused-beans

maybe it would be helpful to document the need to annotate the custom json provider with @unremovable in the code example or link the feature and write a sentence or two for documentation purposes :)

[Feature] Remove or rename (default) fields

It would be useful if through configuration the standard fields could be removed and renamed.

For AWS Lambda the following is logged and it would be useful to remove the clutter:

“threadName”: “main”, 
“threadId”: 1, “hostName”: 
“unknown-host.unknown-domain”, 
“processName”: “lambdainternal.AWSLambda”, 
“processId”: 9,

Also being able to rename existing fields would be useful to comply with company standard level -> logLevel

Logging JSON Objects

Hi Everyone,

I tried to do a simple logging to the request after using jackson to stringify the request. I keep getting the following errors.
It seems to be a similar issue to the link below.
https://issues.apache.org/jira/browse/LOG4J2-2949

Appreciate your help as I love this library, and would be great to use it.

Code Sample:
String requestBodyText = objectMapper.writeValueAsString(objectMapper.writeValueAsString(requestBody));
logger.log(Level.INFO, requestBodyText, kv("correlationId", correlationId));

Stack trace
LogManager error of type FORMAT_FAILURE: Formatting error

java.lang.RuntimeException: java.lang.IllegalArgumentException: can't parse argument number: "storedProcedureName":"INSERT_USER"
at io.quarkiverse.loggingjson.JsonFormatter.format(JsonFormatter.java:37)
at org.jboss.logmanager.ExtFormatter.format(ExtFormatter.java:32)
at org.jboss.logmanager.handlers.WriterHandler.doPublish(WriterHandler.java:43)
at org.jboss.logmanager.ExtHandler.publish(ExtHandler.java:66)
at org.jboss.logmanager.ExtHandler.publishToNestedHandlers(ExtHandler.java:97)
at io.quarkus.bootstrap.logging.QuarkusDelayedHandler.doPublish(QuarkusDelayedHandler.java:81)
at org.jboss.logmanager.ExtHandler.publish(ExtHandler.java:66)
at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:334)
at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:341)
at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:341)
at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:341)
at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:341)
at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:341)
at org.jboss.logmanager.Logger.logRaw(Logger.java:750)
at org.jboss.logmanager.Logger.log(Logger.java:549)
at com.ibm.dha.pda.PanoramaDataAccess.StoredProcedure(PanoramaDataAccess.java:40)
at com.ibm.dha.pda.PanoramaDataAccess_Subclass.StoredProcedure$$superforward1(Unknown Source)
at com.ibm.dha.pda.PanoramaDataAccess_Subclass$$function$$1.apply(Unknown Source)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
at io.quarkus.resteasy.runtime.QuarkusRestPathTemplateInterceptor.restMethodInvoke(QuarkusRestPathTemplateInterceptor.java:39)
at io.quarkus.resteasy.runtime.QuarkusRestPathTemplateInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:50)
at io.quarkus.micrometer.runtime.MicrometerCountedInterceptor.countedMethod(MicrometerCountedInterceptor.java:93)
at io.quarkus.micrometer.runtime.MicrometerCountedInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:50)
at io.quarkus.micrometer.runtime.MicrometerTimedInterceptor.timedMethod(MicrometerTimedInterceptor.java:78)
at io.quarkus.micrometer.runtime.MicrometerTimedInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:50)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(Unknown Source)
at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:42)
at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:33)
at com.ibm.dha.pda.PanoramaDataAccess_Subclass.StoredProcedure(Unknown Source)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:170)
at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:130)
at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:660)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:524)
at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$2(ResourceMethodInvoker.java:474)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:476)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:434)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:408)
at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:69)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:492)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
at io.quarkus.resteasy.runtime.standalone.RequestDispatcher.service(RequestDispatcher.java:73)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler.dispatch(VertxRequestHandler.java:151)
at io.quarkus.resteasy.runtime.standalone.VertxRequestHandler$1.run(VertxRequestHandler.java:91)
at io.quarkus.vertx.core.runtime.VertxCoreRecorder$14.runWith(VertxCoreRecorder.java:564)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
at org.jboss.threads.DelegatingRunnable.run(DelegatingRunnable.java:29)
at org.jboss.threads.ThreadLocalResettingRunnable.run(ThreadLocalResettingRunnable.java:29)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: can't parse argument number: "storedProcedureName":"INSERT_USER"
at java.base/java.text.MessageFormat.makeFormat(MessageFormat.java:1454)
at java.base/java.text.MessageFormat.applyPattern(MessageFormat.java:492)
at java.base/java.text.MessageFormat.(MessageFormat.java:371)
at java.base/java.text.MessageFormat.format(MessageFormat.java:860)
at org.jboss.logmanager.ExtFormatter.formatMessageLegacy(ExtFormatter.java:107)
at org.jboss.logmanager.ExtFormatter.formatMessage(ExtFormatter.java:70)
at io.quarkiverse.loggingjson.providers.MessageJsonProvider.writeTo(MessageJsonProvider.java:26)
at io.quarkiverse.loggingjson.JsonFormatter.format(JsonFormatter.java:26)
... 67 more
Caused by: java.lang.NumberFormatException: For input string: ""storedProcedureName":"INSERT_USER""
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
at java.base/java.lang.Integer.parseInt(Integer.java:668)
at java.base/java.lang.Integer.parseInt(Integer.java:786)
at java.base/java.text.MessageFormat.makeFormat(MessageFormat.java:1452)
... 74 more

default Quarkus JSON logging and quarkiverse-logging-json

Hello guys
With both dependencies: io.quarkus:quarkus-logging-json and io.quarkiverse.loggingjson:quarkiverse-logging-json it complains about

"Multiple matching properties for name "log.console.json" property was matched by both boolean io.quarkus.logging.json.runtime.JsonConfig.enable and boolean io.quarkiverse.loggingjson.Config.enable. This is likely because you have an incompatible combination of extensions that both define the same properties (e.g. including both reactive and blocking database extensions)"

I need quarkiverse-logging-json for additional fields and Structured arguments. How can I use it in parallel to default Quarkus JSON logging?

Ignore some MDC fields

Hi, I am new to this library.
I got a question:
What should I do to ignore some MDC fields when using ths library?
Is there any way to do it now?

Thanks.

TimestampJsonProvider don't implement Enabled

It would be nice if the class: TimestampJsonProvider also could implement Enabled
In order to get rid of the long timestamp format for local development.
This currently does not work:
%dev.quarkus.log.console.json.fields.timestamp.enabled=false

logger does not respect application object mapper

version:
io.quarkiverse.loggingjson:quarkus-logging-json 1.1.1 but also 3.0.0

current behaviour:
java.time.Instant is serialised as numbers, java.time.LocalDateTime is serialised as array of time components

expected behaviour:
I have an ObjectMapperCustomizer setup that writes out dates and friends as strings. The json serialiser of the logger should respect it's settings (e.g. use this instance) instead of creating its own serialiser.
I am aware of the existence of configuration properties that allow you to customize the json output, but apart from the fact that the date config (quarkus.log.json.fields.timestamp.date-format) is only for the timestamp fields, the application settings should be respected and not duplicated in config solely for logging purposes.

There is a similar ticket in #75, but the proposed solution of serialising the object itself is quite clunky and not usable/maintainable in a bigger project.

I think the project should hook up to be able to use CDI.

Critical and High Vulnerabilities reported for quarkus-logging-json in National Vulnerability Database

Hello Quarkiverse Team,
I am currently developing a project that uses the quarkus-logging-json dependency.
We have added a new plugin to our pom.xml lately (org.owasp dependency-check-maven plugin) which looks for vulnerabilities in the dependencies we use.
It turned out, there are some CRITICAL and HIGH vulnerabilities reported for quarkiverse/quarkus-logging-json.
Here is the link: https://nvd.nist.gov/vuln/search/results?form_type=Advanced&results_type=overview&search_type=all&cpe_vendor=cpe%3A%2F%3Aquarkus&cpe_product=cpe%3A%2F%3Aquarkus%3Aquarkus&cpe_version=cpe%3A%2F%3Aquarkus%3Aquarkus%3A1.1.1

I would like to ask if you have any propositions about how to proceed with the vulnerabilities ? They are reported in our Sonarqube as well.

Are you going to provide some fix versions?
Or maybe there is a way to make a fix ourselves?
I would be grateful for your answer.

Best regards,
Agata Rychter

ContextNotActiveException when using a custom LoggingProvider

Hi everyone!

I came across with an error when initializing quarkus with a pre-configured provider with a CDI dependency. Do you guys know what is the problem?

My class:

@Singleton
class JsonLoggingProvider @Inject constructor(
    private val requestId: RequestId
): JsonProvider {

    override fun writeTo(generator: JsonGenerator?, event: ExtLogRecord?) {
        generator?.writeStringField("requestId", requestId.get());
    }
}

Error:

java.lang.RuntimeException: javax.enterprise.context.ContextNotActiveException
        at io.quarkiverse.loggingjson.JsonFormatter.format(JsonFormatter.java:37)
        at org.jboss.logmanager.ExtFormatter.format(ExtFormatter.java:32)
        at org.jboss.logmanager.handlers.WriterHandler.doPublish(WriterHandler.java:43)
        at org.jboss.logmanager.ExtHandler.publish(ExtHandler.java:66)
        at org.jboss.logmanager.ExtHandler.publishToNestedHandlers(ExtHandler.java:97)
        at io.quarkus.bootstrap.logging.QuarkusDelayedHandler.doPublish(QuarkusDelayedHandler.java:73)
        at org.jboss.logmanager.ExtHandler.publish(ExtHandler.java:66)
        at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:334)
        at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:341)
        at org.jboss.logmanager.LoggerNode.publish(LoggerNode.java:341)
        at org.jboss.logmanager.Logger.logRaw(Logger.java:750)
        at org.jboss.logmanager.Logger.log(Logger.java:708)
        at org.jboss.logging.JBossLogManagerLogger.doLogf(JBossLogManagerLogger.java:53)
        at org.jboss.logging.Logger.infof(Logger.java:1125)
        at io.quarkus.bootstrap.runner.Timing.printStartupTime(Timing.java:102)
        at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:886)
        at io.quarkus.runtime.Application.start(Application.java:101)
        at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:101)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
        at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
        at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at io.quarkus.runner.bootstrap.StartupActionImpl$1.run(StartupActionImpl.java:98)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: javax.enterprise.context.ContextNotActiveException
        at io.quarkus.arc.impl.ClientProxies.getDelegate(ClientProxies.java:40)
        at com.banqi.ccbissuer.common.application.logging.RequestId_ClientProxy.arc$delegate(RequestId_ClientProxy.zig:42)
        at com.banqi.ccbissuer.common.application.logging.RequestId_ClientProxy.get(RequestId_ClientProxy.zig:99)
        at com.banqi.ccbissuer.common.application.logging.JsonLoggingProvider.writeTo(JsonLoggingProvider.kt:15)
        at com.banqi.ccbissuer.common.application.logging.JsonLoggingProvider_Subclass.writeTo$$superforward1(JsonLoggingProvider_Subclass.zig:102)
        at com.banqi.ccbissuer.common.application.logging.JsonLoggingProvider_Subclass$$function$$1.apply(JsonLoggingProvider_Subclass$$function$$1.zig:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:51)
        at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
        at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
        at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
        at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
        at com.banqi.ccbissuer.common.application.logging.JsonLoggingProvider_Subclass.writeTo(JsonLoggingProvider_Subclass.zig:172)
        at io.quarkiverse.loggingjson.JsonFormatter.format(JsonFormatter.java:26)
        ... 27 more

Quarkiverse is ignoring zone-id

Hi I tried the default quarkus json logger with: quarkus.log.console.json.zone-id=UTC and it works. When I enable quarkiverse it seems that the zone-id is ignore.

Looking at the configs: https://github.com/quarkiverse/quarkiverse-logging-json/blob/master/runtime/src/main/java/io/quarkiverse/loggingjson/Config.java

It seems missing or is it supposed to inherit it?

Cannot resolve method 'info(java.lang.String, io.quarkiverse.loggingjson.providers.StructuredArgument)'

When I'm trying to use example

import static io.quarkiverse.loggingjson.providers.KeyValueStructuredArgument.*;
...
log.info("Test log of structured arg", kv("key", "value"));

from readme, I see the following error:
Cannot resolve method 'info(java.lang.String, io.quarkiverse.loggingjson.providers.StructuredArgument)'

What am I doing wrong?

My example:

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.smallrye.health.SmallRyeHealthReporter;
import io.smallrye.mutiny.Uni;
import org.jboss.logging.Logger;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

import static io.quarkiverse.loggingjson.providers.KeyValueStructuredArgument.kv;

@Path("/custom-health")
public class CustomHC {

    @Inject
    Logger log;

    @Inject
    SmallRyeHealthReporter smallRyeHealthReporter;

    @GET
    @Path("/health")
    public Uni<Response> reportHealth() {
        return smallRyeHealthReporter.getHealthAsync().onItem().transform(health -> {
            log.info("Test log of structured arg", kv("key", "value"));
            ObjectMapper objectMapper = new ObjectMapper();

            ObjectNode objectNode = null;
            try {
                objectNode = objectMapper.readValue(health.getPayload().toString(), ObjectNode.class);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
            objectNode.put("customKey", "customValue");

            return Response.ok(objectNode).build();
        });

    }
}

changing date-format doesn't work

I'm trying to change date-format in logs.
I want to use such pattern:

  • format - yyyy-MM-dd'T'HH:mm:ss.SSSZZ
  • timezone - UTC
    Required example:
    2021-12-14T21:58:59.129Z

application.yml:

quarkus:
  log:
    console:
      json:
        fields:
          timestamp:
            enabled: true
              date-format: "yyyy-MM-dd'T'HH:mm:ss.SSSZZ"
              zone-id: UTC

But in logs I still see 2021-12-14T22:08:16.016+0000
What am I doing wrong?

Exclude keys from log

Hi!

How can one exclude certain keys from the log?

I tried quarkus.log.console.json.excluded-keys but that didn't work out.

Complex transformations

@gsmet hello :)

Let's discuss here (quarkusio/quarkus#15193):

In our quarkus apps we are required to provide additional metadata for every log event.

Example
Given the following payload [1]:

{
  "timestamp":"2021-02-19T18:00:53Z",
  "sequence":3219,
  "loggerClassName":"database.BlockCacheBuilder",
  "loggerName":"BlockCacheBuilder",
  "level":"INFO",
  "logMessage":"Block cache: Creating Clock Cache with 2147483648 capacity",
  "threadName":"executor-thread-1",
  "threadId":71,
  "mdc":{},
  "ndc":"",
  "hostName":"n36771",
  "processName":"MyApplication",
  "processId":22208
}

the requirement would be to enrich it with:

{
  "EventObject":"1.2",
  "eventTimestamp":"2021-02-19T18:00:53Z",
  "header":{"eventCategory":"SEC","eventMessage":"Security event","severityLevel":"INFO"},
  "product":{"productName":"MyApp","applicationId":"A0666","componentId":"A0666.001","productVersion":"15.1.3-SNAPSHOT","productVendor":"SIX"}, <--- product configuration in application.yaml
  "origin":{"environment":"prod","hostname":"n36771","processId":"22208","threadId":"71"}, <-- hostname is coming from payload (org.jboss.logmanager.formatters.StructuredFormatter)
  "eventPayload": <--- literal payload here (see [1]) 
}

Would be possible to achieve this by using this library?
Additional requirements are:

  • ability to rename log levels: "SEVERE" -> "ERROR", "WARN" -> "WARNING"
  • copy some attributes from the event payload to the external message

level_value field

Does exist any way to add field with numerical value of log level?
I need something like:

  • INFO - 20000
  • WARN - 30000
  • ERROR - 40000

{"level": "INFO", "level-value": 20000, ....}

Create AsciiDoc

Create documentation in asciidoc for use on the quarkiverse documentation site.

How do we add the extension to a project?

Hi using the latest Quarkus 1.9CR1

I tried to run...

./gradlew addExtension --extensions="quarkiverse-logging-json"

But it's not adding the extension.

I guess we just add the extension manually?

Unable to create new CustomLogHandler

Hi

from readme.md adding new CustomLogHandler for creating new field looks easy.
But, when I add quarkus-logging-json dependency, there is no "io.quarkiverse.loggingjson.JsonProvider" interface available.

quarkus version is currently 2.9.2.FINAL, we will be upgrading soon, but not sure if that is relevant to this.

How do we change the field names?

I tried the below combinations...

quarkus.log.console.json.timestamp.fieldName=foo
quarkus.log.console.json.timestamp.field-name=foo

But neither worked

If you tell me, I'm willing to help you document it on the README unless you want to do it?

Support structured access log

Similar to logback-access, provide structured access logs with important access log parameters as separate JSON fields (e.g. request URI, method, response status code, duration ...)

Support additional json encoders/formatters

I'm trying to implement ECS formatting and haven't found a way to do it using quarkus. ECS is becoming a standard format for many enterprises and I was wondering how difficult it would be to implement it in your plugin?

I was able to format the ExtLogRecord using the ECS library like this but this doesn't replace the whole log entry, it adds a new field:

import co.elastic.logging.jboss.logmanager.EcsFormatter;
import io.quarkiverse.loggingjson.JsonProvider;
import io.quarkiverse.loggingjson.JsonGenerator;
import org.jboss.logmanager.ExtLogRecord;

@Singleton
public class MyJsonProvider implements JsonProvider {

    @Override
    public void writeTo(JsonGenerator generator, ExtLogRecord event) throws IOException {
        var ecsFormatter = new EcsFormatter();
        generator.writeStringField("testingxxx", ecsFormatter.format(event));
    }
}

Just add this dependency:

        <dependency>
            <groupId>co.elastic.logging</groupId>
            <artifactId>jboss-logmanager-ecs-formatter</artifactId>
            <version>1.1.0</version>
        </dependency>

Any suggestions?

Document changes for new releases

I updated from 1.1.1 to 2.0.0 and then started to receive many "Unrecognized configuration key" warnings.

I realized that there was a change in configuration properties base path from "log.console.json" to "log.json" so I had to update all my configuration properties.

It would be very helpful if this kind of changes are documented in the release notes.

Update README

The README points to package io.quarkus.logging.json.structured when in fact should point to io.quarkiverse.loggingjson.providers

possible race condition in JsonFormatter?

In our application occasionally we have random characters at beginning of each log:

image

this is typically happening when the logs are coming from different threads.

A quick look in the JsonFormatter showed that there is a field:

  private final StringBuilderWriter writer = new StringBuilderWriter();

Debugger showed that the JsonFormatter is a singleton within the our application, so every thread is writing/clearing this single buffer causing these issues?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.