1 /*
2 * Copyright 2010-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 org.mybatis.logging;
17
18 import java.util.function.Supplier;
19
20 import org.apache.ibatis.logging.Log;
21
22 /**
23 * Wrapper of {@link Log}, allow log with lambda expressions.
24 *
25 * @author Putthiphong Boonphong
26 */
27 public class Logger {
28
29 /** The log. */
30 private final Log log;
31
32 /**
33 * Instantiates a new logger.
34 *
35 * @param log
36 * the log
37 */
38 Logger(Log log) {
39 this.log = log;
40 }
41
42 /**
43 * Error.
44 *
45 * @param s
46 * the s
47 * @param e
48 * the e
49 */
50 public void error(Supplier<String> s, Throwable e) {
51 log.error(s.get(), e);
52 }
53
54 /**
55 * Error.
56 *
57 * @param s
58 * the s
59 */
60 public void error(Supplier<String> s) {
61 log.error(s.get());
62 }
63
64 /**
65 * Warn.
66 *
67 * @param s
68 * the s
69 */
70 public void warn(Supplier<String> s) {
71 log.warn(s.get());
72 }
73
74 /**
75 * Debug.
76 *
77 * @param s
78 * the s
79 */
80 public void debug(Supplier<String> s) {
81 if (log.isDebugEnabled()) {
82 log.debug(s.get());
83 }
84 }
85
86 /**
87 * Trace.
88 *
89 * @param s
90 * the s
91 */
92 public void trace(Supplier<String> s) {
93 if (log.isTraceEnabled()) {
94 log.trace(s.get());
95 }
96 }
97
98 }