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

mybatis / ibatis-2 / 725

28 Dec 2025 10:15PM UTC coverage: 65.615% (+0.03%) from 65.584%
725

push

github

web-flow
Merge branch 'master' into support-javax

1602 of 2802 branches covered (57.17%)

214 of 279 new or added lines in 50 files covered. (76.7%)

26 existing lines in 11 files now uncovered.

5053 of 7701 relevant lines covered (65.61%)

0.66 hits per line

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

42.86
/src/main/java/com/ibatis/common/logging/LogFactory.java
1
/*
2
 * Copyright 2004-2025 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
 *    https://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
package com.ibatis.common.logging;
17

18
import com.ibatis.common.resources.Resources;
19

20
import java.lang.reflect.Constructor;
21

22
/**
23
 * A factory for creating Log objects.
24
 */
25
public class LogFactory {
×
26

27
  /** The log constructor. */
28
  private static Constructor logConstructor;
29

30
  static {
31
    tryImplementation("org.apache.commons.logging.LogFactory",
1✔
32
        "com.ibatis.common.logging.jakarta.JakartaCommonsLoggingImpl");
33
    tryImplementation("org.apache.log4j.Logger", "com.ibatis.common.logging.log4j.Log4jImpl");
1✔
34
    tryImplementation("java.util.logging.Logger", "com.ibatis.common.logging.jdk14.Jdk14LoggingImpl");
1✔
35
    tryImplementation("java.lang.Object", "com.ibatis.common.logging.nologging.NoLoggingImpl");
1✔
36
  }
1✔
37

38
  /**
39
   * Try implementation.
40
   *
41
   * @param testClassName
42
   *          the test class name
43
   * @param implClassName
44
   *          the impl class name
45
   */
46
  private static void tryImplementation(String testClassName, String implClassName) {
47
    if (logConstructor == null) {
1✔
48
      try {
49
        Resources.classForName(testClassName);
1✔
50
        Class implClass = Resources.classForName(implClassName);
1✔
51
        logConstructor = implClass.getConstructor(Class.class);
1✔
52
      } catch (Throwable t) {
×
53
      }
1✔
54
    }
55
  }
1✔
56

57
  /**
58
   * Gets the log.
59
   *
60
   * @param aClass
61
   *          the a class
62
   *
63
   * @return the log
64
   */
65
  public static Log getLog(Class aClass) {
66
    try {
67
      return (Log) logConstructor.newInstance(aClass);
1✔
68
    } catch (Throwable t) {
×
69
      throw new RuntimeException("Error creating logger for class " + aClass + ".  Cause: " + t, t);
×
70
    }
71
  }
72

73
  /**
74
   * This method will switch the logging implementation to Log4J if Log4J is available on the classpath. This is useful
75
   * in situations where you want to use Log4J to log iBATIS activity but commons logging is on the classpath. Note that
76
   * this method is only effective for log classes obtained after calling this method. If you intend to use this method
77
   * you should call it before calling any other iBATIS method.
78
   */
79
  public static synchronized void selectLog4JLogging() {
80
    try {
81
      Resources.classForName("org.apache.log4j.Logger");
×
82
      Class implClass = Resources.classForName("com.ibatis.common.logging.log4j.Log4jImpl");
×
NEW
83
      logConstructor = implClass.getConstructor(Class.class);
×
84
    } catch (Throwable t) {
×
85
    }
×
86
  }
×
87

88
  /**
89
   * This method will switch the logging implementation to Java native logging if you are running in JRE 1.4 or above.
90
   * This is useful in situations where you want to use Java native logging to log iBATIS activity but commons logging
91
   * or Log4J is on the classpath. Note that this method is only effective for log classes obtained after calling this
92
   * method. If you intend to use this method you should call it before calling any other iBATIS method.
93
   */
94
  public static synchronized void selectJavaLogging() {
95
    try {
96
      Resources.classForName("java.util.logging.Logger");
×
97
      Class implClass = Resources.classForName("com.ibatis.common.logging.jdk14.Jdk14LoggingImpl");
×
NEW
98
      logConstructor = implClass.getConstructor(Class.class);
×
99
    } catch (Throwable t) {
×
100
    }
×
101
  }
×
102
}
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