jvm-stash

send your log into logstash

Лицензия

Лицензия

Категории

Категории

Ant Компиляция и сборка
Группа

Группа

com.wuriyanto
Идентификатор

Идентификатор

jvm-stash
Последняя версия

Последняя версия

1.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

jvm-stash
send your log into logstash
Ссылка на сайт

Ссылка на сайт

http://maven.apache.org
Система контроля версий

Система контроля версий

https://github.com/wuriyanto48/jvm-stash/tree/master

Скачать jvm-stash

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.wuriyanto/jvm-stash/ -->
<dependency>
    <groupId>com.wuriyanto</groupId>
    <artifactId>jvm-stash</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.wuriyanto/jvm-stash/
implementation 'com.wuriyanto:jvm-stash:1.0'
// https://jarcasting.com/artifacts/com.wuriyanto/jvm-stash/
implementation ("com.wuriyanto:jvm-stash:1.0")
'com.wuriyanto:jvm-stash:jar:1.0'
<dependency org="com.wuriyanto" name="jvm-stash" rev="1.0">
  <artifact name="jvm-stash" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.wuriyanto', module='jvm-stash', version='1.0')
)
libraryDependencies += "com.wuriyanto" % "jvm-stash" % "1.0"
[com.wuriyanto/jvm-stash "1.0"]

Зависимости

compile (2)

Идентификатор библиотеки Тип Версия
com.fasterxml.jackson.core : jackson-core jar 2.9.10
com.fasterxml.jackson.core : jackson-databind jar 2.9.10.4

test (1)

Идентификатор библиотеки Тип Версия
junit : junit jar 3.8.1

Модули Проекта

Данный проект не имеет модулей.

JVM Stash

Logstash Client for Java Virtual Machine

Note (If you use TLS)

You should convert your server certificate into PKCS12 format.

$ openssl pkcs12 -export -inkey your_server.key -in your_server.crt -out server.p12

Install

<dependency>
  <groupId>com.wuriyanto</groupId>
  <artifactId>jvm-stash</artifactId>
  <version>1.0</version>
</dependency>

Usage

Basic

Stash stash = new Stash.Builder()
                .setHost("localhost")
                .setPort(5000)
                .build();

try {
    stash.connect();
} catch (StashException e) {
    System.out.println(e.getMessage());
    System.exit(1);
}

stash.write("hello logstash".getBytes())

try {
    stash.close();
} catch (IOException e) {
    System.out.println(e.getMessage());
    System.exit(1);
}

TLS Connection

Assumed you already enable ssl config inside logstash.conf

input {
	tcp {
		port => 5000
		ssl_enable => true
		ssl_cert => "/etc/server.crt"
		ssl_key => "/etc/server.key"
		ssl_verify => false
	}
}

Let's write some code again

InputStream keyStore = null;

try {
    keyStore = new FileInputStream("/path/to/your/server.p12");
} catch (Exception e) {
    System.out.println(e.getMessage());
    System.exit(1);
}

Stash stash = new Stash.Builder()
                .setHost("localhost")
                .setPort(5000)
                // makesure set to true
                .setSecure(true)
                .setKeyStoreIs(keyStore)
                .setKeyStorePassword("damn12345")
                .build();

try {
    stash.connect();
} catch (StashException e) {
    System.out.println(e.getMessage());
    System.exit(1);
}

stash.write("hello logstash".getBytes())

try {
    stash.close();
} catch (IOException e) {
    System.out.println(e.getMessage());
    System.exit(1);
}

With Java's standar logging

private static final Logger LOGGER = Logger.getLogger(AppLogger.class.getName());

public static void main(String[] args) throws StashException {
        InputStream keyStore = null;
        
        try {
            keyStore = new FileInputStream("/path/to/your/server.p12");
        } catch (Exception e) {
            System.out.println(e.getMessage());
            System.exit(1);
        }
        
        Stash stash = new Stash.Builder()
                        .setHost("localhost")
                        .setPort(5000)
                        // makesure set to true
                        .setSecure(true)
                        .setKeyStoreIs(keyStore)
                        .setKeyStorePassword("damn12345")
                        .build();
        
        try {
            stash.connect();
        } catch (StashException e) {
            System.out.println(e.getMessage());
            System.exit(1);
        }
        
        // Set Handler with StashLogHandler
        LOGGER.addHandler(new StashLogHandler(stash));
        
        // Use standar log that uses StashLogHandler
        LOGGER.log(Level.INFO, "hello");
        
        try {
            stash.close();
        } catch (IOException e) {
            System.out.println(e.getMessage());
            System.exit(1);
        }

Spring Boot Integration

https://github.com/wuriyanto48/spring-boot-starter-jvmstash

Версии библиотеки

Версия
1.0