org.dbflute.system.QLog Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dbflute-runtime Show documentation
Show all versions of dbflute-runtime Show documentation
The runtime library of DBFlute
/*
* Copyright 2014-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.dbflute.system;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author jflute
*/
public class QLog {
// ===================================================================================
// Definition
// ==========
/** The logger instance for this class. (NotNull) */
private static final Logger _log = LoggerFactory.getLogger(QLog.class);
protected static boolean _queryLogLevelInfo;
protected static boolean _loggingInHolidayMood;
protected static boolean _locked = true;
// ===================================================================================
// Query Logging
// =============
public static void log(String sql) { // very Internal
if (_queryLogLevelInfo) {
_log.info(sql);
} else {
_log.debug(sql);
}
}
public static boolean isLogEnabled() { // very internal
if (_loggingInHolidayMood) {
return false;
}
if (_queryLogLevelInfo) {
return _log.isInfoEnabled();
} else {
return _log.isDebugEnabled();
}
}
// ===================================================================================
// Logging Adjustment
// ==================
public static boolean isQueryLogLevelInfo() {
return _queryLogLevelInfo;
}
public static void setQueryLogLevelInfo(boolean queryLogLevelInfo) {
assertUnlocked();
if (_log.isInfoEnabled()) {
_log.info("...Setting queryLogLevelInfo: " + queryLogLevelInfo);
}
_queryLogLevelInfo = queryLogLevelInfo;
lock(); // auto-lock here, because of deep world
}
protected static boolean isLoggingInHolidayMood() {
return _loggingInHolidayMood;
}
public static void setLoggingInHolidayMood(boolean loggingInHolidayMood) {
assertUnlocked();
if (_log.isInfoEnabled()) {
_log.info("...Setting loggingInHolidayMood: " + loggingInHolidayMood);
}
_loggingInHolidayMood = loggingInHolidayMood;
lock(); // auto-lock here, because of deep world
}
// ===================================================================================
// Logging Lock
// ============
public static boolean isLocked() {
return _locked;
}
public static void lock() {
if (_locked) {
return;
}
if (_log.isInfoEnabled()) {
_log.info("...Locking the log object for query!");
}
_locked = true;
}
public static void unlock() {
if (!_locked) {
return;
}
if (_log.isInfoEnabled()) {
_log.info("...Unlocking the log object for query!");
}
_locked = false;
}
protected static void assertUnlocked() {
if (!isLocked()) {
return;
}
throw new IllegalStateException("The query log is locked.");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy