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

Add withModifiedContext to StructuredLogger #361

Merged

Conversation

ivan-klass
Copy link
Contributor

Add ability to modify context, similar to Logger.withModifiedString
Example: mask some sensitive structure field values

val currentLogger: StructuredLogger[F] = ???
val maskRe = "(?<=.{3}).(?=[^@]*?@)".r
val hideEmailLogger = StructuredLogger.withModifiedContext(currentLogger) {
  ctx => ctx.get("clientEmail").fold(ctx)(
    email => ctx.updated("clientEmail", maskRe.replaceAllIn(email, "*"))
  )
}

@rossabaker
Copy link
Member

I'm just trying to do releases. Paging the experts who use this library more extensively before I merge.

@rossabaker rossabaker changed the base branch from master to main January 20, 2021 04:37
@rossabaker rossabaker changed the base branch from main to series/1.x January 20, 2021 04:38
Copy link
Member

@lorandszakacs lorandszakacs left a comment

Choose a reason for hiding this comment

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

I like this addition to the library 👍

I would like to see the same method added to org.typelevel.log4cats.SelfAwareStructuredLogger as well to maintain predictability in usage.

def info(message: => String): F[Unit] = sl.info(outer)(message)
def debug(message: => String): F[Unit] = sl.debug(outer)(message)
def trace(message: => String): F[Unit] = sl.trace(outer)(message)
private def whenEmpty: Map[String, String] = modify(Map.empty)
Copy link
Member

Choose a reason for hiding this comment

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

This can be easily turned back into a val, right? Since applying a pure function to the same value, yields the same result.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lorandszakacs thanks! I've replaced with lazy val

@ivan-klass
Copy link
Contributor Author

ivan-klass commented Feb 12, 2021

I would like to see the same method added to org.typelevel.log4cats.SelfAwareStructuredLogger as well to maintain predictability in usage.

Added similar method to SelfAwareStructuredLogger

@lorandszakacs
Copy link
Member

LGTM 👍

@ChristopherDavenport, do you want to review this?

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

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

👍 We'll need to not forget to merge this forward to main before releasing that.

@lorandszakacs lorandszakacs merged commit fe70a20 into typelevel:series/1.x Feb 16, 2021
@lorandszakacs lorandszakacs mentioned this pull request Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants