• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

andrey-vasilyev / spring-boot-starter-log4jdbc / #54

11 Mar 2025 08:53AM CUT coverage: 100.0%. Remained the same
#54

push

github

web-flow
Bump org.springframework.boot:spring-boot-dependencies (#60)

Bumps [org.springframework.boot:spring-boot-dependencies](https://github.com/spring-projects/spring-boot) from 3.4.2 to 3.4.3.
- [Release notes](https://github.com/spring-projects/spring-boot/releases)
- [Commits](https://github.com/spring-projects/spring-boot/compare/v3.4.2...v3.4.3)

---
updated-dependencies:
- dependency-name: org.springframework.boot:spring-boot-dependencies
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

13 of 13 relevant lines covered (100.0%)

1.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/main/java/ru/vasiand/spring/boot/log4jdbc/Log4jdbcBeanPostProcessor.java
1
/*
2
 * Copyright 2012-2016 the original author or authors.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *      http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package ru.vasiand.spring.boot.log4jdbc;
18

19

20
import jakarta.annotation.PostConstruct;
21
import net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator;
22
import net.sf.log4jdbc.sql.jdbcapi.DataSourceSpy;
23

24
import org.springframework.beans.BeansException;
25
import org.springframework.beans.factory.annotation.Autowired;
26
import org.springframework.beans.factory.config.BeanPostProcessor;
27
import org.springframework.core.env.Environment;
28

29
import javax.sql.DataSource;
30

31
import static ru.vasiand.spring.boot.log4jdbc.Log4jdbcProperties.PROPERTIES;
32

33
/**
34
 * A {@link BeanPostProcessor} implementation that sets up log4jdbc logging.
35
 *
36
 * @see net.sf.log4jdbc.Properties
37
 */
38
public class Log4jdbcBeanPostProcessor implements BeanPostProcessor {
1✔
39
    @Autowired
40
    private Environment environment;
41

42
    @Override
43
    public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException {
44
        if (bean instanceof DataSource) {
1✔
45
            return new DataSourceSpy((DataSource) bean);
1✔
46
        }
47
        else {
48
            return bean;
1✔
49
        }
50
    }
51

52
    @Override
53
    public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException {
54
        return bean;
1✔
55
    }
56

57
    @PostConstruct
58
    public void postConstruct() {
59
        // Log4jdbc only reads configuration from system properties, so copy relevant environment property to system properties
60
        // See net.sf.log4jdbc.Properties.getProperties()
61
        for (final String property : PROPERTIES) {
1✔
62
            if (this.environment.containsProperty(property)) {
1✔
63
                System.setProperty(property, this.environment.getRequiredProperty(property));
1✔
64
            }
65
        }
66
        // Use slf4j by default.
67
        // Most users will have slf4j configured (because Spring does that by default) and they won't be using log4j (which is the log4jdbc default)
68
        System.setProperty(
1✔
69
            "log4jdbc.spylogdelegator.name",
70
            this.environment.getProperty("log4jdbc.spylogdelegator.name", Slf4jSpyLogDelegator.class.getName())
1✔
71
        );
72
    }
1✔
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc