What happened?
I have a 3-parameter tuple that is used as a composite data store key. I end up writing code that looks like this:
log.error("bad thing happened on {} {} {}",
UnsafeArg.of("key", primaryKey),
UnsafeArg.of("branch", branch),
SafeArg.of("semanticVersion", SafeLog.of(semanticVersion)));
This 3-parameter tuple of [key, branch, semanticVersion] is common across logging statements and safe exceptions because my application needs all 3 parameters to make sense of what is going on.
The construction of logging and exceptions with these three parameters over and over again is tedious and error prone.
I attempted to wrap this logic with something like this:
@SuppressWarnings("rawtypes")
public static Arg[] argsFromPersistedObjectKeyArgs(PersistedObjectKey key) {
Arg[] args = new Arg[3];
args[0] = UnsafeArg.of(KEY_LOG_PARAM, key.key());
args[1] = SafeArg.of(BRANCH_LOG_PARAM, key.branch());
args[2] = SafeArg.of(SEMANTIC_VERSION_LOG_PARAM, key.semanticVersion());
return args;
}
and use it like so:
log.warn("table found no key for ({})", (Object[]) SafeLoggerUtils.argsFromPersistedObjectKeyArgs(key));
but:
- I have to use an
(Object[]) prefix to avoid ambiguous method calls
- I end up throwing Baseline Error Prone Checks for the usage cast to
(Object[])
warning: [Slf4jLogsafeArgs] slf4j log statement does not use logsafe parameters for arguments [1]
(see https://github.com/palantir/gradle-baseline#baseline-error-prone-checks)
To remove the error prone check I have to annotate my methods with Slf4jLogsafeArgs suppressed warnings.
What did you want to happen?
I would like the logging and exception methods to handle non-Args-only objects constructed with an interface that supports both safe and unsafe logging. This may already exist but no one has been able to point me to it so far.
What happened?
I have a 3-parameter tuple that is used as a composite data store key. I end up writing code that looks like this:
This 3-parameter tuple of [
key,branch,semanticVersion] is common across logging statements and safe exceptions because my application needs all 3 parameters to make sense of what is going on.The construction of logging and exceptions with these three parameters over and over again is tedious and error prone.
I attempted to wrap this logic with something like this:
and use it like so:
but:
(Object[])prefix to avoid ambiguous method calls(Object[])To remove the error prone check I have to annotate my methods with
Slf4jLogsafeArgssuppressed warnings.What did you want to happen?
I would like the logging and exception methods to handle non-
Args-only objects constructed with an interface that supports both safe and unsafe logging. This may already exist but no one has been able to point me to it so far.