Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions check-deployed-package/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@

import io.logdash.sdk.Logdash;

import java.util.Map;

public class Check {
public static void main(String[] args) {
System.out.println("=== LogDash Java SDK Demo ===");

// Get package version (would need to be handled differently in a real scenario)
System.out.println("Using logdash package version: " + getLogdashVersion());
System.out.println();

String apiKey = System.getenv("LOGDASH_API_KEY");
String logsSeed = System.getenv().getOrDefault("LOGS_SEED", "default");
String metricsSeed = System.getenv().getOrDefault("METRICS_SEED", "1");

System.out.println("Using API Key: " + apiKey);
System.out.println("Using Logs Seed: " + logsSeed);
System.out.println("Using Metrics Seed: " + metricsSeed);

try (Logdash logdash = Logdash.create(apiKey)) {
var logger = logdash.logger();
var metrics = logdash.metrics();

// Log some messages with seed appended
logger.info("This is an info log " + logsSeed);
logger.error("This is an error log " + logsSeed);
Expand All @@ -33,7 +32,7 @@ public static void main(String[] args) {
logger.silly("This is a silly log " + logsSeed);
logger.info("This is an info log " + logsSeed);
logger.verbose("This is a verbose log " + logsSeed);

// Set and mutate metrics with seed
int seedValue = Integer.parseInt(metricsSeed);
metrics.set("users", seedValue);
Expand All @@ -47,12 +46,12 @@ public static void main(String[] args) {
}
}
}

private static String getLogdashVersion() {
try {
return Check.class.getPackage().getImplementationVersion();
} catch (Exception e) {
return "unknown";
}
}
}
}
21 changes: 15 additions & 6 deletions check-deployed-package/pom.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.logdash</groupId>
<artifactId>check</artifactId>
<version>0.2.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<java.version>17</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.release>${java.version}</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

Expand Down Expand Up @@ -38,16 +41,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.12.1</version>
<configuration>
<source>17</source>
<target>17</target>
<release>${java.version}</release>
<compilerArgs>
<arg>-parameters</arg>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
<configuration>
<mainClass>io.logdash.check.Check</mainClass>
</configuration>
Expand Down
6 changes: 5 additions & 1 deletion examples/example-simple-java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
Expand Down Expand Up @@ -32,6 +32,7 @@

<build>
<plugins>
<!-- Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -40,6 +41,9 @@
<release>${maven.compiler.release}</release>
<compilerArgs>
<arg>-parameters</arg>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>
Expand Down
7 changes: 7 additions & 0 deletions examples/example-springboot/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM eclipse-temurin:21-jre-alpine

WORKDIR /app
COPY target/springboot-example-*.jar app.jar

EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
14 changes: 14 additions & 0 deletions examples/example-springboot/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: '3.8'
services:
app:
build: .
ports:
- '8080:8080'
environment:
- LOGDASH_API_KEY=${LOGDASH_API_KEY:-your-api-key}
- SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-dev}
healthcheck:
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080/actuator/health"]
interval: 30s
timeout: 10s
retries: 3
155 changes: 155 additions & 0 deletions examples/example-springboot/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.6</version>
<relativePath/>
</parent>

<groupId>io.logdash.example</groupId>
<artifactId>springboot-example</artifactId>
<version>0.2.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Logdash Spring Boot Example</name>
<description>Spring Boot application demonstrating Logdash Java SDK usage</description>

<properties>
<java.version>21</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.compiler.release>${java.version}</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<!-- Logdash SDK Version -->
<logdash-sdk.version>0.2.0-SNAPSHOT</logdash-sdk.version>

<!-- Plugin versions -->
<maven-help-plugin.version>3.5.1</maven-help-plugin.version>
</properties>

<dependencies>
<!-- Spring Boot Starters -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<!-- Logdash SDK -->
<dependency>
<groupId>io.logdash</groupId>
<artifactId>logdash</artifactId>
<version>${logdash-sdk.version}</version>
</dependency>

<!-- Test Dependencies -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<repositories>
<!-- Maven Central Snapshots -->
<repository>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>interval:60</updatePolicy>
</snapshots>
<id>maven-central-snapshots</id>
<name>Maven Central Snapshots</name>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</repository>
</repositories>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>io.logdash.example.SpringBootExampleApplication</mainClass>
</configuration>
</plugin>

<!-- Compiler Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<release>${java.version}</release>
<compilerArgs>
<arg>-parameters</arg>
<arg>-Xlint:unchecked</arg>
<arg>-Xlint:deprecation</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
<version>${maven-help-plugin.version}</version>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>local-dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<snapshots>
<updatePolicy>never</updatePolicy>
</snapshots>
<id>maven-central-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</repository>
</repositories>
</profile>

<profile>
<id>force-remote</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>purge-local-logdash</id>
<goals>
<goal>purge-local-repository</goal>
</goals>
<phase>initialize</phase>
<configuration>
<includes>
<include>io.logdash:logdash</include>
</includes>
<snapshotsOnly>true</snapshotsOnly>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
23 changes: 23 additions & 0 deletions examples/example-springboot/requests.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
### Variables
@baseUrl = http://localhost:8080

### Get all pets
GET {{baseUrl}}/api/pets

### Get pet by ID
GET {{baseUrl}}/api/pets/1

### Create a new pet
POST {{baseUrl}}/api/pets
Content-Type: application/json

{
"name": "Fluffy",
"type": "DOG"
}

### Create a random pet
POST {{baseUrl}}/api/pets/random

### Delete a pet by ID
DELETE {{baseUrl}}/api/pets/3
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.logdash.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication
@EnableScheduling
public class SpringBootExampleApplication {

public static void main(String[] args) {
SpringApplication.run(SpringBootExampleApplication.class, args);
}
}
Loading