-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor project, better separate implementation.
- Loading branch information
Showing
20 changed files
with
649 additions
and
603 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.chavaillaz.appender; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Optional; | ||
|
||
import javax.net.ssl.SSLContext; | ||
import lombok.SneakyThrows; | ||
import lombok.experimental.UtilityClass; | ||
import org.apache.http.conn.ssl.TrustAllStrategy; | ||
import org.apache.http.ssl.SSLContextBuilder; | ||
|
||
/** | ||
* Common utility methods. | ||
*/ | ||
@UtilityClass | ||
public class CommonUtils { | ||
|
||
/** | ||
* Searches an environment or system property value. | ||
* | ||
* @param key The key to search in the properties | ||
* @param defaultValue The default value to use in case the given key is not found | ||
* @return The value found in environment/system properties or the given default value | ||
*/ | ||
public static String getProperty(String key, String defaultValue) { | ||
return Optional.ofNullable(System.getenv(key)).orElse(System.getProperty(key, defaultValue)); | ||
} | ||
|
||
/** | ||
* Creates a permissive SSL context trusting everything. | ||
* | ||
* @return The SSL context | ||
*/ | ||
@SneakyThrows | ||
public static SSLContext createSSLContext() { | ||
return new SSLContextBuilder() | ||
.loadTrustMaterial(null, TrustAllStrategy.INSTANCE) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Gets the current host name of the machine. | ||
* | ||
* @return The host name or {@code localhost} if it cannot be determined | ||
*/ | ||
public static String getInitialHostname() { | ||
try { | ||
return InetAddress.getLocalHost().getCanonicalHostName(); | ||
} catch (UnknownHostException e) { | ||
return "localhost"; | ||
} | ||
} | ||
|
||
} |
82 changes: 82 additions & 0 deletions
82
src/main/java/com/chavaillaz/appender/LogConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.chavaillaz.appender; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* Configuration for logs transmission. | ||
*/ | ||
public interface LogConfiguration { | ||
|
||
/** | ||
* Gets the name of the application generating the logs. | ||
* | ||
* @return The application name | ||
*/ | ||
String getApplication(); | ||
|
||
/** | ||
* Sets the name of the application generating the logs. | ||
* | ||
* @param application The application name | ||
*/ | ||
void setApplication(String application); | ||
|
||
/** | ||
* Gets the name of the host on which the application is running. | ||
* | ||
* @return The host name | ||
*/ | ||
String getHost(); | ||
|
||
/** | ||
* Sets the name of the host on which the application is running. | ||
* | ||
* @param host The host name | ||
*/ | ||
void setHost(String host); | ||
|
||
/** | ||
* Sets the environment in which the application is running. | ||
* | ||
* @return The environment name | ||
*/ | ||
String getEnvironment(); | ||
|
||
/** | ||
* Sets the environment in which the application is running. | ||
* | ||
* @param environment The environment name | ||
*/ | ||
void setEnvironment(String environment); | ||
|
||
/** | ||
* Gets the threshold number of messages triggering the transmission of the logs. | ||
* | ||
* @return The threshold number of messages | ||
*/ | ||
long getFlushThreshold(); | ||
|
||
/** | ||
* Sets the threshold number of messages triggering the transmission of the logs. | ||
* | ||
* @param messageNumber The threshold number of messages | ||
*/ | ||
void setFlushThreshold(long messageNumber); | ||
|
||
/** | ||
* Gets the maximum time interval between two flushes. | ||
* After each interval, the transmission of logs is triggered, even if not reaching the threshold number of messages. | ||
* | ||
* @return The maximum interval between two flushes | ||
*/ | ||
Duration getFlushInterval(); | ||
|
||
/** | ||
* Gets the maximum time interval between two flushes. | ||
* After each interval, the transmission of logs is triggered, even if not reaching the threshold number of messages. | ||
* | ||
* @param flushInterval The maximum interval between two flushes | ||
*/ | ||
void setFlushInterval(Duration flushInterval); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.chavaillaz.appender; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Transmission of logs to an external monitoring system. | ||
*/ | ||
public interface LogDelivery extends AutoCloseable { | ||
|
||
/** | ||
* Sends the given record data. | ||
* | ||
* @param document The record data | ||
*/ | ||
void send(Map<String, Object> document); | ||
|
||
/** | ||
* Sends the given list of record data. | ||
* | ||
* @param documents The list of record data | ||
*/ | ||
void send(List<Map<String, Object>> documents); | ||
|
||
/** | ||
* Sends the pending records (generating a partially filled batch). | ||
* Intended to be called periodically to clean out pending messages. | ||
*/ | ||
void flush(); | ||
|
||
} |
Oops, something went wrong.