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

Support change the context prefix and suffix format of KeyValueFormatter #275

Open
kuraun opened this issue Jun 7, 2021 · 0 comments
Open
Assignees
Labels
P3 type=enhancement Make an existing feature better

Comments

@kuraun
Copy link

kuraun commented Jun 7, 2021

Hi, Flogger Team.
I like Flogger very much, but I would like to see one improvement.
Why not allow the KeyValueFormatter prefix and suffix to be set with LogData.getMetaData () instead of constants?
I find it very difficult to use because I can't change the format of [CONTEXT ~].
It is possible to create own KeyValueFormatter by extending AbstractBackend and AbstractLogRecord,
but I would like a more convenient way to change only the prefix and suffix.

For example, like the following.

// AbstractRecord.java
  protected LogMessageFormatter getLogMessageFormatter() {
   return SimpleMessageFormatter.getDefaultFormatter(data.getMetadata());
 }

// SimpleMessageFormatter.java
public static LogMessageFormatter getDefaultFormatter(Metadata metadata) {
   if (metadata == null
           || metadata.equals(Metadata.empty())
           || metadata.findValue(LogContext.Key.KVF_PREFIX) == null
           || metadata.findValue(LogContext.Key.KVF_SUFFIX) == null) {
     return DEFAULT_FORMATTER;
   }
   return newFormatter(DEFAULT_KEYS_TO_IGNORE,
           metadata.findValue(LogContext.Key.KVF_PREFIX),
           metadata.findValue(LogContext.Key.KVF_SUFFIX));
 }

// ExtendedFluentLogger.java
...
 /** Logging context implementing the fully specified API for this logger. */
 // VisibleForTesting
 final class Context extends LogContext<ExtendedFluentLogger, Api> implements Api {
   private Context(Level level, boolean isForced) {
     super(level, isForced);
     addMetadata(Key.KVF_PREFIX, "MyPrefix");
     addMetadata(Key.KVF_SUFFIX, "MySuffix");
   }

Related: #60

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 type=enhancement Make an existing feature better
Projects
None yet
Development

No branches or pull requests

3 participants