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

daml-lf/data: Optionally truncate party names in structured logs. [KVL-996] #10163

Merged
merged 6 commits into from
Jul 1, 2021
Merged
Prev Previous commit
Next Next commit
logging-entries: Make ToLoggingValue mixin-able.
  • Loading branch information
SamirTalwar committed Jul 1, 2021
commit a69b56bf8223c742b07009670e1acc12a84a8a0f
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,12 @@ object domain {
implicit val `Absolute Ordering`: Ordering[LedgerOffset.Absolute] =
Ordering.by[LedgerOffset.Absolute, String](_.value)

implicit object `LedgerOffset to LoggingValue` extends ToLoggingValue[LedgerOffset] {
override def apply(value: LedgerOffset): LoggingValue =
LoggingValue.OfString(value match {
case LedgerOffset.Absolute(absolute) => absolute
case LedgerOffset.LedgerBegin => "%begin%"
case LedgerOffset.LedgerEnd => "%end%"
})
}

implicit val `LedgerOffset to LoggingValue`: ToLoggingValue[LedgerOffset] = value =>
LoggingValue.OfString(value match {
case LedgerOffset.Absolute(absolute) => absolute
case LedgerOffset.LedgerBegin => "%begin%"
case LedgerOffset.LedgerEnd => "%end%"
})
}

sealed trait Event extends Product with Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ object Offset {

def fromHexString(s: Ref.HexString) = new Offset(Bytes.fromHexString(s))

implicit object `Offset to LoggingValue` extends ToLoggingValue[Offset] {
override def apply(value: Offset): LoggingValue =
LoggingValue.OfString(value.toHexString)
}
implicit val `Offset to LoggingValue`: ToLoggingValue[Offset] = value =>
LoggingValue.OfString(value.toHexString)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ object LoggingValue {

@inline
implicit def from[T](value: T)(implicit toLoggingValue: ToLoggingValue[T]): LoggingValue =
toLoggingValue(value)
toLoggingValue.toLoggingValue(value)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package com.daml.logging.entries
import java.time.{Duration, Instant}

trait ToLoggingValue[-T] {
def apply(value: T): LoggingValue
def toLoggingValue(value: T): LoggingValue
}

object ToLoggingValue {
Expand All @@ -32,11 +32,11 @@ object ToLoggingValue {
elementToLoggingValue: ToLoggingValue[T]
): ToLoggingValue[Option[T]] = {
case None => LoggingValue.Empty
case Some(value) => elementToLoggingValue(value)
case Some(value) => elementToLoggingValue.toLoggingValue(value)
}

implicit def `Iterable[T] to LoggingValue`[T](implicit
elementToLoggingValue: ToLoggingValue[T]
): ToLoggingValue[Iterable[T]] =
sequence => LoggingValue.OfIterable(sequence.view.map(elementToLoggingValue.apply))
sequence => LoggingValue.OfIterable(sequence.view.map(elementToLoggingValue.toLoggingValue))
}