Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
To be honest, it's not entirely clear what you want.
The database has logging. Here, for example, PostgreSQL
If we are talking about hibernate & jpa logs, then here is a useful article:
https://www.baeldung.com/sql-logging-spring-boot
You can set the logging level, and then, for example, output the logs to a file
If we are talking about Spring & Hibernate (about listening), for example, when which entity was added or updated, that is, for example, EntityListeners.
Here is a simple example:
@SpringBootApplication
@EnableJpaAuditing
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@CreatedDate
@Column(updatable = false)
private LocalDateTime created;
@LastModifiedDate
private LocalDateTime lastModified;
}
To log in a DB (in the separate table) the spring quite can. But this is usually not a very good solution. In industrial use, it is still better to log to a file, then logstash -> elastic -> grafana/kibana or a similar stack. You can graylog - in general, there are a lot of solutions and it usually makes little sense to load a relational database with logs.
Decide what you want to log.
1. the level of the database event is already dropped into the system log
2. Schema changes, depends on the DBMS and is configured in some
3. Data change, just add the user to a separate field
4. Versioning, the same as in pp3 but the version and changed columns ( strongly do not advise)
5. Blame trigger for some actions, written in a separate table, it all depends on the business
Something else. Describe what you want in the context of the business, just explain how stupid. Where, who, why and what
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question