-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
slf4j2-bridge - annotations for logger
- Loading branch information
Showing
11 changed files
with
150 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 0 additions & 101 deletions
101
slf4j2-bridge/src/main/java/zio/logging/slf4j/bridge/Logger.java
This file was deleted.
Oops, something went wrong.
55 changes: 0 additions & 55 deletions
55
slf4j2-bridge/src/main/java/zio/logging/slf4j/bridge/LoggerFactory.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
slf4j2-bridge/src/main/scala/zio/logging/slf4j/bridge/LoggerRuntime.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* 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.slf4j.bridge | ||
|
||
import org.slf4j.event.{ KeyValuePair, Level } | ||
|
||
trait LoggerRuntime { | ||
|
||
def log( | ||
logger: LoggerData, | ||
level: Level, | ||
messagePattern: String, | ||
arguments: Array[AnyRef], | ||
throwable: Throwable, | ||
keyValues: java.util.List[KeyValuePair] | ||
): Unit | ||
|
||
def isEnabled(logger: LoggerData, level: Level): Boolean | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
slf4j2-bridge/src/main/scala/zio/logging/slf4j/bridge/ZioLogger.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package zio.logging.slf4j.bridge | ||
|
||
import org.slf4j.Marker | ||
import org.slf4j.event.{KeyValuePair, Level, LoggingEvent} | ||
import org.slf4j.helpers.AbstractLogger | ||
import org.slf4j.spi.LoggingEventAware | ||
|
||
import java.util.Collections; | ||
|
||
final class ZioLogger private[bridge] (name: String, factory: ZioLoggerFactory) | ||
extends AbstractLogger | ||
with LoggingEventAware { | ||
|
||
private val data: LoggerData = LoggerData(name) | ||
|
||
override def getName: String = name | ||
|
||
override protected def getFullyQualifiedCallerName: String = null | ||
|
||
override protected def handleNormalizedLoggingCall( | ||
level: Level, | ||
marker: Marker, | ||
messagePattern: String, | ||
arguments: Array[AnyRef], | ||
throwable: Throwable | ||
): Unit = | ||
factory.log(data, level, messagePattern, arguments, throwable, Collections.emptyList[KeyValuePair]()) | ||
|
||
override def isTraceEnabled: Boolean = factory.isEnabled(data, Level.TRACE) | ||
|
||
override def isTraceEnabled(marker: Marker): Boolean = isTraceEnabled | ||
|
||
override def isDebugEnabled: Boolean = factory.isEnabled(data, Level.DEBUG) | ||
|
||
override def isDebugEnabled(marker: Marker): Boolean = isDebugEnabled | ||
|
||
override def isInfoEnabled: Boolean = factory.isEnabled(data, Level.INFO) | ||
|
||
override def isInfoEnabled(marker: Marker): Boolean = isInfoEnabled | ||
|
||
override def isWarnEnabled: Boolean = factory.isEnabled(data, Level.WARN) | ||
|
||
override def isWarnEnabled(marker: Marker): Boolean = isWarnEnabled | ||
|
||
override def isErrorEnabled: Boolean = factory.isEnabled(data, Level.ERROR) | ||
|
||
override def isErrorEnabled(marker: Marker): Boolean = isErrorEnabled | ||
|
||
override def log(event: LoggingEvent): Unit = | ||
if (factory.isEnabled(data, event.getLevel)) | ||
factory.log( | ||
data, | ||
event.getLevel, | ||
event.getMessage, | ||
event.getArgumentArray, | ||
event.getThrowable, | ||
event.getKeyValuePairs | ||
) | ||
} |
46 changes: 46 additions & 0 deletions
46
slf4j2-bridge/src/main/scala/zio/logging/slf4j/bridge/ZioLoggerFactory.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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.slf4j.bridge | ||
|
||
import org.slf4j.event.{ KeyValuePair, Level } | ||
import org.slf4j.{ ILoggerFactory, Logger } | ||
|
||
import java.util.concurrent.ConcurrentHashMap | ||
import scala.jdk.CollectionConverters._ | ||
|
||
final class ZioLoggerFactory extends ILoggerFactory { | ||
private var runtime: LoggerRuntime = null | ||
private val loggers = new ConcurrentHashMap[String, Logger]().asScala | ||
|
||
private[bridge] def attachRuntime(runtime: LoggerRuntime): Unit = | ||
this.runtime = runtime | ||
|
||
private[bridge] def log( | ||
logger: LoggerData, | ||
level: Level, | ||
messagePattern: String, | ||
arguments: Array[AnyRef], | ||
throwable: Throwable, | ||
keyValues: java.util.List[KeyValuePair] | ||
): Unit = | ||
if (runtime != null) runtime.log(logger, level, messagePattern, arguments, throwable, keyValues) | ||
|
||
private[bridge] def isEnabled(logger: LoggerData, level: Level): Boolean = | ||
if (runtime != null) runtime.isEnabled(logger, level) else false | ||
|
||
override def getLogger(name: String): Logger = | ||
loggers.getOrElseUpdate(name, new ZioLogger(name, this)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters