Logback Appender 中文版README Aliyun Log Logback Appender Logback is intended as a successor to the popular log4j project. You can control the…
Logback Appender 中文版README Aliyun Log Logback Appender Logback is intended as a successor to the popular log4j project. You can control the…
Logback is intended as a successor to the popular log4j project. You can control the destination of the log through logback. It can be console, file, GUI components, socket, NT event log, syslog. You can control the output format for each log as well. You can control the generation process of the log through log level. The most interesting thing is you can complete the above things through a configuration file and without any code modification.
You can set the destination of your log to AliCloud Log Service through Aliyun Log Logback Appender, The format of the log in AliCloud Log Service is as follows:
level: ERROR
location: com.aliyun.openservices.log.logback.example.LogbackAppenderExample.main(LogbackAppenderExample.java:18)
message: error log
throwable: java.lang.RuntimeException: xxx
thread: main
time: 2018-01-02T03:15+0000
log: 2018-01-02 11:15:29,682 ERROR [main] com.aliyun.openservices.log.logback.example.LogbackAppenderExample: error log
__source__: xxx
__topic__: yyyField Specifications:
level stands for log levellocation is logs's output position, can be disabled by configurationmessage is the content of the logthrowable is exception of the log (this field will appear only if the exception is recorded)thread stands for thread nametime is the log's generation time (you can configure it's format through timeFormat and timeZone)log is custom log format (this field will appear only if you configure the encoder)__source__ is the log's source, you can specify its value in conf file__topic__ is the log's topic, you can specify its value in conf fileDisk Free: the generation data will be send to AliCloud Log Service in real time through network.Without Refactor: if your application already use logback, you can just add logback appender to your configuration file.Asynchronous and High Throughput: the data will be send to AliCloud Log Service asynchronously. It is suitable for high concurrent write.Context Query: at server side, in addition to searching log with keywords, you can obtain the context information of original log as well.
com.google.protobuf
protobuf-java
2.5.0
com.aliyun.openservices
aliyun-log-logback-appender
0.1.28
Take logback.xml as an example, you can configure the appender and logger related to AliCloud Log Services as follows:
your project endpoint
your accesskey id
your accesskey
your project
your logStore
your topic
your source
104857600
0
8
524288
4096
2000
10
100
50000
%d %-5level [%thread] %logger{0}: %msg
yyyy-MM-dd'T'HH:mmZ
UTC
true
true
${accessKeyId}
${accessKeySecret}
500
s
Note:
DelayingShutdownHook.BasicStatusManager, you can obtain the exception information through OnConsoleStatusListener or other means. Reference: https://logback.qos.ch/access.htmlThe Aliyun Log Logback Appender provides following parameters.
…The logback-appender supports custom CredentialsProvider. By implementing the CredentialsProvider interface, you can implement advanced features yourself, such as dynamic rotation of AccessKey.
Once a
CredentialsProvideris provided, it's unnecessary to configure parameter for static credentials (AccessKeyId/AccessKeySecret/SecurityToken); the system will use the credentials fetched through theCredentialsProviderprovided.
Defines a class, eg. MyCredentialsProvider, and implements the CredentialsProvider interface to support the dynamic updates of credentials. Make sure the implementation is thread-safe.
getCredentials caches credentials and refreshes them before expired.class MyCredentialsProvider implements CredentialsProvider {
@Override
public synchronized Credentials getCredentials() {
// fetch credentials and caches credentials
}
// constructor
MyCredentialsProvider(String param1, long paramField2) {}
}Defines a class, eg. MyBuilder, and implements the CredentialsProviderBuilder interface.
getCredentialsProvider should return a new instance of CredentialsProvider for each call.class MyBuilder implements CredentialsProviderBuilder {
@Override
public CredentialsProvider getCredentialsProvider() {
return new MyCredentialsProvider(param1, paramField2);
}
private String param1;
private long paramField2;
public void setParam1(String param1) {
this.param1 = param1;
}
public void setParamField2(long paramField2) {
this.paramField2 = paramField2;
}
}Configure logback with xml file, set the class of credentialsProviderBuilder with the fully qualified name of your class, eg. com.example.MyBuilder, and pass any custom parameters.
hello
123
To pass in some custom parameters to the MyBuilder class, such as param1, paramField2, define the setter methods setParam1 and setParamField2 in the class first.
class MyBuilder implements CredentialsProviderBuilder {
private String param1;
private long paramField2;
public void setParam1(String param1) {
this.param1 = param1;
}
public void setParamField2(long paramField2) {
this.paramField2 = paramField2;
}
// Omit other codes
}Then configure logback with xml file, set the class of credentialsProviderBuilder with the fully qualified name of your class, eg. com.example.MyBuilder, and fill with custom parameters.
hello
123
No open issues yet, or sync has not completed.