本文整理汇总了Java中java.util.logging.Handler类的典型用法代码示例。如果您正苦于以下问题:Java Handler类的具体用法?Java Handler怎么用?Java Handler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Handler类属于java.util.logging包,在下文中一共展示了Handler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUnknownLevels
import java.util.logging.Handler; //导入依赖的package包/类
public void testUnknownLevels() throws IOException {
TestLevel level = new TestLevel("WARN", 233);
LogRecord r = new LogRecord(level, "Custom level test");
Formatter formatter = new LogFormatter();
String s = formatter.format(r);
cleanKnownLevels();
final LogRecord[] rPtr = new LogRecord[] { null };
Handler h = new Handler() {
@Override
public void publish(LogRecord record) {
rPtr[0] = record;
}
@Override
public void flush() {}
@Override
public void close() throws SecurityException {}
};
LogRecords.scan(new ReaderInputStream(new StringReader(s)), h);
assertEquals("level", r.getLevel(), rPtr[0].getLevel());
}
示例2: activate
import java.util.logging.Handler; //导入依赖的package包/类
/**
* Activates this feature.
*/
public static void activate()
{
try
{
Logger rootLogger = LogManager.getLogManager().getLogger("");
// remove old ConsoleHandler
for( Handler handler : rootLogger.getHandlers() )
{
rootLogger.removeHandler(handler);
}
activeHandler = new JDKLogHandler();
activeHandler.setLevel(Level.ALL);
rootLogger.addHandler(activeHandler);
rootLogger.setLevel(Level.ALL);
}
catch( Exception exc )
{
LogFactory.getLog(TomcatLogRedirector.class).error("activation failed", exc);
}
}
示例3: LogHelper
import java.util.logging.Handler; //导入依赖的package包/类
private LogHelper() {
try {
logger = Logger.getLogger(LogHelper.class.getName());
if ( DEBUG )
logger.setLevel(Level.ALL);
else
logger.setLevel(Level.WARNING);
Handler handler = new FileHandler("%t/suji.log", 0, 1, false);
logger.addHandler(handler);
}
catch (IOException e) {
e.printStackTrace();
}
}
示例4: getLogger
import java.util.logging.Handler; //导入依赖的package包/类
/**
* Creates a static {@code Logger} instance.
*
* @return a static {@code Logger} with properties:
* <ul>
* <li>Name: {@code "DefaultDatabaseConfigurator"}.</li>
* <li>Output file pattern:
* {@code user.home/.kawansoft/log/AceQL.log}.</li>
* <li>Formatter: {@code SimpleFormatter}.</li>
* <li>Limit: 200Mb.</li>
* <li>Count (number of files to use): 2.</li>
* </ul>
*/
@Override
public Logger getLogger() throws IOException {
if (ACEQL_LOGGER != null) {
return ACEQL_LOGGER;
}
File logDir = new File(SystemUtils.USER_HOME + File.separator + ".kawansoft" + File.separator + "log");
logDir.mkdirs();
String pattern = logDir.toString() + File.separator + "AceQL.log";
ACEQL_LOGGER = Logger.getLogger(DefaultDatabaseConfigurator.class.getName());
Handler fh = new FileHandler(pattern, 200 * 1024 * 1024, 2, true);
fh.setFormatter(new SimpleFormatter());
ACEQL_LOGGER.addHandler(fh);
return ACEQL_LOGGER;
}
示例5: 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);
}
}
}
示例6: setLogging
import java.util.logging.Handler; //导入依赖的package包/类
static private void setLogging(int logging) {
Level logLevel = getLogLevel(logging%10);
Logger.getLogger("org.jboss.wfink.eap71.playground").setLevel(logLevel);
logLevel = getLogLevel((logging/10)%10);
Logger.getLogger("org.xnio").setLevel(logLevel);
Logger.getLogger("org.jboss.remoting").setLevel(logLevel); //classes are remoting3
logLevel = getLogLevel((logging/100)%10);
Logger.getLogger("org.jboss.ejb.client").setLevel(logLevel);
logLevel = getLogLevel((logging/1000)%10);
Logger.getLogger("org.wildfly").setLevel(logLevel);
// Logger.getLogger("org.jboss.invocation").setLevel(logLevel);
// change default ConsoleHandler
Logger root = Logger.getLogger("");
Handler[] handlers = root.getHandlers();
for (int i = 0; i < handlers.length; i++) {
root.removeHandler(handlers[i]);
}
ConsoleHandler handler = new ConsoleHandler();
handler.setFormatter(new PlaygroundFormatter());
handler.setLevel(Level.ALL);
root.addHandler(handler);
}
示例7: setUpBeforeClass
import java.util.logging.Handler; //导入依赖的package包/类
@BeforeClass
public static void setUpBeforeClass() throws Exception {
saveLog4j2Config = System.getProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
saveUserDir = System.getProperty("user.dir");
saveUserHome = System.getProperty("user.home");
julLogger = java.util.logging.Logger.getLogger("");
saveHandlers = julLogger.getHandlers();
for (Handler handler : saveHandlers) {
julLogger.removeHandler(handler);
}
File log4j2XML = temporaryFolder_Config.newFile("log4j2.xml");
FileUtils.writeStringToFile(log4j2XML, "<Configuration/>", APPEND);
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY,
log4j2XML.toURI().toString());
}
示例8: 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);
}
示例9: tearDownAfterClass
import java.util.logging.Handler; //导入依赖的package包/类
@AfterClass
public static void tearDownAfterClass() throws Exception {
for (Handler handler : saveHandlers) {
julLogger.addHandler(handler);
}
if (saveLog4j2Config == null) {
System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
} else {
System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, saveLog4j2Config);
((LoggerContext) LogManager.getContext(false)).reconfigure();
}
if (saveUserDir == null) {
System.clearProperty("user.dir");
} else {
System.setProperty("user.dir", saveUserDir);
}
if (saveUserHome == null) {
System.clearProperty("user.home");
} else {
System.setProperty("user.home", saveUserHome);
}
}
示例10: defaultHandler
import java.util.logging.Handler; //导入依赖的package包/类
private static synchronized Handler defaultHandler() {
if (defaultHandler != null) return defaultHandler;
File home = Places.getUserDirectory();
if (home != null && !CLIOptions.noLogging) {
File dir = new File(new File(home, "var"), "log");
dir.mkdirs ();
Handler h = NbLogging.createMessagesHandler(dir);
defaultHandler = NbLogging.createDispatchHandler(h, 5000);
}
if (defaultHandler == null) {
defaultHandler = streamHandler();
disabledConsole = true;
}
return defaultHandler;
}
示例11: flush
import java.util.logging.Handler; //导入依赖的package包/类
/** Allows tests to flush all standard handlers */
static void flush(boolean clear) {
System.err.flush();
Handler s = streamHandler;
if (s != null) {
s.flush();
}
Handler d = defaultHandler;
if (d != null) {
d.flush();
}
if (clear) {
streamHandler = null;
defaultHandler = null;
}
}
示例12: readLog
import java.util.logging.Handler; //导入依赖的package包/类
private String readLog() throws IOException {
Handler[] ha = Logger.getLogger("").getHandlers();
assertEquals("There is one handler", 1, ha.length);
ha[0].flush();
assertTrue("Log file exists: " + log, log.canRead());
FileInputStream is = new FileInputStream(log);
byte[] arr = new byte[(int)log.length()];
int r = is.read(arr);
assertEquals("all read", arr.length, r);
is.close();
return new String(arr);
}
示例13: createHandler
import java.util.logging.Handler; //导入依赖的package包/类
/**
* Create a logging handler that sets value in an AtomicBoolean to true if
* folder2 or text2.txt is refreshed.
*
* @param refreshedFlag The AtomicBoolean to be set to true if incorrect
* refreshing was triggered.
* @return The new logging handler.
*/
private Handler createHandler(final AtomicBoolean refreshedFlag) {
Handler h = new Handler() {
@Override
public void publish(LogRecord record) {
if (record.getMessage() != null
&& record.getMessage().startsWith("refreshImpl for ")
&& record.getParameters() != null
&& record.getParameters().length > 0
&& (record.getParameters()[0] == folder2FO
|| record.getParameters()[0] == folder2text2TxtFO)) {
refreshedFlag.set(true);
}
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
};
return h;
}
示例14: readLogs
import java.util.logging.Handler; //导入依赖的package包/类
static void readLogs(Handler handler){
UIHandler.waitFlushed();
synchronized (UIGESTURE_LOG_LOCK) {
File f = logFile(0);
if (f == null || !f.exists()) {
return ;
}
closeLogStream();
File f1 = logFile(1);
if (logsSize < UIHandler.MAX_LOGS && f1 != null && f1.exists()) {
scan(f1, handler);
}
scan(f, handler);
}
}
示例15: scan
import java.util.logging.Handler; //导入依赖的package包/类
private static void scan(File f, Handler handler){
try {
LogRecords.scan(f, handler);
} catch (IOException ex) {
LOG.log(Level.INFO, "Broken uilogs file, not all UI actions will be submitted", ex);
if (!fileContentReported) {
try {
if (LOG.isLoggable(Level.INFO)) {
LOG.log(Level.INFO, "Problematic file content = {0}", reportFileContent(f));
}
} finally {
fileContentReported = true;
}
}
}
}