This repository contains the sources for the client-side components of the LogFlake product suite for applications logs and performance collection for Java applications with a 5 thread pool.
Install the package:
<dependency>
<groupId>io.logflake</groupId>
<artifactId>client</artifactId>
<version>0.0.1</version>
</dependency>
Import the necessary functions and initialize the client with your application ID and server URL:
import io.logflake.LogFlakeClient;
...
LogFlakeClient logFlakeClient = LogFlakeClient.builder()
.server("YOUR_SERVER_URL") // Optional, default is "https://app.logflake.io"
.appKey("YOUR_APP_ID")
.hostname("HOSTNAME") // Optional
.correlation("correlation-id") // Optional correlation function or string
.enableCompression(true) // Optional, default is true
.verbose(true) // Optional, default is true
.build();
...
Send a log message with optional parameters:
import io.logflake.enums.LogLevel;
import io.logflake.LogFlakeClient;
...
LogFlakeClient logFlakeClient = LogFlakeClient.builder()
.server("YOUR_SERVER_URL") // Optional, default is "https://app.logflake.io"
.appKey("YOUR_APP_ID")
.hostname("HOSTNAME") // Optional
.correlation("correlation-id") // Optional correlation function or string
.enableCompression(true) // Optional, default is true
.verbose(true) // Optional, default is true
.build();
logFlakeClient.sendLog("Hello, LogFlake!", LogLevel.INFO,"correlation-id", "HOSTNAME", HashMap<String, String> params);
...
correlation
: Optional by overloading, default from client or nullhostname
: Optional by overloading, default from client or nullparam
: Optional by overloading
Capture and send exceptions to LogFlake:
import io.logflake.enums.LogLevel;
import io.logflake.LogFlakeClient;
import java.util.HashMap;
...
LogFlakeClient logFlakeClient = LogFlakeClient.builder()
.server("YOUR_SERVER_URL") // Optional, default is "https://app.logflake.io"
.appKey("YOUR_APP_ID")
.hostname("HOSTNAME") // Optional
.correlation("correlation-id") // Optional correlation function or string
.enableCompression(true) // Optional, default is true
.verbose(true) // Optional, default is true
.build();
Exception e = new Exception("Something went wrong");
HashMap<String,String> params = new HashMap<>();
params.put("key", "value");
logFlakeClient.sendsendException(e,params,"correlation-id","HOSTNAME");
...
param
: Optional by overloadingcorrelation
: Optional by overloading, default from client or nullhostname
: Optional by overloading, default from client or null
Measure the performance of a code block:
import io.logflake.enums.LogLevel;
import io.logflake.LogFlakeClient;
import java.util.HashMap;
...
LogFlakeClient logFlakeClient = LogFlakeClient.builder()
.server("YOUR_SERVER_URL") // Optional, default is "https://app.logflake.io"
.appKey("YOUR_APP_ID")
.hostname("HOSTNAME") // Optional
.correlation("correlation-id") // Optional correlation function or string
.enableCompression(true) // Optional, default is true
.verbose(true) // Optional, default is true
.build();
// Your operation code here
logFlakeClient.measurePerformance("YOUR_LABEL");
...
You must manually destroy the client when done using it
import io.logflake.enums.LogLevel;
import io.logflake.LogFlakeClient;
import java.util.HashMap;
...
LogFlakeClient logFlakeClient = LogFlakeClient.builder()
.server("YOUR_SERVER_URL") // Optional, default is "https://app.logflake.io"
.appKey("YOUR_APP_ID")
.hostname("HOSTNAME") // Optional
.correlation("correlation-id") // Optional correlation function or string
.enableCompression(true) // Optional, default is true
.verbose(true) // Optional, default is true
.build();
// Your operation code here
logFlakeClient.close();
...
The client use a 5 thread pool to send logs to the server, if it fails to send log, it starts an Exponential Back Off mechanism with 10s retry time and do 5 attempts.
When initializing the client, you can provide the following options:
correlation
: A function or value used to generate a correlation ID. Default isnull
.enableCompression
: Enables compression of logs. Default istrue
.verbose
: Enables verbose logging. Default istrue
.hostname
: The hostname associated with the logs.
The following log levels are available:
DEBUG
INFO
WARNING
ERROR
FATAL
EXCEPTION
Use these levels to categorize your log messages appropriately.
The LogFlake client includes a Log4J wrapper that allows you to send logs directly from your Log4J configuration. To use the wrapper see the following example:
import io.logflake.LogFlakeClient;
Log4jWrapper.getLogger(YourClass .class, (LogFlakeClient) logFlakeClient);
What does it do?:
- It wraps the
Apache
Log4J logger with the LogFlake client. - You can use the logger as you would do with Log4J by adding the client as the last parameter.
- We maintain the same log levels as Log4J, so you can use them as you would do with Log4J.
- At the moment we support only the message to be wrapped, we are working on the other parameters.
- The correlation and hostname are automatically added to the log message from client config.
This project is licensed under the MIT License.