eclipse-apoapsis / ort-server

A scalable server implementation of the OSS Review Toolkit.
Apache License 2.0
14 stars 6 forks source link

Print all log output on one line #571

Open mmurto opened 3 days ago

mmurto commented 3 days ago

Log aggregators often process logs line by line. Most of the ORT Server's log calls seem to be on one line, but exception stacktraces are not:

2024-07-02 11:13:02.210 [pool-1-thread-4] level=INFO  o.e.a.o.transport.MessagePublisher - Sending 'ReporterWorkerError' message to 'OrchestratorEndpoint'. TraceID: 'b93fa9cf-525b-437b-ad44-c2dd61030186'. 
  ... 14 common frames omitted
  at org.eclipse.apoapsis.ortserver.config.local.LocalConfigFileProvider.getFile-JbEZD94(LocalConfigFileProvider.kt:63) |  
  at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157) |  
  at java.base/java.io.FileInputStream.open(FileInputStream.java:216) |  
  at java.base/java.io.FileInputStream.open0(Native Method) |  
  Caused by: java.io.FileNotFoundException: /mnt/config/reporter.how-to-fix-text-provider.kts (No such file or directory) |  
  at java.base/java.lang.Thread.run(Thread.java:840) |  
  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) |  
  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) |  
  at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:111) |  
  at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149) |  
  at org.eclipse.apoapsis.ortserver.transport.rabbitmq.RabbitMqMessageReceiverFactory$createConsumer$1.handleDelivery(RabbitMqMessageReceiverFactory.kt:125) |  
  at org.eclipse.apoapsis.ortserver.workers.reporter.ReporterComponent.endpointHandler$lambda$2(ReporterComponent.kt:101) |  
  at org.eclipse.apoapsis.ortserver.workers.reporter.ReporterWorker.run(ReporterWorker.kt:74) |  
  at org.eclipse.apoapsis.ortserver.workers.reporter.ReporterRunner.run(ReporterRunner.kt:159) |  
  at org.eclipse.apoapsis.ortserver.config.ConfigManager.getFileAsString-eAavqeE(ConfigManager.kt:184) |  
  at org.eclipse.apoapsis.ortserver.config.ConfigManager.getFile-eAavqeE(ConfigManager.kt:177) |  
  at org.eclipse.apoapsis.ortserver.config.ConfigManagerKt.access$wrapExceptions(ConfigManager.kt:1) |  
  at org.eclipse.apoapsis.ortserver.config.ConfigManagerKt.wrapExceptions(ConfigManager.kt:271) |  
  at org.eclipse.apoapsis.ortserver.config.ConfigManager.getFile_eAavqeE$lambda$2(ConfigManager.kt:177) |  
  at org.eclipse.apoapsis.ortserver.config.local.LocalConfigFileProvider.getFile-JbEZD94(LocalConfigFileProvider.kt:65) |  
  org.eclipse.apoapsis.ortserver.config.ConfigException: Cannot read path 'reporter.how-to-fix-text-provider.kts'.

These would be easier to process and debug if they were on one line as well.

mnonnenmacher commented 3 days ago

Stacktraces without line breaks are hardly readable, could the solution be to log JSON instead of plain text?

mmurto commented 3 days ago

JSON for all logging would be even better!

sschuberth commented 3 days ago

I'm surprised that the logger does not automatically prefix stacktrace lines if an exception is passed to the logger call.

sschuberth commented 1 day ago

Actually, the above example seems to not come from a case where the logger takes an exception, but a plain uncaught exception being thrown (coincidentally preceded by a log message).

mmurto commented 1 day ago

Actually, the above example seems to not come from a case where the logger takes an exception, but a plain uncaught exception being thrown (coincidentally preceded by a log message).

There could be a way to override all logging with the chosen format, which would uncaught exceptions and log those to JSON as well. Something like this maybe.

sschuberth commented 1 day ago

uncaught exceptions and log those

The emphasis is "uncaught". If exception are uncaught, they're also not intercepted in order to log them, but instead the JVM will just print the stacktrace to stderr, bypassing any logger.

We could probably use an UncaughtExceptionHandler and log from there, but I'm not sure whether that's really worth the effort.