diff --git a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceAlreadyInitializedException.scala b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceAlreadyInitializedException.scala new file mode 100644 index 0000000000..29ffeaef25 --- /dev/null +++ b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceAlreadyInitializedException.scala @@ -0,0 +1,7 @@ +package org.enso.loggingservice + +case class LoggingServiceAlreadyInitializedException() + extends RuntimeException( + "The logging service was already initialized. " + + "If it should be restarted, it should be torn down first." + ) diff --git a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceManager.scala b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceManager.scala index bb8ded70f4..4ce14956f0 100644 --- a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceManager.scala +++ b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceManager.scala @@ -1,7 +1,7 @@ package org.enso.loggingservice -import org.enso.loggingservice.internal.service.{Client, Local, Server, Service} import org.enso.loggingservice.internal._ +import org.enso.loggingservice.internal.service.{Client, Local, Server, Service} import org.enso.loggingservice.printers.{Printer, StderrPrinter} import scala.concurrent.{ExecutionContext, Future} @@ -168,9 +168,7 @@ object LoggingServiceManager { ): InitializationResult = { this.synchronized { if (currentService.isDefined) { - throw new IllegalStateException( - "The logging service has already been set up." - ) + throw new LoggingServiceAlreadyInitializedException() } val (service, result): (Service, InitializationResult) = mode match { diff --git a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceSetupHelper.scala b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceSetupHelper.scala index d141fd0111..738845bf24 100644 --- a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceSetupHelper.scala +++ b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/LoggingServiceSetupHelper.scala @@ -11,8 +11,8 @@ import org.enso.loggingservice.printers.{ StderrPrinterWithColors } -import scala.concurrent.{Await, ExecutionContext, Future, Promise} import scala.concurrent.duration.DurationInt +import scala.concurrent.{Await, ExecutionContext, Future, Promise} import scala.util.control.NonFatal import scala.util.{Failure, Success} @@ -145,6 +145,12 @@ abstract class LoggingServiceSetupHelper(implicit LoggingServiceManager .setup(LoggerMode.Server(createPrinters()), logLevel) .onComplete { + case Failure(LoggingServiceAlreadyInitializedException()) => + logger.warn( + "Failed to initialize the logger because the logging service " + + "was already initialized." + ) + loggingServiceEndpointPromise.trySuccess(None) case Failure(exception) => logger.error( s"Failed to initialize the logging service server: $exception", @@ -158,6 +164,12 @@ abstract class LoggingServiceSetupHelper(implicit logLevel ) .onComplete { + case Failure(LoggingServiceAlreadyInitializedException()) => + logger.warn( + "Failed to initialize the fallback logger because the " + + "logging service was already initialized." + ) + loggingServiceEndpointPromise.trySuccess(None) case Failure(fallbackException) => System.err.println( s"Failed to initialize the fallback logger: " + diff --git a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/internal/service/ServiceWithActorSystem.scala b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/internal/service/ServiceWithActorSystem.scala index 151cbd7a7e..211ffa4ff3 100644 --- a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/internal/service/ServiceWithActorSystem.scala +++ b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/internal/service/ServiceWithActorSystem.scala @@ -40,7 +40,7 @@ trait ServiceWithActorSystem extends Service { val loggers: java.lang.Iterable[String] = Seq("akka.event.Logging$StandardOutLogger").asJava val config = ConfigFactory - .load() + .empty() .withValue("akka.loggers", ConfigValueFactory.fromAnyRef(loggers)) .withValue( "akka.logging-filter", @@ -51,6 +51,7 @@ trait ServiceWithActorSystem extends Service { "akka.coordinated-shutdown.run-by-actor-system-terminate", ConfigValueFactory.fromAnyRef("off") ) + .withValue("akka.daemonic", ConfigValueFactory.fromAnyRef("on")) ActorSystem( name, config, diff --git a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/internal/service/ThreadProcessingService.scala b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/internal/service/ThreadProcessingService.scala index 1fe2521148..8e3a9ca144 100644 --- a/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/internal/service/ThreadProcessingService.scala +++ b/lib/scala/logging-service/src/main/scala/org/enso/loggingservice/internal/service/ThreadProcessingService.scala @@ -1,11 +1,11 @@ package org.enso.loggingservice.internal.service import org.enso.loggingservice.LogLevel +import org.enso.loggingservice.internal.protocol.WSLogMessage import org.enso.loggingservice.internal.{ BlockingConsumerMessageQueue, InternalLogger } -import org.enso.loggingservice.internal.protocol.WSLogMessage import scala.util.control.NonFatal @@ -47,6 +47,8 @@ trait ThreadProcessingService extends Service { } val thread = new Thread(() => runQueue()) + thread.setName("logging-service-processing-thread") + thread.setDaemon(true) queueThread = Some(thread) thread.start() }