Logger
The primary interface for writing logs.
Reference
// In Java
private static final Logger logger = LoggerFactory.getLogger();
logger.log();
//In spring
@Configuration
@Import(value= {
AutoConfigurationBitryonLogger.class, // to load the configs from application.yml for logging related beans
})
public class ExampleWebServerConfiguration {
@Resource
Logger logger;
}
Methods
| Method | Description |
|---|---|
flush() | flush the logs into persistence. |
skip(boolean skip) | Setup if the logging should skip. true skipped, false not. |
boolean getSkip() | To indicate if the logging is skipped. |
reset() | before or after enter a thread to process logics, to clean up context. |
setStepLogId(String stepLogId, boolean sequenceIdRenewal) |
If the thread is created by another un-related thread, it needs to setup the log id manually in order to trace. |
setStepLogId(String stepLogId) |
If the thread is created by another un-related thread, it needs to setup the log id manually in order to trace. |
String getStepLogId() |
Get the step log id. @return E.G. 4ouOhT4RN5jcGxJTCJRn4eOWfjyNZ07L-5-2-1 |
String getNextStepLogId() |
Get the next step log id used for a new step. should call getStepLogId() if used for an inside invoke. @return E.G. 4ouOhT4RN5jcGxJTCJRn4eOWfjyNZ07L-5-2-1 -> 4ouOhT4RN5jcGxJTCJRn4eOWfjyNZ07L-5-2-2 |
String getTraceId() |
trace id, should be 32 characters consist of 0-1a-zA-Z only. @return E.G. 4ouOhT4RN5jcGxJTCJRn4eOWfjyNZ07L |
log(Object... objects) |
log objects as PreDefinition.TYPE.JSON. For most cases, it's enough for use. @param objects values to log |
text(String textMessage, Object... objects) |
write text message with PreDefinition.TYPE.TEXT, and replace the message by placeholder {}. logText("this is a {}, {} has it", "apple", "joe") -> "this is a apple, joe has it" For most cases, it's enough for use. @param textMessage text message with formats @param objects values to log. Should only be simple types like number or string. |
ret(String step, Object... objects) |
[Not recommended] write a return log. In general return log would be pair to the enter log. @param step If null, trace back with the stack by default skipLayer; or write the string including empty "", @param objects The first should be the return values, then comes the parameters if configured in @Logger; values to transform by PreDefinition.TYPE indicated |
exception(Throwable throwable) |
log exceptions with PreDefinition.TYPE.EXCEP. @param throwable the exception, may log multiple lines |
bitryon logger believes log levels is out-dated. So it provides skip and skipRandom instead.