Installation¶
Requirements¶
- Java 21+ (Virtual Threads are recommended but not required)
- Spring Boot 3.5+
- PostgreSQL 15+ (the storage layer relies on JSONB; older versions work but lose some operators)
Adding the dependency¶
Latest version
Replace 0.3.0 with the latest from Maven Central.
What the starter pulls in¶
The starter brings these for you transitively:
spring-boot-starter-data-jpa(theApiLogRepository)spring-boot-starter-web(the bundledRestApiClientUtil)spring-retry(retry-aware logging)jackson-module-blackbird(high-throughput JSON serialization)postgresqlJDBC driver (runtime)
Flyway is optional — only needed if you set api.log.schema.management=flyway (see Schema management below). The default doesn't need it.
What you bring yourself¶
- A PostgreSQL
DataSource— the starter doesn't configure database connection details for you - An
ObjectMapperbean — Spring Boot's auto-configured one is sufficient
That's it. With the default settings, the api_log table is created for you on first boot.
spring:
datasource:
url: jdbc:postgresql://localhost:5432/your_db
username: your_user
password: your_password
threads:
virtual:
enabled: true # recommended on Java 21+
# Both of these have working defaults — only set them when you want non-default behavior.
api:
log:
enabled: true # default — false disables the whole infrastructure
schema:
management: builtin # default — see "Schema management" below
What auto-configuration does¶
When the starter is on the classpath and api.log.enabled is true (the default), ApiLogAutoConfiguration activates and registers:
ApiLogService— the persistence orchestrator (gated on anObjectMapperbean)ApiEventListener— the@EventListener(async) that bridges events to the serviceRetryConfig— enables@EnableRetryfor Spring Retry integrationApiLogSchemaInitializer— runsCREATE TABLE IF NOT EXISTSon startup (active forschema.management=builtin, the default)- JPA
@EntityScanand@EnableJpaRepositoriesscoped tokr.devslab.apilog.modelandkr.devslab.apilog.repository
All beans use @ConditionalOnMissingBean. Define your own to override.
Schema management¶
How the api_log table is created depends on api.log.schema.management:
On every application startup, the starter runs the bundled V1.0__create_api_log.sql
against your DataSource. The DDL uses CREATE TABLE IF NOT EXISTS / CREATE INDEX IF NOT EXISTS,
so it's idempotent — re-running on every boot is a no-op once the table exists.
No extra dependencies needed. No external migration tool. Just works.
The schema is applied via Spring Boot's
DataSourceScriptDatabaseInitializer,
so it runs BEFORE JPA's entity validation — a fresh database won't fail Hibernate's
ddl-auto=validate check at boot.
Add Flyway to your dependencies:
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-database-postgresql</artifactId>
<scope>runtime</scope>
</dependency>
Then set:
The starter registers a FlywayConfigurationCustomizer that appends classpath:db/api-log to your existing spring.flyway.locations. Your own migrations run alongside ours, and flyway_schema_history tracks V1.0__create_api_log like any other migration.
Pick this if your team treats the flyway_schema_history row as the authoritative record of schema changes.
The starter does not touch the schema. Take the SQL from the Schema reference and put it in:
- your own Liquibase changelog, or
- a manual
psqlrun during deployment, or - your own startup script
Pick this if your team's policy forbids third-party libraries from touching the schema, or if the table is already provisioned by infrastructure you don't want to overlap with.
Verifying the install¶
After adding the dependency and starting your app:
- The auto-configuration loads. With
--debugyou'll seeApiLogAutoConfiguration matched. - The
api_logtable exists — for BUILTIN, this happens automatically. For FLYWAY, you'll see Flyway's standard "applied 1 migration" log line. For NONE, you applied it yourself.
Continue to the Quickstart to make your first logged call.