forked from lightbend-labs/scala-logging
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
logger taking constructor arg macro, for when you have a context, but…
… you don't want to pass it each time via implicit for every call, just set it once when you instantiate the logger. see lightbend-labs#208
- Loading branch information
Showing
8 changed files
with
878 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.typesafe.scalalogging | ||
|
||
import org.slf4j.Marker | ||
|
||
/** | ||
* | ||
* abstract class common for both Logger and LoggerTakingConstructorArg, | ||
* if you have a library that is sometimes used in a context - in which case you want to log the context, | ||
* but other times is used outside of a context in which case you want to log "normally", your base class can have a logger of this abstract type | ||
*/ | ||
trait ALogger { | ||
|
||
// Error | ||
|
||
def error(message: String): Unit = {} | ||
|
||
def error(message: String, cause: Throwable): Unit = {} | ||
|
||
def error(message: String, args: Any*): Unit = {} | ||
|
||
def error(marker: Marker, message: String): Unit = {} | ||
|
||
def error(marker: Marker, message: String, cause: Throwable): Unit = {} | ||
|
||
def error(marker: Marker, message: String, args: Any*): Unit = {} | ||
|
||
// Warn | ||
|
||
def warn(message: String): Unit = {} | ||
|
||
def warn(message: String, cause: Throwable): Unit = {} | ||
|
||
def warn(message: String, args: Any*): Unit = {} | ||
|
||
def warn(marker: Marker, message: String): Unit = {} | ||
|
||
def warn(marker: Marker, message: String, cause: Throwable): Unit = {} | ||
|
||
def warn(marker: Marker, message: String, args: Any*): Unit = {} | ||
|
||
// Info | ||
|
||
def info(message: String): Unit = {} | ||
|
||
def info(message: String, cause: Throwable): Unit = {} | ||
|
||
def info(message: String, args: Any*): Unit = {} | ||
|
||
def info(marker: Marker, message: String): Unit = {} | ||
|
||
def info(marker: Marker, message: String, cause: Throwable): Unit = {} | ||
|
||
def info(marker: Marker, message: String, args: Any*): Unit = {} | ||
|
||
// Debug | ||
|
||
def debug(message: String): Unit = {} | ||
|
||
def debug(message: String, cause: Throwable): Unit = {} | ||
|
||
def debug(message: String, args: Any*): Unit = {} | ||
|
||
def debug(marker: Marker, message: String): Unit = {} | ||
|
||
def debug(marker: Marker, message: String, cause: Throwable): Unit = {} | ||
|
||
def debug(marker: Marker, message: String, args: Any*): Unit = {} | ||
|
||
// Trace | ||
|
||
def trace(message: String): Unit = {} | ||
|
||
def trace(message: String, cause: Throwable): Unit = {} | ||
|
||
def trace(message: String, args: Any*): Unit = {} | ||
|
||
def trace(marker: Marker, message: String): Unit = {} | ||
|
||
def trace(marker: Marker, message: String, cause: Throwable): Unit = {} | ||
|
||
def trace(marker: Marker, message: String, args: Any*): Unit = {} | ||
|
||
} | ||
|
||
|
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
83 changes: 83 additions & 0 deletions
83
src/main/scala/com/typesafe/scalalogging/LoggerTakingConstructorArg.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,83 @@ | ||
package com.typesafe.scalalogging | ||
|
||
import org.slf4j.{Marker, Logger => Underlying} | ||
|
||
import scala.language.experimental.macros | ||
|
||
/** | ||
* ALogger that takes some data A and uses it according to strategy CanLog[A] during every log operation. | ||
* Useful for logging things in a context, such as a request id, assuming it's available during construction time. | ||
* */ | ||
class LoggerTakingConstructorArg[A] private[scalalogging](val underlying: Underlying, val canLogEv: CanLog[A], val a: A) extends ALogger with Serializable with LogsAdditionalData[A] { | ||
|
||
// Error | ||
|
||
override def error(message: String): Unit = macro LoggerTakingConstructorArgMacro.errorMessage[A] | ||
|
||
override def error(message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.errorMessageCause[A] | ||
|
||
override def error(message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.errorMessageArgs[A] | ||
|
||
override def error(marker: Marker, message: String): Unit = macro LoggerTakingConstructorArgMacro.errorMessageMarker[A] | ||
|
||
override def error(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.errorMessageCauseMarker[A] | ||
|
||
override def error(marker: Marker, message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.errorMessageArgsMarker[A] | ||
|
||
// Warn | ||
|
||
override def warn(message: String): Unit = macro LoggerTakingConstructorArgMacro.warnMessage[A] | ||
|
||
override def warn(message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.warnMessageCause[A] | ||
|
||
override def warn(message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.warnMessageArgs[A] | ||
|
||
override def warn(marker: Marker, message: String): Unit = macro LoggerTakingConstructorArgMacro.warnMessageMarker[A] | ||
|
||
override def warn(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.warnMessageCauseMarker[A] | ||
|
||
override def warn(marker: Marker, message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.warnMessageArgsMarker[A] | ||
|
||
// Info | ||
|
||
override def info(message: String): Unit = macro LoggerTakingConstructorArgMacro.infoMessage[A] | ||
|
||
override def info(message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.infoMessageCause[A] | ||
|
||
override def info(message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.infoMessageArgs[A] | ||
|
||
override def info(marker: Marker, message: String): Unit = macro LoggerTakingConstructorArgMacro.infoMessageMarker[A] | ||
|
||
override def info(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.infoMessageCauseMarker[A] | ||
|
||
override def info(marker: Marker, message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.infoMessageArgsMarker[A] | ||
|
||
// Debug | ||
|
||
override def debug(message: String): Unit = macro LoggerTakingConstructorArgMacro.debugMessage[A] | ||
|
||
override def debug(message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.debugMessageCause[A] | ||
|
||
override def debug(message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.debugMessageArgs[A] | ||
|
||
override def debug(marker: Marker, message: String): Unit = macro LoggerTakingConstructorArgMacro.debugMessageMarker[A] | ||
|
||
override def debug(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.debugMessageCauseMarker[A] | ||
|
||
override def debug(marker: Marker, message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.debugMessageArgsMarker[A] | ||
|
||
// Trace | ||
|
||
override def trace(message: String): Unit = macro LoggerTakingConstructorArgMacro.traceMessage[A] | ||
|
||
override def trace(message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.traceMessageCause[A] | ||
|
||
override def trace(message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.traceMessageArgs[A] | ||
|
||
override def trace(marker: Marker, message: String): Unit = macro LoggerTakingConstructorArgMacro.traceMessageMarker[A] | ||
|
||
override def trace(marker: Marker, message: String, cause: Throwable): Unit = macro LoggerTakingConstructorArgMacro.traceMessageCauseMarker[A] | ||
|
||
override def trace(marker: Marker, message: String, args: Any*): Unit = macro LoggerTakingConstructorArgMacro.traceMessageArgsMarker[A] | ||
|
||
} |
Oops, something went wrong.