From 0426d4ee9a0c3120fc39a4fbfafd5c73ac330301 Mon Sep 17 00:00:00 2001 From: StefanMoCoAt Date: Thu, 16 Apr 2026 18:47:32 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20vereinheitliche=20Startup-Logs=20in=20a?= =?UTF-8?q?llen=20Backend-Services,=20verbessere=20Konsistenz=20und=20Diag?= =?UTF-8?q?nosem=C3=B6glichkeiten?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: StefanMoCoAt --- .../gateway/GatewayApplication.kt | 33 ++++++----- .../service/BillingServiceApplication.kt | 21 ++++++- .../service/EntriesServiceApplication.kt | 20 ++++++- .../service/EventsServiceApplication.kt | 21 ++++++- .../service/IdentityServiceApplication.kt | 21 ++++++- .../mail/service/MailServiceApplication.kt | 21 ++++++- .../at/mocode/ping/PingServiceApplication.kt | 21 ++++++- .../service/ResultsServiceApplication.kt | 21 ++++++- .../service/SchedulingServiceApplication.kt | 21 ++++++- .../service/SeriesServiceApplication.kt | 21 ++++++- .../service/ZnsImportServiceApplication.kt | 20 ++++++- .../2026-04-16_Consolidated-Startup-Logs.md | 58 +++++++++++++++++++ 12 files changed, 275 insertions(+), 24 deletions(-) create mode 100644 docs/99_Journal/2026-04-16_Consolidated-Startup-Logs.md diff --git a/backend/infrastructure/gateway/src/main/kotlin/at/mocode/infrastructure/gateway/GatewayApplication.kt b/backend/infrastructure/gateway/src/main/kotlin/at/mocode/infrastructure/gateway/GatewayApplication.kt index 38637b95..097d8735 100644 --- a/backend/infrastructure/gateway/src/main/kotlin/at/mocode/infrastructure/gateway/GatewayApplication.kt +++ b/backend/infrastructure/gateway/src/main/kotlin/at/mocode/infrastructure/gateway/GatewayApplication.kt @@ -1,25 +1,30 @@ package at.mocode.infrastructure.gateway import org.slf4j.LoggerFactory -import org.springframework.beans.factory.getBean import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication +import org.springframework.context.event.EventListener import org.springframework.core.env.Environment @SpringBootApplication -class GatewayApplication +class GatewayApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(GatewayApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8081") + val appName = env.getProperty("spring.application.name", "gateway") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} fun main(args: Array) { - val context = runApplication(*args) - val logger = LoggerFactory.getLogger(GatewayApplication::class.java) - val env = context.getBean() - val port = env.getProperty("server.port") ?: "8081" - - logger.info(""" - ---------------------------------------------------------- - Application 'Gateway' is running! - Port: $port - Profiles: ${env.activeProfiles.joinToString(", ").ifEmpty { "default" }} - ---------------------------------------------------------- - """.trimIndent()) + runApplication(*args) } diff --git a/backend/services/billing/billing-service/src/main/kotlin/at/mocode/billing/service/BillingServiceApplication.kt b/backend/services/billing/billing-service/src/main/kotlin/at/mocode/billing/service/BillingServiceApplication.kt index 032f23c1..6d11dcc7 100644 --- a/backend/services/billing/billing-service/src/main/kotlin/at/mocode/billing/service/BillingServiceApplication.kt +++ b/backend/services/billing/billing-service/src/main/kotlin/at/mocode/billing/service/BillingServiceApplication.kt @@ -2,14 +2,33 @@ package at.mocode.billing.service +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication import org.springframework.cloud.client.discovery.EnableDiscoveryClient +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment import kotlin.uuid.ExperimentalUuidApi @EnableDiscoveryClient @SpringBootApplication -class BillingServiceApplication +class BillingServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(BillingServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8087") + val appName = env.getProperty("spring.application.name", "billing-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} fun main(args: Array) { runApplication(*args) diff --git a/backend/services/entries/entries-service/src/main/kotlin/at/mocode/entries/service/EntriesServiceApplication.kt b/backend/services/entries/entries-service/src/main/kotlin/at/mocode/entries/service/EntriesServiceApplication.kt index 9554b272..92cf076b 100644 --- a/backend/services/entries/entries-service/src/main/kotlin/at/mocode/entries/service/EntriesServiceApplication.kt +++ b/backend/services/entries/entries-service/src/main/kotlin/at/mocode/entries/service/EntriesServiceApplication.kt @@ -1,9 +1,13 @@ package at.mocode.entries.service +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication import org.springframework.context.annotation.Bean import org.springframework.context.annotation.EnableAspectJAutoProxy +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment import org.springframework.web.servlet.config.annotation.CorsRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer @@ -13,7 +17,21 @@ fun main(args: Array) { @SpringBootApplication(scanBasePackages = ["at.mocode.entries", "at.mocode.billing", "at.mocode.infrastructure.security"]) @EnableAspectJAutoProxy -class EntriesServiceApplication { +class EntriesServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(EntriesServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8084") + val appName = env.getProperty("spring.application.name", "entries-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } @Bean fun corsConfigurer(): WebMvcConfigurer { diff --git a/backend/services/events/events-service/src/main/kotlin/at/mocode/events/service/EventsServiceApplication.kt b/backend/services/events/events-service/src/main/kotlin/at/mocode/events/service/EventsServiceApplication.kt index d4158d77..87c1b6aa 100644 --- a/backend/services/events/events-service/src/main/kotlin/at/mocode/events/service/EventsServiceApplication.kt +++ b/backend/services/events/events-service/src/main/kotlin/at/mocode/events/service/EventsServiceApplication.kt @@ -1,8 +1,12 @@ package at.mocode.events.service +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication import org.springframework.cloud.client.discovery.EnableDiscoveryClient +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment /** * Main application class for the Events Service. @@ -11,7 +15,22 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient */ @SpringBootApplication @EnableDiscoveryClient -class EventsServiceApplication +class EventsServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(EventsServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8085") + val appName = env.getProperty("spring.application.name", "events-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} /** * Main entry point for the Events Service application. diff --git a/backend/services/identity/identity-service/src/main/kotlin/at/mocode/identity/service/IdentityServiceApplication.kt b/backend/services/identity/identity-service/src/main/kotlin/at/mocode/identity/service/IdentityServiceApplication.kt index 3453b8f6..74061975 100644 --- a/backend/services/identity/identity-service/src/main/kotlin/at/mocode/identity/service/IdentityServiceApplication.kt +++ b/backend/services/identity/identity-service/src/main/kotlin/at/mocode/identity/service/IdentityServiceApplication.kt @@ -1,10 +1,29 @@ package at.mocode.identity.service +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment @SpringBootApplication(scanBasePackages = ["at.mocode.identity", "at.mocode.infrastructure.security", "at.mocode.backend.infrastructure.persistence"]) -class IdentityServiceApplication +class IdentityServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(IdentityServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8089") + val appName = env.getProperty("spring.application.name", "identity-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} fun main(args: Array) { runApplication(*args) diff --git a/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/MailServiceApplication.kt b/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/MailServiceApplication.kt index 3fd84fd1..db13b5e6 100644 --- a/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/MailServiceApplication.kt +++ b/backend/services/mail/mail-service/src/main/kotlin/at/mocode/mail/service/MailServiceApplication.kt @@ -1,10 +1,29 @@ package at.mocode.mail.service +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment @SpringBootApplication -class MailServiceApplication +class MailServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(MailServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8083") + val appName = env.getProperty("spring.application.name", "mail-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} fun main(args: Array) { runApplication(*args) diff --git a/backend/services/ping/ping-service/src/main/kotlin/at/mocode/ping/PingServiceApplication.kt b/backend/services/ping/ping-service/src/main/kotlin/at/mocode/ping/PingServiceApplication.kt index 2296d043..297f9160 100644 --- a/backend/services/ping/ping-service/src/main/kotlin/at/mocode/ping/PingServiceApplication.kt +++ b/backend/services/ping/ping-service/src/main/kotlin/at/mocode/ping/PingServiceApplication.kt @@ -1,15 +1,34 @@ package at.mocode.ping +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.EnableAspectJAutoProxy +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment @SpringBootApplication @EnableAspectJAutoProxy // Scannt das eigene Service-Package UND das Security-Infrastruktur-Package @ComponentScan(basePackages = ["at.mocode.ping", "at.mocode.infrastructure.security"]) -class PingServiceApplication +class PingServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(PingServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8082") + val appName = env.getProperty("spring.application.name", "ping-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} fun main(args: Array) { runApplication(*args) diff --git a/backend/services/results/results-service/src/main/kotlin/at/mocode/results/service/ResultsServiceApplication.kt b/backend/services/results/results-service/src/main/kotlin/at/mocode/results/service/ResultsServiceApplication.kt index a231f4f6..12d5e7a0 100644 --- a/backend/services/results/results-service/src/main/kotlin/at/mocode/results/service/ResultsServiceApplication.kt +++ b/backend/services/results/results-service/src/main/kotlin/at/mocode/results/service/ResultsServiceApplication.kt @@ -2,14 +2,33 @@ package at.mocode.results.service import at.mocode.results.service.application.ResultsService import at.mocode.results.service.domain.Ergebnis +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication import org.springframework.cloud.client.discovery.EnableDiscoveryClient +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment import org.springframework.web.bind.annotation.* @SpringBootApplication @EnableDiscoveryClient -class ResultsServiceApplication +class ResultsServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(ResultsServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8088") + val appName = env.getProperty("spring.application.name", "results-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} fun main(args: Array) { runApplication(*args) diff --git a/backend/services/scheduling/scheduling-service/src/main/kotlin/at/mocode/scheduling/service/SchedulingServiceApplication.kt b/backend/services/scheduling/scheduling-service/src/main/kotlin/at/mocode/scheduling/service/SchedulingServiceApplication.kt index ccc63502..b5d8a5e9 100644 --- a/backend/services/scheduling/scheduling-service/src/main/kotlin/at/mocode/scheduling/service/SchedulingServiceApplication.kt +++ b/backend/services/scheduling/scheduling-service/src/main/kotlin/at/mocode/scheduling/service/SchedulingServiceApplication.kt @@ -1,12 +1,31 @@ package at.mocode.scheduling.service +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RestController @SpringBootApplication -class SchedulingServiceApplication +class SchedulingServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(SchedulingServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8089") + val appName = env.getProperty("spring.application.name", "scheduling-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} fun main(args: Array) { runApplication(*args) diff --git a/backend/services/series/series-service/src/main/kotlin/at/mocode/series/service/SeriesServiceApplication.kt b/backend/services/series/series-service/src/main/kotlin/at/mocode/series/service/SeriesServiceApplication.kt index fcb0e2c8..2f21561b 100644 --- a/backend/services/series/series-service/src/main/kotlin/at/mocode/series/service/SeriesServiceApplication.kt +++ b/backend/services/series/series-service/src/main/kotlin/at/mocode/series/service/SeriesServiceApplication.kt @@ -3,14 +3,33 @@ package at.mocode.series.service import at.mocode.series.service.application.SeriesService import at.mocode.series.service.domain.Serie import at.mocode.series.service.domain.SeriePunkt +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication import org.springframework.cloud.client.discovery.EnableDiscoveryClient +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment import org.springframework.web.bind.annotation.* @SpringBootApplication @EnableDiscoveryClient -class SeriesServiceApplication +class SeriesServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(SeriesServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8089") + val appName = env.getProperty("spring.application.name", "series-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } +} fun main(args: Array) { runApplication(*args) diff --git a/backend/services/zns-import/zns-import-service/src/main/kotlin/at/mocode/zns/import/service/ZnsImportServiceApplication.kt b/backend/services/zns-import/zns-import-service/src/main/kotlin/at/mocode/zns/import/service/ZnsImportServiceApplication.kt index 79b1843a..1b715a3c 100644 --- a/backend/services/zns-import/zns-import-service/src/main/kotlin/at/mocode/zns/import/service/ZnsImportServiceApplication.kt +++ b/backend/services/zns-import/zns-import-service/src/main/kotlin/at/mocode/zns/import/service/ZnsImportServiceApplication.kt @@ -2,12 +2,30 @@ package at.mocode.zns.import.service import at.mocode.masterdata.domain.repository.* import at.mocode.zns.importer.ZnsImportService +import org.slf4j.LoggerFactory import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.context.event.ApplicationReadyEvent import org.springframework.boot.runApplication import org.springframework.context.annotation.Bean +import org.springframework.context.event.EventListener +import org.springframework.core.env.Environment @SpringBootApplication -class ZnsImportServiceApplication { +class ZnsImportServiceApplication(private val env: Environment) { + + private val log = LoggerFactory.getLogger(ZnsImportServiceApplication::class.java) + + @EventListener(ApplicationReadyEvent::class) + fun onApplicationReady() { + val springPort = env.getProperty("server.port", "8095") + val appName = env.getProperty("spring.application.name", "zns-import-service") + + log.info("----------------------------------------------------------") + log.info("Application '{}' is running!", appName) + log.info("Spring Management Port: {}", springPort) + log.info("Profiles: {}", env.activeProfiles.joinToString(", ")) + log.info("----------------------------------------------------------") + } @Bean fun znsImportService( diff --git a/docs/99_Journal/2026-04-16_Consolidated-Startup-Logs.md b/docs/99_Journal/2026-04-16_Consolidated-Startup-Logs.md new file mode 100644 index 00000000..ec271c84 --- /dev/null +++ b/docs/99_Journal/2026-04-16_Consolidated-Startup-Logs.md @@ -0,0 +1,58 @@ +# 📓 Journal-Eintrag: 2026-04-16 - Vereinheitlichung der Service-Start-Logs + +## 🏗️ Status Quo + +Nach dem Vorbild des `masterdata-service` sollten alle Backend-Services konsistente Informationen beim Start in die +Konsole loggen. + +## 🚀 Umgesetzte Änderungen + +### 1. onApplicationReady() Implementierung + +In allen 11 Backend-Services wurde die Methode `onApplicationReady()` in der jeweiligen Application-Klasse +implementiert. Diese reagiert auf das `ApplicationReadyEvent` von Spring Boot. + +**Betroffene Services:** + +- `api-gateway` +- `masterdata-service` (bereits vorhanden) +- `events-service` +- `zns-import-service` +- `ping-service` +- `billing-service` +- `entries-service` +- `identity-service` +- `mail-service` +- `results-service` +- `scheduling-service` +- `series-service` + +### 2. Standardisiertes Log-Format + +Das Log-Format wurde vereinheitlicht und gibt nun folgende Informationen aus: + +- Anwendungsname (aus `spring.application.name`) +- Spring Management Port (Actuator) +- Ktor API Port (falls zutreffend, z.B. bei `masterdata-service`) +- Aktive Spring-Profile + +**Beispiel:** + +``` +---------------------------------------------------------- +Application 'events-service' is running! +Spring Management Port: 8085 +Profiles: docker +---------------------------------------------------------- +``` + +## 🛠️ Technische Details + +- Verwendung von `@EventListener(ApplicationReadyEvent::class)` für den exakten Zeitpunkt, wenn die App bereit ist. +- Dynamisches Auslesen der Ports und Profile über das `Environment` Objekt. +- Bereinigung der `main`-Funktion im API Gateway zugunsten des deklarativen `@EventListener` Ansatzes. + +--- +**🧹 [Curator]**: Start-Logs über alle Backend-Services hinweg konsolidiert. +**👷 [Backend Developer]**: Alle Application-Klassen konsistent refactored. +**🏗️ [Lead Architect]**: Observability und Diagnosemöglichkeiten beim Systemstart verbessert.