Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(core): support scala native + enabled JS tests #909

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
with:
fetch-depth: '0'
- name: Compile additional subprojects
run: sbt ++${{ matrix.scala }} examplesCore/compile examplesJpl/compile examplesJulBridge/compile examplesSlf4j2Bridge/compile examplesSlf4jLogback/compile examplesSlf4j2Logback/compile examplesSlf4j2Log4j/compile benchmarks/compile
run: sbt ++${{ matrix.scala }} examplesCoreJVM/compile examplesCoreJS/compile examplesCoreNative/compile examplesJpl/compile examplesJulBridge/compile examplesSlf4j2Bridge/compile examplesSlf4jLogback/compile examplesSlf4j2Logback/compile examplesSlf4j2Log4j/compile benchmarks/compile
update-readme:
name: Update README
runs-on: ubuntu-22.04
Expand Down
4 changes: 4 additions & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-XX:+PrintCommandLineFlags
-Xss2m
-Xmx6g
-XX:+UseG1GC
39 changes: 30 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ inThisBuild(
List(
name := "zio-logging",
ciEnabledBranches := Seq("master"),
// ciJvmOptions ++= Seq("-Xmx6g", "-Xss2m", "-XX:+UseG1GC"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this some leftover ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is was rendered in the ci.yaml but not properly picked up in the job. If you check the jobs here then you will see it was picked up but later in the job it still seemed to have only the default 1GB of memory: https://github.com/zio/zio-logging/actions/runs/11993647760/job/33434815940
So for now I added a .jvmopts file to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the commented out part there so it can be fixed. I am not sure where it goes wrong. It prints NOTE: Picked up JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags -Xmx6G -Xss2M -XX:+UseG1GC -XX:G1ConcRefinementThreads=4 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=1073741824 -XX:MaxHeapSize=1073741824 -XX:+PrintCommandLineFlags -XX:ReservedCodeCacheSize=134217728 -XX:ThreadStackSize=4096 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC which shows different InitialHeapSize and MaxHeapSize than the passed Xmx.
Locally I have the same issue. I am a bit puzzeled here. With the .jvmopts it is fine.

ciTestJobs := ciTestJobs.value.map(ciJobWithSetup) :+ compileExamplesJob.value,
ciLintJobs := ciLintJobs.value.map(ciJobWithSetup),
ciBuildJobs := ciBuildJobs.value.map(ciJobWithSetup),
Expand Down Expand Up @@ -50,14 +51,17 @@ lazy val root = project
.aggregate(
coreJVM,
coreJS,
coreNative,
slf4j,
slf4j2,
slf4jBridge,
slf4j2Bridge,
jpl,
julBridge,
benchmarks,
examplesCore,
examplesCoreJVM,
examplesCoreJS,
examplesCoreNative,
examplesJpl,
examplesJulBridge,
examplesSlf4j2Bridge,
Expand All @@ -67,7 +71,7 @@ lazy val root = project
docs
)

lazy val core = crossProject(JSPlatform, JVMPlatform)
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("core"))
.settings(stdSettings(Some("zio-logging"), turnCompilerWarningIntoErrors = false))
Expand All @@ -84,9 +88,16 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
mimaSettings(failOnProblem = true)
)

lazy val coreJVM = core.jvm
lazy val coreJS = core.js.settings(
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion % Test
lazy val coreJVM = core.jvm
lazy val coreJS = core.js.settings(
libraryDependencies ++= Seq(
"io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion,
"io.github.cquiroz" %%% "scala-java-time-tzdb" % scalaJavaTimeVersion,
("org.scala-js" %%% "scalajs-java-securerandom" % "1.0.0" % Test).cross(CrossVersion.for3Use2_13)
)
)
lazy val coreNative = core.native.settings(
libraryDependencies += "io.github.cquiroz" %%% "scala-java-time" % scalaJavaTimeVersion
)

lazy val slf4j = project
Expand Down Expand Up @@ -180,19 +191,29 @@ lazy val benchmarks = project
.dependsOn(coreJVM)
.enablePlugins(JmhPlugin)

lazy val examplesCore = project
lazy val examplesCore = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Full)
.in(file("examples/core"))
.dependsOn(coreJVM)
.dependsOn(core % "compile->compile;test->test")
.settings(stdSettings(Some("zio-logging-examples-core"), turnCompilerWarningIntoErrors = false))
.settings(enableZIO())
.settings(
publish / skip := true,
publish / skip := true
)

lazy val examplesCoreJVM = examplesCore.jvm
.settings(
libraryDependencies ++= Seq(
"dev.zio" %% "zio-metrics-connectors-prometheus" % zioMetricsConnectorsVersion,
"dev.zio" %% "zio-http" % zioHttp,
"dev.zio" %% "zio-config-typesafe" % zioConfig
)
)
lazy val examplesCoreJS = examplesCore.js
.settings(
scalaJSUseMainModuleInitializer := true
)
lazy val examplesCoreNative = examplesCore.native

lazy val examplesSlf4jLogback = project
.in(file("examples/slf4j-logback"))
Expand Down Expand Up @@ -280,7 +301,7 @@ lazy val compileExamplesJob = Def.setting {
SingleStep(
name = "Compile additional subprojects",
run = Some(
"sbt ++${{ matrix.scala }} examplesCore/compile examplesJpl/compile examplesJulBridge/compile " +
"sbt ++${{ matrix.scala }} examplesCoreJVM/compile examplesCoreJS/compile examplesCoreNative/compile examplesJpl/compile examplesJulBridge/compile " +
"examplesSlf4j2Bridge/compile examplesSlf4jLogback/compile examplesSlf4j2Logback/compile " +
"examplesSlf4j2Log4j/compile benchmarks/compile"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2019-2024 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package zio.logging

private[logging] trait LoggingPackagePlatformSpecific
170 changes: 170 additions & 0 deletions core/jvm-native/src/main/scala/zio/logging/FileLoggerLayers.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
/*
* Copyright 2019-2024 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package zio.logging

import zio.{ Config, NonEmptyChunk, Queue, Runtime, Scope, UIO, ZIO, ZLayer, ZLogger }

import java.nio.charset.Charset
import java.nio.file.Path

private[logging] trait FileLoggerLayers {

def fileAsyncJsonLogger(config: FileLoggerConfig): ZLayer[Any, Nothing, Unit] =
makeFileAsyncJsonLogger(config).installUnscoped

def fileAsyncJsonLogger(configPath: NonEmptyChunk[String] = loggerConfigPath): ZLayer[Any, Config.Error, Unit] =
FileLoggerConfig.load(configPath).flatMap(makeFileAsyncJsonLogger).installUnscoped

def fileAsyncLogger(config: FileLoggerConfig): ZLayer[Any, Nothing, Unit] =
makeFileAsyncLogger(config).installUnscoped

def fileAsyncLogger(configPath: NonEmptyChunk[String] = loggerConfigPath): ZLayer[Any, Config.Error, Unit] =
FileLoggerConfig.load(configPath).flatMap(makeFileAsyncLogger).installUnscoped

def fileJsonLogger(config: FileLoggerConfig): ZLayer[Any, Nothing, Unit] =
makeFileJsonLogger(config).install

def fileJsonLogger(configPath: NonEmptyChunk[String] = loggerConfigPath): ZLayer[Any, Config.Error, Unit] =
FileLoggerConfig.load(configPath).flatMap(makeFileJsonLogger).install

def fileLogger(config: FileLoggerConfig): ZLayer[Any, Nothing, Unit] =
makeFileLogger(config).install

def fileLogger(configPath: NonEmptyChunk[String] = loggerConfigPath): ZLayer[Any, Config.Error, Unit] =
FileLoggerConfig.load(configPath).flatMap(makeFileLogger).install

def makeFileAsyncJsonLogger(config: FileLoggerConfig): ZIO[Scope, Nothing, FilteredLogger[String, Any]] =
makeFileAsyncLogger(
config.destination,
config.format.toJsonLogger,
config.charset,
config.autoFlushBatchSize,
config.bufferedIOSize,
config.rollingPolicy
).filter(config.toFilter)

def makeFileAsyncLogger(config: FileLoggerConfig): ZIO[Scope, Nothing, FilteredLogger[String, Any]] =
makeFileAsyncLogger(
config.destination,
config.format.toLogger,
config.charset,
config.autoFlushBatchSize,
config.bufferedIOSize,
config.rollingPolicy
).filter(config.toFilter)

def makeFileAsyncLogger(
destination: Path,
logger: ZLogger[String, String],
charset: Charset,
autoFlushBatchSize: Int,
bufferedIOSize: Option[Int],
rollingPolicy: Option[FileLoggerConfig.FileRollingPolicy]
): ZIO[Scope, Nothing, ZLogger[String, Any]] =
for {
queue <- Queue.bounded[UIO[Any]](1000)
_ <- queue.take.flatMap(task => task.ignore).forever.forkScoped
} yield fileWriterAsyncLogger(
destination,
logger,
charset,
autoFlushBatchSize,
bufferedIOSize,
queue,
rollingPolicy
)

private def fileWriterAsyncLogger(
destination: Path,
logger: ZLogger[String, String],
charset: Charset,
autoFlushBatchSize: Int,
bufferedIOSize: Option[Int],
queue: Queue[UIO[Any]],
rollingPolicy: Option[FileLoggerConfig.FileRollingPolicy]
): ZLogger[String, Any] = {
val logWriter =
new zio.logging.internal.FileWriter(destination, charset, autoFlushBatchSize, bufferedIOSize, rollingPolicy)

val stringLogger: ZLogger[String, Any] = logger.map { (line: String) =>
zio.Unsafe.unsafe { implicit u =>
Runtime.default.unsafe.run(queue.offer(ZIO.succeed {
try logWriter.writeln(line)
catch {
case t: VirtualMachineError => throw t
case _: Throwable => ()
}
}))
}
}
stringLogger
}

def makeFileJsonLogger(config: FileLoggerConfig): ZIO[Any, Nothing, FilteredLogger[String, Any]] =
makeFileLogger(
config.destination,
config.format.toJsonLogger,
config.charset,
config.autoFlushBatchSize,
config.bufferedIOSize,
config.rollingPolicy
).filter(config.toFilter)

def makeFileLogger(config: FileLoggerConfig): ZIO[Any, Nothing, FilteredLogger[String, Any]] =
makeFileLogger(
config.destination,
config.format.toLogger,
config.charset,
config.autoFlushBatchSize,
config.bufferedIOSize,
config.rollingPolicy
).filter(config.toFilter)

def makeFileLogger(
destination: Path,
logger: ZLogger[String, String],
charset: Charset,
autoFlushBatchSize: Int,
bufferedIOSize: Option[Int],
rollingPolicy: Option[FileLoggerConfig.FileRollingPolicy]
): ZIO[Any, Nothing, ZLogger[String, Any]] =
ZIO.succeed(
fileWriterLogger(destination, logger, charset, autoFlushBatchSize, bufferedIOSize, rollingPolicy)
)

private def fileWriterLogger(
destination: Path,
logger: ZLogger[String, String],
charset: Charset,
autoFlushBatchSize: Int,
bufferedIOSize: Option[Int],
rollingPolicy: Option[FileLoggerConfig.FileRollingPolicy]
): ZLogger[String, Any] = {
val logWriter =
new zio.logging.internal.FileWriter(destination, charset, autoFlushBatchSize, bufferedIOSize, rollingPolicy)

val stringLogger: ZLogger[String, Any] = logger.map { (line: String) =>
try logWriter.writeln(line)
catch {
case t: VirtualMachineError => throw t
case _: Throwable => ()
}
}

stringLogger
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright 2019-2024 John A. De Goes and the ZIO Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package zio.logging

private[logging] trait LoggingPackagePlatformSpecific extends FileLoggerLayers
8 changes: 4 additions & 4 deletions core/shared/src/main/scala/zio/logging/LogFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ sealed trait LogFormat { self =>
* the log output is highlighted.
*/
final def highlight: LogFormat =
highlight(defaultHighlighter)
highlight(LogFormat.defaultHighlighter)

/**
* The alphanumeric version of the `|-|` operator.
Expand Down Expand Up @@ -164,6 +164,9 @@ sealed trait LogFormat { self =>
)
builder.toString()
}
}

object LogFormat {

private val defaultHighlighter: LogLevel => LogColor = {
case LogLevel.Error => LogColor.RED
Expand All @@ -172,9 +175,6 @@ sealed trait LogFormat { self =>
case LogLevel.Debug => LogColor.GREEN
case _ => LogColor.WHITE
}
}

object LogFormat {

private[logging] def makeLogger(
fn: (
Expand Down
Loading
Loading