logSite

public static LogSite logSite()

Returns a LogSite for the current line of code. This can be used in conjunction with the withInjectedLogSite method to implement logging helper methods. In some platforms, log site determination may be unsupported, and in those cases this method will always return the INVALID instance.

For example (in MyLoggingHelper):


public static void logAndSomethingElse(LogSite logSite, String message, Object... args) {
  logger.atInfo()
      .withInjectedLogSite(logSite)
      .logVarargs(message, args);
}
where callers would do:

MyLoggingHelper.logAndSomethingElse(logSite(), "message...");

Because this method adds an additional parameter and exposes a Flogger specific type to the calling code, you should consider using callerOf for simple logging utilities.

It is very important to note that this method can be very slow, since determining the log site can involve stack trace analysis. It is only recommended that it is used for cases where logging is expected to occur (e.g. INFO level or above). Implementing a helper method for FINE logging is usually unnecessary (it doesn't normally need to follow any specific "best practice" behavior).

Note that even when log site determination is supported, it is not defined as to whether two invocations of this method on the same line of code will produce the same instance, equivalent instances or distinct instance. Thus you should never invoke this method twice in a single statement (and you should never need to).

Note that this method call may be replaced in compiled applications via bytecode manipulation or other mechanisms to improve performance.

Return

the log site of the caller of this method.