Skip to content

Commit 752fbba

Browse files
Merge pull request #8 from logdash-io/feat/spring-boot-example
feat(example): add Spring Boot example
2 parents b55f3cf + a299ec5 commit 752fbba

20 files changed

Lines changed: 897 additions & 17 deletions

File tree

check-deployed-package/Check.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,27 @@
22

33
import io.logdash.sdk.Logdash;
44

5-
import java.util.Map;
65

76
public class Check {
87
public static void main(String[] args) {
98
System.out.println("=== LogDash Java SDK Demo ===");
10-
9+
1110
// Get package version (would need to be handled differently in a real scenario)
1211
System.out.println("Using logdash package version: " + getLogdashVersion());
1312
System.out.println();
14-
13+
1514
String apiKey = System.getenv("LOGDASH_API_KEY");
1615
String logsSeed = System.getenv().getOrDefault("LOGS_SEED", "default");
1716
String metricsSeed = System.getenv().getOrDefault("METRICS_SEED", "1");
18-
17+
1918
System.out.println("Using API Key: " + apiKey);
2019
System.out.println("Using Logs Seed: " + logsSeed);
2120
System.out.println("Using Metrics Seed: " + metricsSeed);
22-
21+
2322
try (Logdash logdash = Logdash.create(apiKey)) {
2423
var logger = logdash.logger();
2524
var metrics = logdash.metrics();
26-
25+
2726
// Log some messages with seed appended
2827
logger.info("This is an info log " + logsSeed);
2928
logger.error("This is an error log " + logsSeed);
@@ -33,7 +32,7 @@ public static void main(String[] args) {
3332
logger.silly("This is a silly log " + logsSeed);
3433
logger.info("This is an info log " + logsSeed);
3534
logger.verbose("This is a verbose log " + logsSeed);
36-
35+
3736
// Set and mutate metrics with seed
3837
int seedValue = Integer.parseInt(metricsSeed);
3938
metrics.set("users", seedValue);
@@ -47,12 +46,12 @@ public static void main(String[] args) {
4746
}
4847
}
4948
}
50-
49+
5150
private static String getLogdashVersion() {
5251
try {
5352
return Check.class.getPackage().getImplementationVersion();
5453
} catch (Exception e) {
5554
return "unknown";
5655
}
5756
}
58-
}
57+
}

check-deployed-package/pom.xml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<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">
33
<modelVersion>4.0.0</modelVersion>
4+
45
<groupId>io.logdash</groupId>
56
<artifactId>check</artifactId>
67
<version>0.2.0-SNAPSHOT</version>
78

89
<properties>
9-
<maven.compiler.source>17</maven.compiler.source>
10-
<maven.compiler.target>17</maven.compiler.target>
10+
<java.version>17</java.version>
11+
<maven.compiler.source>${java.version}</maven.compiler.source>
12+
<maven.compiler.target>${java.version}</maven.compiler.target>
13+
<maven.compiler.release>${java.version}</maven.compiler.release>
1114
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1215
</properties>
1316

@@ -38,16 +41,22 @@
3841
<plugin>
3942
<groupId>org.apache.maven.plugins</groupId>
4043
<artifactId>maven-compiler-plugin</artifactId>
41-
<version>3.11.0</version>
44+
<version>3.12.1</version>
4245
<configuration>
43-
<source>17</source>
44-
<target>17</target>
46+
<release>${java.version}</release>
47+
<compilerArgs>
48+
<arg>-parameters</arg>
49+
<arg>-Xlint:unchecked</arg>
50+
<arg>-Xlint:deprecation</arg>
51+
<arg>-Werror</arg>
52+
</compilerArgs>
4553
</configuration>
4654
</plugin>
55+
4756
<plugin>
4857
<groupId>org.codehaus.mojo</groupId>
4958
<artifactId>exec-maven-plugin</artifactId>
50-
<version>3.1.0</version>
59+
<version>3.1.1</version>
5160
<configuration>
5261
<mainClass>io.logdash.check.Check</mainClass>
5362
</configuration>

examples/example-simple-java/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
2+
<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">
33
<modelVersion>4.0.0</modelVersion>
44

55
<groupId>com.example</groupId>
@@ -32,6 +32,7 @@
3232

3333
<build>
3434
<plugins>
35+
<!-- Compiler Plugin -->
3536
<plugin>
3637
<groupId>org.apache.maven.plugins</groupId>
3738
<artifactId>maven-compiler-plugin</artifactId>
@@ -40,6 +41,9 @@
4041
<release>${maven.compiler.release}</release>
4142
<compilerArgs>
4243
<arg>-parameters</arg>
44+
<arg>-Xlint:unchecked</arg>
45+
<arg>-Xlint:deprecation</arg>
46+
<arg>-Werror</arg>
4347
</compilerArgs>
4448
</configuration>
4549
</plugin>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM eclipse-temurin:21-jre-alpine
2+
3+
WORKDIR /app
4+
COPY target/springboot-example-*.jar app.jar
5+
6+
EXPOSE 8080
7+
ENTRYPOINT ["java", "-jar", "app.jar"]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: '3.8'
2+
services:
3+
app:
4+
build: .
5+
ports:
6+
- '8080:8080'
7+
environment:
8+
- LOGDASH_API_KEY=${LOGDASH_API_KEY:-your-api-key}
9+
- SPRING_PROFILES_ACTIVE=${SPRING_PROFILES_ACTIVE:-dev}
10+
healthcheck:
11+
test: ["CMD", "wget", "--quiet", "--tries=1", "--spider", "http://localhost:8080/actuator/health"]
12+
interval: 30s
13+
timeout: 10s
14+
retries: 3
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-starter-parent</artifactId>
8+
<version>3.4.6</version>
9+
<relativePath/>
10+
</parent>
11+
12+
<groupId>io.logdash.example</groupId>
13+
<artifactId>springboot-example</artifactId>
14+
<version>0.2.0-SNAPSHOT</version>
15+
<packaging>jar</packaging>
16+
17+
<name>Logdash Spring Boot Example</name>
18+
<description>Spring Boot application demonstrating Logdash Java SDK usage</description>
19+
20+
<properties>
21+
<java.version>21</java.version>
22+
<maven.compiler.source>${java.version}</maven.compiler.source>
23+
<maven.compiler.target>${java.version}</maven.compiler.target>
24+
<maven.compiler.release>${java.version}</maven.compiler.release>
25+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
26+
27+
<!-- Logdash SDK Version -->
28+
<logdash-sdk.version>0.2.0-SNAPSHOT</logdash-sdk.version>
29+
30+
<!-- Plugin versions -->
31+
<maven-help-plugin.version>3.5.1</maven-help-plugin.version>
32+
</properties>
33+
34+
<dependencies>
35+
<!-- Spring Boot Starters -->
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-web</artifactId>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.boot</groupId>
42+
<artifactId>spring-boot-starter-actuator</artifactId>
43+
</dependency>
44+
45+
<!-- Logdash SDK -->
46+
<dependency>
47+
<groupId>io.logdash</groupId>
48+
<artifactId>logdash</artifactId>
49+
<version>${logdash-sdk.version}</version>
50+
</dependency>
51+
52+
<!-- Test Dependencies -->
53+
<dependency>
54+
<groupId>org.springframework.boot</groupId>
55+
<artifactId>spring-boot-starter-test</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
</dependencies>
59+
60+
<repositories>
61+
<!-- Maven Central Snapshots -->
62+
<repository>
63+
<releases>
64+
<enabled>false</enabled>
65+
</releases>
66+
<snapshots>
67+
<enabled>true</enabled>
68+
<updatePolicy>interval:60</updatePolicy>
69+
</snapshots>
70+
<id>maven-central-snapshots</id>
71+
<name>Maven Central Snapshots</name>
72+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
73+
</repository>
74+
</repositories>
75+
76+
<build>
77+
<plugins>
78+
<plugin>
79+
<groupId>org.springframework.boot</groupId>
80+
<artifactId>spring-boot-maven-plugin</artifactId>
81+
<configuration>
82+
<mainClass>io.logdash.example.SpringBootExampleApplication</mainClass>
83+
</configuration>
84+
</plugin>
85+
86+
<!-- Compiler Plugin -->
87+
<plugin>
88+
<groupId>org.apache.maven.plugins</groupId>
89+
<artifactId>maven-compiler-plugin</artifactId>
90+
<version>${maven-compiler-plugin.version}</version>
91+
<configuration>
92+
<release>${java.version}</release>
93+
<compilerArgs>
94+
<arg>-parameters</arg>
95+
<arg>-Xlint:unchecked</arg>
96+
<arg>-Xlint:deprecation</arg>
97+
<arg>-Werror</arg>
98+
</compilerArgs>
99+
</configuration>
100+
</plugin>
101+
102+
<plugin>
103+
<groupId>org.apache.maven.plugins</groupId>
104+
<artifactId>maven-help-plugin</artifactId>
105+
<version>${maven-help-plugin.version}</version>
106+
</plugin>
107+
</plugins>
108+
</build>
109+
110+
<profiles>
111+
<profile>
112+
<id>local-dev</id>
113+
<activation>
114+
<activeByDefault>true</activeByDefault>
115+
</activation>
116+
<repositories>
117+
<repository>
118+
<snapshots>
119+
<updatePolicy>never</updatePolicy>
120+
</snapshots>
121+
<id>maven-central-snapshots</id>
122+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
123+
</repository>
124+
</repositories>
125+
</profile>
126+
127+
<profile>
128+
<id>force-remote</id>
129+
<build>
130+
<plugins>
131+
<plugin>
132+
<groupId>org.apache.maven.plugins</groupId>
133+
<artifactId>maven-dependency-plugin</artifactId>
134+
<executions>
135+
<execution>
136+
<id>purge-local-logdash</id>
137+
<goals>
138+
<goal>purge-local-repository</goal>
139+
</goals>
140+
<phase>initialize</phase>
141+
<configuration>
142+
<includes>
143+
<include>io.logdash:logdash</include>
144+
</includes>
145+
<snapshotsOnly>true</snapshotsOnly>
146+
</configuration>
147+
</execution>
148+
</executions>
149+
</plugin>
150+
</plugins>
151+
</build>
152+
</profile>
153+
</profiles>
154+
155+
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### Variables
2+
@baseUrl = http://localhost:8080
3+
4+
### Get all pets
5+
GET {{baseUrl}}/api/pets
6+
7+
### Get pet by ID
8+
GET {{baseUrl}}/api/pets/1
9+
10+
### Create a new pet
11+
POST {{baseUrl}}/api/pets
12+
Content-Type: application/json
13+
14+
{
15+
"name": "Fluffy",
16+
"type": "DOG"
17+
}
18+
19+
### Create a random pet
20+
POST {{baseUrl}}/api/pets/random
21+
22+
### Delete a pet by ID
23+
DELETE {{baseUrl}}/api/pets/3
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.logdash.example;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.scheduling.annotation.EnableScheduling;
6+
7+
@SpringBootApplication
8+
@EnableScheduling
9+
public class SpringBootExampleApplication {
10+
11+
public static void main(String[] args) {
12+
SpringApplication.run(SpringBootExampleApplication.class, args);
13+
}
14+
}

0 commit comments

Comments
 (0)