当前位置: 首页>>代码示例>>Java>>正文


Java MemoryHandler类代码示例

本文整理汇总了Java中java.util.logging.MemoryHandler的典型用法代码示例。如果您正苦于以下问题:Java MemoryHandler类的具体用法?Java MemoryHandler怎么用?Java MemoryHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MemoryHandler类属于java.util.logging包,在下文中一共展示了MemoryHandler类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMemoryHandlerDefaultValue

import java.util.logging.MemoryHandler; //导入依赖的package包/类
public void testMemoryHandlerDefaultValue() throws SecurityException,
		IOException {
	props.clear();
	props.put("java.util.logging.MemoryHandler.target", baseClassName
			+ "$MockHandler");

	manager.readConfiguration(EnvironmentHelper
			.PropertiesToInputStream(props));
	handler = new MemoryHandler();
	assertNull(handler.getFilter());
	assertTrue(handler.getFormatter() instanceof SimpleFormatter);
	assertNull(handler.getEncoding());
	assertNotNull(handler.getErrorManager());
	assertEquals(handler.getLevel(), Level.ALL);
	assertEquals(handler.getPushLevel(), Level.SEVERE);
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:17,代码来源:MemoryHandlerTest.java

示例2: dumpMemoryTrace47

import java.util.logging.MemoryHandler; //导入依赖的package包/类
protected static void dumpMemoryTrace47(java.util.logging.Logger logger) {
    MemoryHandler mHand = null;

    if (logger != null) {
        Handler[] handlers = logger.getHandlers();

        for (int i = 0; i < handlers.length; i++) {
            if (handlers[i] instanceof java.util.logging.MemoryHandler) {
                synchronized (handlers[i]) {
                    mHand = ((java.util.logging.MemoryHandler) handlers[i]);
                    mHand.push();
                    return;
                } // synchronized (handler).
            }
        } // for handlers...
        dumpMemoryTrace47(logger.getParent());
    }
}
 
开发者ID:longkerdandy,项目名称:chii2mqtt,代码行数:19,代码来源:JSR47Logger.java

示例3: dumpMemoryTrace47

import java.util.logging.MemoryHandler; //导入依赖的package包/类
protected static void dumpMemoryTrace47(java.util.logging.Logger logger) {
	MemoryHandler mHand = null;

	if (logger!= null) {
		Handler[] handlers = logger.getHandlers();
		
	    for (int i=0; i<handlers.length; i++) {
	      if (handlers[i] instanceof java.util.logging.MemoryHandler) {
	        synchronized (handlers[i]) {
	        	mHand = ((java.util.logging.MemoryHandler)handlers[i]);
	        	mHand.push();
	        	return;
	        } // synchronized (handler).
	      }      
	    } // for handlers...
	    dumpMemoryTrace47(logger.getParent());
	}
}
 
开发者ID:gulliverrr,项目名称:hestia-engine-dev,代码行数:19,代码来源:JSR47Logger.java

示例4: enableFileOut

import java.util.logging.MemoryHandler; //导入依赖的package包/类
@Override
public void enableFileOut(String filepattern, boolean check, int bufferSize, int fileSize, int fileCount,
        boolean isAppend, Formatter format) {

    if (check == true) {

        if (this.fileHandler == null) {
            initFileHandler(filepattern, fileSize, fileCount, isAppend);
        }

        if (this.fileHandler != null) {
            this.fileHandler.setLevel(this.level);
            this.fileHandler.setFormatter(format);
        }

        /**
         * NOTE: we use async log buffer
         */
        if (this.memHandler == null) {
            this.memHandler = new MemoryHandler(this.fileHandler, bufferSize, this.level);
            this.log.addHandler(this.memHandler);
        }
    }
    else {
        if (this.memHandler != null) {
            log.removeHandler(this.memHandler);
        }
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:30,代码来源:PLogger.java

示例5: run

import java.util.logging.MemoryHandler; //导入依赖的package包/类
@Override
public void run() {
    // MemoryHandler

    check(new MemoryHandler(),
        Level.ALL, null, null, SimpleFormatter.class,
        ConfiguredHandler.class, 1000, Level.SEVERE);

    check(new MemoryHandler(new SpecifiedHandler(), 100, Level.WARNING),
        Level.ALL, null, null, SimpleFormatter.class,
        SpecifiedHandler.class, 100, Level.WARNING);

    // StreamHandler

    check(new StreamHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        null);

    check(new StreamHandler(System.out, new SpecifiedFormatter()),
        Level.INFO, null, null, SpecifiedFormatter.class,
        System.out);

    // ConsoleHandler

    check(new ConsoleHandler(),
        Level.INFO, null, null, SimpleFormatter.class,
        System.err);

    // SocketHandler (use the ServerSocket's port)

    try {
        check(new SocketHandler("localhost", serverSocket.getLocalPort()),
            Level.ALL, null, null, XMLFormatter.class);
    } catch (IOException e) {
        throw new RuntimeException("Can't connect to localhost:" + serverSocket.getLocalPort(), e);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:HandlersConfigTest.java

示例6: check

import java.util.logging.MemoryHandler; //导入依赖的package包/类
void check(MemoryHandler handler,
           Level expectedLevel,
           String expectedEncoding,
           Class<? extends Filter> expectedFilterType,
           Class<? extends Formatter> expectedFormatterType,
           Class<? extends Handler> expextedTargetType,
           int expextedSize,
           Level expectedPushLevel) {
    checkType(handler, "target", getTarget(handler), expextedTargetType);
    checkEquals(handler, "size", getSize(handler), expextedSize);
    checkEquals(handler, "pushLevel", handler.getPushLevel(), expectedPushLevel);
    check(handler, expectedLevel, expectedEncoding, expectedFilterType, expectedFormatterType);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:HandlersConfigTest.java

示例7: getTarget

import java.util.logging.MemoryHandler; //导入依赖的package包/类
Handler getTarget(MemoryHandler memoryHandler) {
    try {
        return (Handler) memoryHandlerTarget.get(memoryHandler);
    } catch (IllegalAccessException e) {
        throw new IllegalAccessError(e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:HandlersConfigTest.java

示例8: getSize

import java.util.logging.MemoryHandler; //导入依赖的package包/类
int getSize(MemoryHandler memoryHandler) {
    try {
        return (int) memoryHandlerSize.get(memoryHandler);
    } catch (IllegalAccessException e) {
        throw new IllegalAccessError(e.getMessage());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:HandlersConfigTest.java

示例9: setUp

import java.util.logging.MemoryHandler; //导入依赖的package包/类
protected void setUp() throws Exception {
	super.setUp();
	manager.reset();
	initProps();
	manager.readConfiguration(EnvironmentHelper
			.PropertiesToInputStream(props));
	handler = new MemoryHandler();
       errSubstituteStream = new NullOutputStream();
       System.setErr(new PrintStream(errSubstituteStream));
}
 
开发者ID:Sellegit,项目名称:j2objc,代码行数:11,代码来源:MemoryHandlerTest.java

示例10: setUp

import java.util.logging.MemoryHandler; //导入依赖的package包/类
@Override protected void setUp() throws Exception {
    super.setUp();
    manager.reset();
    initProps();
    manager.readConfiguration(propertiesToInputStream(props));
    handler = new MemoryHandler();
}
 
开发者ID:keplersj,项目名称:In-the-Box-Fork,代码行数:8,代码来源:OldMemoryHandlerTest.java

示例11: setUp

import java.util.logging.MemoryHandler; //导入依赖的package包/类
protected void setUp() throws Exception {
	super.setUp();
	manager.reset();
	initProps();
	manager.readConfiguration(EnvironmentHelper
			.PropertiesToInputStream(props));
	handler = new MemoryHandler();
       errSubstituteStream = new NullOutputStream();
       System.setErr(new PrintStream(errSubstituteStream));        
}
 
开发者ID:shannah,项目名称:cn1,代码行数:11,代码来源:MemoryHandlerTest.java

示例12: up

import java.util.logging.MemoryHandler; //导入依赖的package包/类
@Setup(Level.Trial)
public void up() {
    memoryHandler = new MemoryHandler(new NoOpJULHandler(), 262144, java.util.logging.Level.SEVERE);
    logger = Logger.getLogger(getClass().getName());
    logger.setUseParentHandlers(false);
    logger.addHandler(memoryHandler);
    logger.setLevel(java.util.logging.Level.ALL);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:9,代码来源:MemoryHandlerJULLocationBenchmark.java

示例13: up

import java.util.logging.MemoryHandler; //导入依赖的package包/类
@Setup(Level.Trial)
public void up() {
    memoryHandler = new MemoryHandler(new NoOpJULHandler(), 262144, java.util.logging.Level.SEVERE);
    logger = java.util.logging.Logger.getLogger(getClass().getName());
    logger.setUseParentHandlers(false);
    logger.addHandler(memoryHandler);
    logger.setLevel(java.util.logging.Level.ALL);
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:9,代码来源:MemoryHandlerJULBenchmark.java

示例14: main

import java.util.logging.MemoryHandler; //导入依赖的package包/类
public static void main(String... args) throws IOException {
    // load logging.propertes for the test
    String tstSrc = System.getProperty("test.src", ".");
    File fname = new File(tstSrc, LM_PROP_FNAME);
    String prop = fname.getCanonicalPath();
    System.setProperty(CFG_FILE_PROP, prop);
    LogManager.getLogManager();
    // create a logger
    logger = Logger.getLogger(MemoryHandlerTest.class.getName());
    // don't have parent handlers get log messages
    logger.setUseParentHandlers(false);
    //
    // Test 1,2: create a CustomMemoryHandler which in the config has
    // specified a target of CustomTargetHandler.  (1) Make sure that it
    // is created and (2) that the target handler is loaded.
    //
    CustomMemoryHandler cmh = new CustomMemoryHandler();
    try {
        logger.addHandler(cmh);
    } catch (RuntimeException rte) {
        throw new RuntimeException(
            "Test Failed: did not load java.util.logging.ConsoleHandler as expected",
            rte);
    }
    // if we get here and our config has been processed properly, then we
    // should have loaded our target handler
    if (CustomTargetHandler.numLoaded !=1) {
        throw new RuntimeException(
            "Test failed: did not load CustomTargetHandler as expected");
    }
    //
    // Test 3: try to add a handler with no target.  This should fail with
    // an exception
    CustomMemoryHandlerNoTarget cmhnt = null;
    try {
        cmhnt = new CustomMemoryHandlerNoTarget();
    } catch (RuntimeException re) {
        // expected -- no target specified
        System.out.println("Info: " + re.getMessage() + " as expected.");
    }
    if (cmhnt != null) {
        throw new RuntimeException(
            "Test Failed: erroneously loaded CustomMemoryHandlerNoTarget");
    }

    // Test 4: log a message and check that the target handler is actually used
    logger.log(Level.WARNING, "Unused");
    if (CustomTargetHandler.numPublished != 1) {
        throw new RuntimeException("Test failed: CustomTargetHandler was not used");
    }

    // Test 5: make sure that SimpleTargetHandler hasn't been erroneously called
    if (SimpleTargetHandler.numPublished != 0) {
        throw new RuntimeException("Test failed: SimpleTargetHandler has been used");
    }

    // Test 6: try using SimpleTargetHanlder via standard MemoryHandler
    // (which has target set to SimpleTargetHandler)
    MemoryHandler mh = new MemoryHandler();
    mh.publish(new LogRecord(Level.INFO, "Unused msg to MemoryHandler"));
    // see if it made it to the SimpleTargetHandler
    if (SimpleTargetHandler.numPublished != 1) {
        throw new RuntimeException("Test failed: SimpleTargetHandler was not used");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:66,代码来源:MemoryHandlerTest.java


注:本文中的java.util.logging.MemoryHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。