本文整理汇总了Java中java.util.logging.Handler.setLevel方法的典型用法代码示例。如果您正苦于以下问题:Java Handler.setLevel方法的具体用法?Java Handler.setLevel怎么用?Java Handler.setLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.logging.Handler
的用法示例。
在下文中一共展示了Handler.setLevel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setHandlers
import java.util.logging.Handler; //导入方法依赖的package包/类
private void setHandlers(Logger logger, File file) throws FileNotFoundException {
for (Handler h : logger.getHandlers()) {
logger.removeHandler(h);
}
Handler stderrHandler = new FlushedStreamHandler(System.err, noColors ? CommandLineLogFormatter.INSTANCE : CommandLineLogFormatter.COLORS);
logger.addHandler(stderrHandler);
if (file == null)
stderrHandler.setLevel(logLevel);
else {
File dir = file.getParentFile();
if (dir != null) {
dir.mkdirs();
}
Handler fileHandler = new FlushedStreamHandler(new FileOutputStream(file, appendToLog), CommandLineLogFormatter.INSTANCE);
logger.addHandler(fileHandler);
if (logLevel.intValue() < Level.FINE.intValue()) {
fileHandler.setLevel(logLevel);
stderrHandler.setLevel(Level.FINE);
}
else {
fileHandler.setLevel(Level.FINE);
stderrHandler.setLevel(logLevel);
}
}
}
示例2: PlanBuilder
import java.util.logging.Handler; //导入方法依赖的package包/类
public PlanBuilder(File planDir, File resourceDir) {
super();
this.planDir = planDir;
this.resourceDir = resourceDir;
logger = Logger.getLogger(ALVISNLP_LOGGER_NAME);
Level logLevel = Level.INFO;
logger.setLevel(logLevel);
logger.setUseParentHandlers(false);
for (Handler h : logger.getHandlers()) {
logger.removeHandler(h);
}
Handler stderrHandler = new FlushedStreamHandler(System.err, CommandLineLogFormatter.INSTANCE);
logger.addHandler(stderrHandler);
stderrHandler.setLevel(logLevel);
moduleFactory = new CompoundCorpusModuleFactory();
moduleFactory.loadServiceFactories(CorpusModuleFactory.class, null, null, null);
converterFactory = new CompoundParamConverterFactory();
converterFactory.loadServiceFactories(ParamConverterFactory.class, null, null, null);
}
示例3: disableLogging
import java.util.logging.Handler; //导入方法依赖的package包/类
public static void disableLogging() {
// Disable Logging (FastSet sometimes complains about skewed key distributions with lots of WARNINGs)
Logger root = Logger.getLogger("");
Handler[] handlers = root.getHandlers();
for (Handler handler : handlers)
handler.setLevel(Level.OFF);
}
示例4: setLogging
import java.util.logging.Handler; //导入方法依赖的package包/类
static void setLogging(Level level) {
if (LOGGER.getHandlers().length == 0) {
//System.setProperty("java.util.logging.SimpleFormatter.format", "[%4$s] MixThem: %5$s [%1$tc]%n");
System.setProperty("java.util.logging.SimpleFormatter.format", "[%4$s] MixThem: %5$s%n");
LOGGER.setUseParentHandlers(false);
LOGGER.setLevel(Level.ALL);
Handler handler = new ConsoleHandler();
LOGGER.addHandler(handler);
handler.setLevel(Level.OFF);
String prop = System.getProperty("mixthem.logging");
if (prop == null || prop.equals("true")) {
handler.setLevel(level);
}
}
}
示例5: setGlobalLevel
import java.util.logging.Handler; //导入方法依赖的package包/类
public static void setGlobalLevel(Level newLevel) {
Logger rootLogger = LogManager.getLogManager().getLogger("");
rootLogger.setLevel(newLevel);
for (Handler h : rootLogger.getHandlers()) {
h.setLevel(newLevel);
}
}
示例6: setHandlers
import java.util.logging.Handler; //导入方法依赖的package包/类
public void setHandlers(Logger logger, Level logLevel) throws FileNotFoundException {
for (Handler h : logger.getHandlers()) {
logger.removeHandler(h);
}
Handler stderrHandler = new FlushedStreamHandler(System.err, CommandLineLogFormatter.INSTANCE);
logger.addHandler(stderrHandler);
stderrHandler.setLevel(logLevel);
Handler fileHandler = new FlushedStreamHandler(new FileOutputStream(new File(processingDir, ALVISNLP_LOG_FILENAME), false), CommandLineLogFormatter.INSTANCE);
logger.addHandler(fileHandler);
fileHandler.setLevel(logLevel);
}
示例7: setupLoggers
import java.util.logging.Handler; //导入方法依赖的package包/类
/**
* Sets up loggers to print to stdout (rather than stderr) and log to ~/Shuffleboard/shuffleboard.log
*/
private void setupLoggers() throws IOException {
//Set up the global level logger. This handles IO for all loggers.
final Logger globalLogger = LogManager.getLogManager().getLogger("");
// Remove the default handlers that stream to System.err
for (Handler handler : globalLogger.getHandlers()) {
globalLogger.removeHandler(handler);
}
final Handler fileHandler = new FileHandler(Storage.getStorageDir() + "/shuffleboard.log");
fileHandler.setLevel(Level.INFO); // Only log INFO and above to disk
globalLogger.setLevel(Level.CONFIG); // Log CONFIG and higher
// We need to stream to System.out instead of System.err
final StreamHandler sh = new StreamHandler(System.out, new SimpleFormatter()) {
@Override
public synchronized void publish(final LogRecord record) { // NOPMD this is the same signature as the superclass
super.publish(record);
// For some reason this doesn't happen automatically.
// This will ensure we get all of the logs printed to the console immediately instead of at shutdown
flush();
}
};
sh.setLevel(Level.CONFIG); // Log CONFIG and higher to stdout
globalLogger.addHandler(sh);
globalLogger.addHandler(fileHandler);
fileHandler.setFormatter(new SimpleFormatter()); //log in text, not xml
globalLogger.config("Configuration done."); //Log that we are done setting up the logger
globalLogger.config("Shuffleboard app version: " + Shuffleboard.class.getPackage().getImplementationVersion());
}
示例8: enableLogging
import java.util.logging.Handler; //导入方法依赖的package包/类
public static void enableLogging() {
Logger logger = Logger.getLogger(com.sun.tools.javac.Main.class.getPackage().getName());
logger.setLevel(Level.ALL);
for (Handler h : logger.getParent().getHandlers()) {
h.setLevel(Level.ALL);
}
}
示例9: getLogger
import java.util.logging.Handler; //导入方法依赖的package包/类
private static Logger getLogger() {
Logger result = Logger.getAnonymousLogger();
result.setLevel(Level.ALL);
result.setUseParentHandlers(false);
Handler handler = new FlushedStreamHandler(System.err, new StandardFormatter());
handler.setLevel(Level.ALL);
result.addHandler(handler);
return result;
}
示例10: setRootLoggerLevel
import java.util.logging.Handler; //导入方法依赖的package包/类
/**
* Overrides the system's root logger level.
* <p>
* This is for internal testing and debugging only!
*
* @param level the level to use, not null
*/
@Nonnull
public static void setRootLoggerLevel(@Nonnull Level level) {
Objects.requireNonNull(level);
Logger rootLogger = Logger.getLogger("");
for (Handler handler : rootLogger.getHandlers())
handler.setLevel(Level.FINEST);
rootLogger.setLevel(level);
}
示例11: main
import java.util.logging.Handler; //导入方法依赖的package包/类
public static void main(String[] args) {
TestInferCaller test = new TestInferCaller();
Logger root = Logger.getLogger("");
for (Handler h : root.getHandlers()) {
h.setLevel(Level.OFF);
}
root.addHandler(new TestHandler());
for (Logger logger : Arrays.asList(root, Logger.getGlobal(),
Logger.getAnonymousLogger(), Logger.getLogger("foo.bar"))) {
System.out.println("Testing with: " + loggerName(logger) + " " + logger.getClass());
test.test(logger);
}
}
示例12: setLevel
import java.util.logging.Handler; //导入方法依赖的package包/类
private static void setLevel(Logger pLogger, Level pLevel) {
Handler[] handlers = pLogger.getHandlers();
for (Handler h : handlers) {
h.setLevel(pLevel);
}
pLogger.setLevel(pLevel);
}
示例13: onApplicationEvent
import java.util.logging.Handler; //导入方法依赖的package包/类
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (event instanceof ContextRefreshedEvent) {
Logger log = LogManager.getLogManager().getLogger("");
for (Handler h : log.getHandlers()) {
h.setLevel(Level.INFO);
}
}
}
示例14: setJDKDebugEnabled
import java.util.logging.Handler; //导入方法依赖的package包/类
/**
* 开启DEBUG级别日志(仅针对JDK14LOGGER,LOG4J请自行修改配置文件)
*
* @param isEnabled
*/
public static void setJDKDebugEnabled(Boolean isEnabled) {
//如果使用JDK14LOGGER,将业务日志级别设为DEBUG(FINE)
if (blog instanceof Jdk14Logger) {
Jdk14Logger logger = (Jdk14Logger) blog;
if (isEnabled) {
logger.getLogger().setLevel(Level.FINE);
Handler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.FINE);
logger.getLogger().addHandler(consoleHandler);
} else {
logger.getLogger().setLevel(Level.INFO);
}
}
}
示例15: setJDKDebugEnabled
import java.util.logging.Handler; //导入方法依赖的package包/类
public static void setJDKDebugEnabled(Boolean isEnabled) {
//如果使用JDK14LOGGER,将业务日志级别设为DEBUG(FINE)
if (blog instanceof Jdk14Logger) {
Jdk14Logger logger = (Jdk14Logger) blog;
if (isEnabled) {
logger.getLogger().setLevel(Level.FINE);
Handler consoleHandler = new ConsoleHandler();
consoleHandler.setLevel(Level.FINE);
logger.getLogger().addHandler(consoleHandler);
} else {
logger.getLogger().setLevel(Level.INFO);
}
}
}