Skip to content

Commit

Permalink
Merge branch 'main' of github.com:typelevel/log4cats into js-console-…
Browse files Browse the repository at this point in the history
…logger
  • Loading branch information
bpholt committed Dec 5, 2022
2 parents a5f2972 + fe7cf88 commit 7d5e8a7
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 39 deletions.
60 changes: 30 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8, 2.12.17, 3.1.3]
scala: [2.13.10, 2.12.17, 3.2.1]
java: [temurin@8, temurin@11]
project: [rootJS, rootJVM, rootNative]
exclude:
- scala: 2.12.17
java: temurin@11
- scala: 3.1.3
- scala: 3.2.1
java: temurin@11
- project: rootJS
java: temurin@11
Expand Down Expand Up @@ -96,26 +96,26 @@ jobs:

- name: Check headers and formatting
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: scalaJSLink
if: matrix.project == 'rootJS'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/scalaJSLinkerResult
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/scalaJSLinkerResult

- name: nativeLink
if: matrix.project == 'rootNative'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/nativeLink
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/nativeLink

- name: Test
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' mimaReportBinaryIssues
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' doc
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand All @@ -139,7 +139,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.10]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -192,32 +192,32 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.13.8, rootJS)
- name: Download target directories (2.13.10, rootJS)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootJS
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJS

- name: Inflate target directories (2.13.8, rootJS)
- name: Inflate target directories (2.13.10, rootJS)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.8, rootJVM)
- name: Download target directories (2.13.10, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJVM

- name: Inflate target directories (2.13.8, rootJVM)
- name: Inflate target directories (2.13.10, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.8, rootNative)
- name: Download target directories (2.13.10, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootNative
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootNative

- name: Inflate target directories (2.13.8, rootNative)
- name: Inflate target directories (2.13.10, rootNative)
run: |
tar xf targets.tar
rm targets.tar
Expand Down Expand Up @@ -252,32 +252,32 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.3, rootJS)
- name: Download target directories (3.2.1, rootJS)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.3-rootJS
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootJS

- name: Inflate target directories (3.1.3, rootJS)
- name: Inflate target directories (3.2.1, rootJS)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.3, rootJVM)
- name: Download target directories (3.2.1, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.3-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootJVM

- name: Inflate target directories (3.1.3, rootJVM)
- name: Inflate target directories (3.2.1, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.3, rootNative)
- name: Download target directories (3.2.1, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.3-rootNative
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootNative

- name: Inflate target directories (3.1.3, rootNative)
- name: Inflate target directories (3.2.1, rootNative)
run: |
tar xf targets.tar
rm targets.tar
Expand All @@ -294,14 +294,14 @@ jobs:
(echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1)
- name: Publish
run: sbt '++${{ matrix.scala }}' tlRelease
run: sbt '++ ${{ matrix.scala }}' tlRelease

site:
name: Generate Site
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.10]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -355,7 +355,7 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Generate site
run: sbt '++${{ matrix.scala }}' docs/tlSite
run: sbt '++ ${{ matrix.scala }}' docs/tlSite

- name: Publish site
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# tune this file as appropriate to your style! see:
# https://scalameta.org/scalafmt/docs/configuration.html

version = 3.5.9
version = 3.6.1

maxColumn = 100

Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ libraryDependencies ++= Seq(
)
```

## Why log4cats?

Well, to answer that, let's take a look at how you might combine cats-effect with vanilla logging...

```scala
object MyVanillaLoggingThing {
val logger: Logger = Logger(LoggerFactory.getLogger(getClass.getName))

def doSomething(): IO[Unit] =
IO(logger.info("Doing something!")) *> IO.println("Hello, World!")

}
```

But what if you don't want to wrap your logger in an `IO` like this?
Good news, you don't have to! Enter log4cats! Read on!

## Examples

```scala
Expand Down Expand Up @@ -56,6 +73,20 @@ object MyThing {
}
```

## Wait...why log4cats again?
If you compare the vanilla logger + cats-effect example with the log4cats examples above,
you might be asking yourself "why do I have to do any of this?"
or "why can't I just add a log statement like normal?"

Well there are several reasons. Logging is often times an overlooked side-effect,
which under the hood can range from writing to a mutable queue, writing to disk,
outputting to the console, or sometimes even doing network I/O!
To correctly deal with these kinds of side-effects we have to ensure they are properly wrapped in `IO`,
see the [cats-effect docs](https://typelevel.org/cats-effect/docs/concepts#side-effects) for more details.

Basically, we are using cats-effect. We like things like "referential transparency"
and "programs-as-values". Wrapping our log statement in an `IO` helps with that.

### Laconic syntax

It's possible to use interpolated syntax for logging.
Expand Down
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import com.typesafe.tools.mima.core._

val Scala213 = "2.13.8"
val Scala213 = "2.13.10"
val Scala212 = "2.12.17"
val Scala3 = "3.1.3"
val Scala3 = "3.2.1"

ThisBuild / tlBaseVersion := "2.5"
ThisBuild / crossScalaVersions := Seq(Scala213, Scala212, Scala3)
Expand All @@ -26,8 +26,8 @@ ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8"), JavaSpec.te

ThisBuild / tlVersionIntroduced := Map("3" -> "2.1.1")

val catsV = "2.8.0"
val catsEffectV = "3.3.14"
val catsV = "2.9.0"
val catsEffectV = "3.4.2"
val slf4jV = "1.7.36"
val munitCatsEffectV = "2.0.0-M3"
val logbackClassicV = "1.2.11"
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.1
sbt.version=1.8.0
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.7")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.11.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.9")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
val sbtTypelevelVersion = "0.4.15"
val sbtTypelevelVersion = "0.4.17"
addSbtPlugin("org.typelevel" % "sbt-typelevel" % sbtTypelevelVersion)
addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % sbtTypelevelVersion)

0 comments on commit 7d5e8a7

Please sign in to comment.