From 8f9894c9ef40ed1a2bb690e2453eab3ae4fb85e0 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Mon, 3 Jun 2024 14:22:40 +0200 Subject: [PATCH] ? --- .../almond/VariableInspectorApiImpl.scala | 6 +++--- .../src/main/scala/almond/ScalaKernel.scala | 2 +- .../channels/zeromq/ZeromqSocketImpl.scala | 18 ++++++++++-------- .../interpreter/input/InputManager.scala | 2 +- .../messagehandlers/MessageHandler.scala | 2 +- .../src/main/scala/almond/kernel/Kernel.scala | 2 +- .../logger/internal/PrintStreamLogger.scala | 17 +---------------- .../scala/almond/testkit/ClientStreams.scala | 4 ++-- 8 files changed, 20 insertions(+), 33 deletions(-) diff --git a/modules/scala/scala-interpreter/src/main/scala/almond/VariableInspectorApiImpl.scala b/modules/scala/scala-interpreter/src/main/scala/almond/VariableInspectorApiImpl.scala index 702d88a61..7fc8e4c71 100644 --- a/modules/scala/scala-interpreter/src/main/scala/almond/VariableInspectorApiImpl.scala +++ b/modules/scala/scala-interpreter/src/main/scala/almond/VariableInspectorApiImpl.scala @@ -106,9 +106,9 @@ private object VariableInspectorApiImpl { ) .map(_.render) .mkString - .replaceAll(java.util.regex.Pattern.quote("(") + "\n\\s+", "(") - .replaceAll("\n\\s+", " ") - .replaceAll("\n", " ") + .replaceAll(java.util.regex.Pattern.quote("(") + "\r?\n\\s+", "(") + .replaceAll("\r?\n\\s+", " ") + .replaceAll("\r?\n", " ") }, varType = tprint.render(TPrintColors.BlackWhite).render, isMatrix = false, diff --git a/modules/scala/scala-kernel/src/main/scala/almond/ScalaKernel.scala b/modules/scala/scala-kernel/src/main/scala/almond/ScalaKernel.scala index e24f0c55b..d7f8cb5b3 100644 --- a/modules/scala/scala-kernel/src/main/scala/almond/ScalaKernel.scala +++ b/modules/scala/scala-kernel/src/main/scala/almond/ScalaKernel.scala @@ -115,7 +115,7 @@ object ScalaKernel extends CaseApp[Options] { case (trigger, auto) => Seq("Auto dependency:", s" Trigger: $trigger") ++ auto.map(dep => s" Adds: $dep") } - .mkString("\n") + .mkString(System.lineSeparator()) ) val interpreterEc = singleThreadedExecutionContext("scala-interpreter") diff --git a/modules/shared/channels/src/main/scala/almond/channels/zeromq/ZeromqSocketImpl.scala b/modules/shared/channels/src/main/scala/almond/channels/zeromq/ZeromqSocketImpl.scala index 2ff96a128..40e859c37 100644 --- a/modules/shared/channels/src/main/scala/almond/channels/zeromq/ZeromqSocketImpl.scala +++ b/modules/shared/channels/src/main/scala/almond/channels/zeromq/ZeromqSocketImpl.scala @@ -138,20 +138,21 @@ final class ZeromqSocketImpl( ensureOpened() - log.debug( - "Sending:\n" + + log.debug { + val nl = System.lineSeparator() + "Sending:" + nl + " header: " + Try(new String(message.header, "UTF-8")) .toOption .getOrElse(message.header.toString) + - "\n" + + nl + " content: " + Try(new String(message.content, "UTF-8")) .toOption .getOrElse(message.content.toString) + - "\n" + + nl + " idents: " + identsAsStrings(message.idents) - ) + } for (c <- message.idents) channel.send(c.toArray, ZMQ.SNDMORE) @@ -196,17 +197,18 @@ final class ZeromqSocketImpl( if (expectedSignature == signature || !enableMac) { log.debug { + val nl = System.lineSeparator() val headerStr = Try(new String(message.header, UTF_8)) .getOrElse(message.header.toString) - s"Received on $uri:\n" + + s"Received on $uri:" + nl + " header: " + headerStr + - "\n" + + nl + " content: " + Try(new String(message.content, "UTF-8")) .toOption .getOrElse(message.content.toString) + - "\n" + + nl + " idents: " + identsAsStrings(message.idents) } Some(message) diff --git a/modules/shared/interpreter/src/main/scala/almond/interpreter/input/InputManager.scala b/modules/shared/interpreter/src/main/scala/almond/interpreter/input/InputManager.scala index 9657935cf..80ea8e600 100644 --- a/modules/shared/interpreter/src/main/scala/almond/interpreter/input/InputManager.scala +++ b/modules/shared/interpreter/src/main/scala/almond/interpreter/input/InputManager.scala @@ -49,7 +49,7 @@ object InputManager { res match { case Success(value) => - val b0 = ByteBuffer.wrap((value + "\n").getBytes(UTF_8)).asReadOnlyBuffer() + val b0 = ByteBuffer.wrap((value + System.lineSeparator()).getBytes(UTF_8)).asReadOnlyBuffer() bufferOpt = Some(b0) case Failure(_: NoMoreInputException) => done = true diff --git a/modules/shared/interpreter/src/main/scala/almond/interpreter/messagehandlers/MessageHandler.scala b/modules/shared/interpreter/src/main/scala/almond/interpreter/messagehandlers/MessageHandler.scala index 487e27628..1d1605331 100644 --- a/modules/shared/interpreter/src/main/scala/almond/interpreter/messagehandlers/MessageHandler.scala +++ b/modules/shared/interpreter/src/main/scala/almond/interpreter/messagehandlers/MessageHandler.scala @@ -53,7 +53,7 @@ final case class MessageHandler( ): Option[Stream[IO, (Channel, RawMessage)]] = handle(channel, message).map { case Left(e) => - log.error(s"Ignoring error decoding message\n$message", e) + log.error(s"Ignoring error decoding message${System.lineSeparator()}$message", e) Stream.empty case Right(s) => s } diff --git a/modules/shared/kernel/src/main/scala/almond/kernel/Kernel.scala b/modules/shared/kernel/src/main/scala/almond/kernel/Kernel.scala index 691a8a80d..ae43db509 100644 --- a/modules/shared/kernel/src/main/scala/almond/kernel/Kernel.scala +++ b/modules/shared/kernel/src/main/scala/almond/kernel/Kernel.scala @@ -127,7 +127,7 @@ final case class Kernel( immediateHandlers.handleOrLogError(channel, rawMessage, log) match { case None => - log.warn(s"Ignoring unhandled message on $channel:\n$rawMessage") + log.warn(s"Ignoring unhandled message on $channel:${System.lineSeparator()}$rawMessage") IO.unit case Some(output) => diff --git a/modules/shared/logger/src/main/scala/almond/logger/internal/PrintStreamLogger.scala b/modules/shared/logger/src/main/scala/almond/logger/internal/PrintStreamLogger.scala index 67815fd0f..176a251b6 100644 --- a/modules/shared/logger/src/main/scala/almond/logger/internal/PrintStreamLogger.scala +++ b/modules/shared/logger/src/main/scala/almond/logger/internal/PrintStreamLogger.scala @@ -5,8 +5,6 @@ import java.lang.management.ManagementFactory import almond.logger.Level -import scala.annotation.tailrec - final class PrintStreamLogger( val level: Level, out: PrintStream, @@ -33,21 +31,8 @@ final class PrintStreamLogger( b += ' ' b ++= message - @tailrec - def addException(ex: Throwable): Unit = - if (ex != null) { - b += '\n' // FIXME Not portable - b ++= ex.toString - for (elem <- ex.getStackTrace) { - b ++= "\n " // FIXME Not portable - b ++= elem.toString - } - addException(ex.getCause) - } - - addException(exception) - out.println(b.result()) + exception.printStackTrace(out) } } diff --git a/modules/shared/test-kit/src/main/scala/almond/testkit/ClientStreams.scala b/modules/shared/test-kit/src/main/scala/almond/testkit/ClientStreams.scala index c4f314d4f..5e15da696 100644 --- a/modules/shared/test-kit/src/main/scala/almond/testkit/ClientStreams.scala +++ b/modules/shared/test-kit/src/main/scala/almond/testkit/ClientStreams.scala @@ -36,7 +36,7 @@ final case class ClientStreams( case Right((`channel`, m)) => m.decodeAs[T] match { case Left(err) => - throw new Exception(s"Error decoding message: $err\n$m") + throw new Exception(s"Error decoding message: $err${System.lineSeparator()}$m") case Right(m0) => m0 } @@ -58,7 +58,7 @@ final case class ClientStreams( case Left((`channel`, m)) if m.header.msg_type == msgType.messageType => m.decodeAs[T] match { case Left(err) => - throw new Exception(s"Error decoding message: $err\n$m") + throw new Exception(s"Error decoding message: $err${System.lineSeparator()}$m") case Right(m0) => m0 }