當前位置: 首頁>>代碼示例>>Java>>正文


Java Layout類代碼示例

本文整理匯總了Java中org.apache.log4j.Layout的典型用法代碼示例。如果您正苦於以下問題:Java Layout類的具體用法?Java Layout怎麽用?Java Layout使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Layout類屬於org.apache.log4j包,在下文中一共展示了Layout類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLoggingMessages

import org.apache.log4j.Layout; //導入依賴的package包/類
public static Collection<String> getLoggingMessages(RingBufferAppender...appenders) {
    List<LoggingEvent> events = new ArrayList<LoggingEvent>();
    Layout layout = null; 
    for (RingBufferAppender rba : appenders) {
        LoggingEvent e[] = rba.getLogEvents();
        if (LOG.isDebugEnabled())
            LOG.debug("Got " + e.length + " LoggingEvents for " + rba);
        CollectionUtil.addAll(events, e);
        if (layout == null) layout = rba.getLayout();
    } // FOR
    if (events.isEmpty() == false) assert(layout != null);
    
    Collections.sort(events, new Comparator<LoggingEvent>() {
        @Override
        public int compare(LoggingEvent o1, LoggingEvent o2) {
            return (int)(o1.timeStamp - o2.timeStamp);
        }
    });
    List<String> messages = new ArrayList<String>();
    for (LoggingEvent event : events) {
        messages.add(layout.format(event));
    } // FOR
    return (messages);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:25,代碼來源:RingBufferAppender.java

示例2: appendThrowableAsHTML

import org.apache.log4j.Layout; //導入依賴的package包/類
void appendThrowableAsHTML(String s[], StringBuilder sbuf)
{
	if( s != null )
	{
		int len = s.length;
		if( len == 0 )
		{
			return;
		}

		sbuf.append(Transform.escapeTags(s[0]));
		sbuf.append(Layout.LINE_SEP);
		for( int i = 1; i < len; i++ )
		{
			sbuf.append("<br>&nbsp;&nbsp;&nbsp;&nbsp;");
			sbuf.append(Transform.escapeTags(s[i]));
			sbuf.append(Layout.LINE_SEP);
		}
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:21,代碼來源:HTMLLayout3.java

示例3: getHeader

import org.apache.log4j.Layout; //導入依賴的package包/類
@Override
public String getHeader()
{
	StringBuilder sbuf = new StringBuilder();
	sbuf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("<html><head><title>");
	sbuf.append(title);
	sbuf.append("</title><style type=\"text/css\"><!--");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("body, table {font-family: arial,sans-serif; font-size: x-small;}");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("th {background: #336699; color: #FFFFFF; text-align: left;}");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("--></style></head><body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\"><hr size=\"1\">");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">");
	sbuf.append(Layout.LINE_SEP);
	sbuf.append("<tr><th>Time</th><th>Context</th><th>Level</th><th>Category</th><th>Message</th></tr>");
	sbuf.append(Layout.LINE_SEP);
	return sbuf.toString();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:23,代碼來源:HTMLLayout3.java

示例4: appendThrowableAsHTML

import org.apache.log4j.Layout; //導入依賴的package包/類
void appendThrowableAsHTML(String s[], StringBuilder sbuf)
{
	if( s != null )
	{
		int len = s.length;
		if( len == 0 )
		{
			return;
		}

		sbuf.append(Transform.escapeTags(s[0]));
		sbuf.append(Layout.LINE_SEP);
		for( int i = 1; i < len; i++ )
		{
			sbuf.append("<br>&nbsp;&nbsp;&nbsp;&nbsp;");
			sbuf.append(Transform.escapeTags(s[i]));
			sbuf.append(Layout.LINE_SEP);
		}

	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:22,代碼來源:HTMLLayout2.java

示例5: append

import org.apache.log4j.Layout; //導入依賴的package包/類
@Override
protected void append(final LoggingEvent event) {
    final StringBuilder buffer = new StringBuilder();
    buffer.append(layout.format(event));
    if(layout.ignoresThrowable()) {
        final String[] trace = event.getThrowableStrRep();
        if(trace != null) {
            buffer.append(Layout.LINE_SEP);
            for(final String t : trace) {
                buffer.append(t).append(Layout.LINE_SEP);
            }
        }
    }
    console.printf("\r%s%s%s", Ansi.ansi()
                    .saveCursorPosition()
                    .eraseLine(Ansi.Erase.ALL)
                    .fg(Ansi.Color.MAGENTA)
                    .restoreCursorPosition(),
            buffer.toString(), Ansi.ansi().reset());
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:21,代碼來源:TerminalLoggingAppender.java

示例6: setupLogger

import org.apache.log4j.Layout; //導入依賴的package包/類
public static void setupLogger(Config config) throws IOException {

        Layout layout = new PatternLayout("%d{" + DATE_FORMAT + "} %5p: %m%n");

        Appender appender = new DailyRollingFileAppender(
                layout, config.getString("logger.file"), "'.'yyyyMMdd");

        LogManager.resetConfiguration();
        LogManager.getRootLogger().addAppender(new NullAppender());

        logger = Logger.getLogger(LOGGER_NAME);
        logger.addAppender(appender);
        logger.setLevel(Level.toLevel(config.getString("logger.level"), Level.ALL));

        // Workaround for "Bug 745866 - (EDG-45) Possible netty logging config problem"
        InternalLoggerFactory.setDefaultFactory(new InternalLoggerFactory() {
            @Override
            public InternalLogger newInstance(String string) {
                return new NettyInternalLogger();
            }
        });

        Log.logSystemInfo();
        Log.info("Version: " + getAppVersion());
    }
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:26,代碼來源:Log.java

示例7: LogUtil

import org.apache.log4j.Layout; //導入依賴的package包/類
public LogUtil(LogConfig config, Object obj){
	this.logConfig = config;
	if(LogConfig.logType == 0){
		report = new ExtentReports(config.getExtentLogPath(),false);
		File configFile = new File(System.getProperty("user.dir") + "\\configs\\extent-config.xml");
		if(configFile.exists()) {
			report.loadConfig(configFile);		
		}		
		testLog = report.startTest(String.valueOf(obj));
	}else{
		logger = Logger.getLogger(String.valueOf(obj));
		Layout layout = new PatternLayout("%d{yyyy-MM-dd HH:mm:ss} [%p] %c:%L �� %m%n");  
		try {
			Appender appender = new FileAppender(layout, config.getLog4jPath());
			logger.addAppender(appender);
		} catch (IOException e) {
			e.printStackTrace();
		} 
	}
}
 
開發者ID:AlanYangs,項目名稱:Log4Reports,代碼行數:21,代碼來源:LogUtil.java

示例8: getLogger

import org.apache.log4j.Layout; //導入依賴的package包/類
public static Logger getLogger(final Class<?> cl, final String initFile, final String property) {

		Properties properties;
		Logger c = null;
		try {
			ManagerIni mi = initFile != null ? ManagerIni.createManagerIniFile(initFile) : ManagerIni.createManagerIniParameter();
			properties = mi.getSession("FreedomLogger");
			c = Logger.getLogger(cl.getCanonicalName(), myFactory);
			Layout layout = new PatternLayout(LAYOUT_DEFAULT);
			c.addAppender(new FileAppender(layout, properties.get(property).toString(), true));
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		return c;
	}
 
開發者ID:cams7,項目名稱:erp,代碼行數:17,代碼來源:FreedomLogger.java

示例9: initializeLogger

import org.apache.log4j.Layout; //導入依賴的package包/類
private static void initializeLogger() throws IOException
{
	String logConfigFileName = ApplicationArguments.getInstance().getLoggingConfigFileName();
	if (logConfigFileName != null) {
		PropertyConfigurator.configure(logConfigFileName);
	} else {
		ApplicationFiles appFiles = new ApplicationFiles();
		
		String logMessagePattern = "%-4r [%t] %-5p %c %x - %m%n";
		Layout layout = new PatternLayout(logMessagePattern);
		
		File logsDir = new File(appFiles.getUserSettingsDirectory(), "logs");
		File updateLogFile = new File(logsDir, "updater.log");
		
		FileAppender appender = new FileAppender(layout, updateLogFile.getAbsolutePath());
		
		LoggerController.registerLoggerFactory(new SquirrelLoggerFactory(appender, false));
	}
}
 
開發者ID:realxujiang,項目名稱:bigtable-sql,代碼行數:20,代碼來源:PreLaunchUpdateApplication.java

示例10: NTEventLogAppender

import org.apache.log4j.Layout; //導入依賴的package包/類
public NTEventLogAppender(String server, String source, Layout layout) {
  if (source == null) {
    source = "Log4j";
  }
  if (layout == null) {
    this.layout = new TTCCLayout();
  } else {
    this.layout = layout;
  }

  try {
    _handle = registerEventSource(server, source);
  } catch (Exception e) {
    e.printStackTrace();
    _handle = 0;
  }
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:18,代碼來源:NTEventLogAppender.java

示例11: testExceptionWithCDATA

import org.apache.log4j.Layout; //導入依賴的package包/類
/**
   * Tests CDATA element within exception.  See bug 37560.
   */
 public void testExceptionWithCDATA() throws Exception {
     Logger logger = Logger.getLogger("com.example.bar");
     Level level = Level.INFO;
     String exceptionMessage ="<envelope><faultstring><![CDATA[The EffectiveDate]]></faultstring><envelope>";
     LoggingEvent event =
       new LoggingEvent(
         "com.example.bar", logger, level, "Hello, World", new Exception(exceptionMessage));
     Layout layout = createLayout();
     String result = layout.format(event);
     Element parsedResult = parse(result);
     NodeList throwables = parsedResult.getElementsByTagName("log4j:throwable");
     assertEquals(1, throwables.getLength());
     StringBuffer buf = new StringBuffer();
     for(Node child = throwables.item(0).getFirstChild();
             child != null;
             child = child.getNextSibling()) {
         buf.append(child.getNodeValue());
     }
     assertTrue(buf.toString().indexOf(exceptionMessage) != -1);
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:24,代碼來源:XMLLayoutTest.java

示例12: append

import org.apache.log4j.Layout; //導入依賴的package包/類
@Override
protected void append(LoggingEvent event) {
    if(this.layout == null) {
        logger.log(event.getLevel() + " " + event.getMessage());
        return;
    }
    logger.log(this.layout.format(event));
    //prints the Throwable from the log
    if(layout.ignoresThrowable()) {
        StringBuilder traceString = new StringBuilder();
        String[] s = event.getThrowableStrRep();
        if (s != null) {
            int len = s.length;
            for(int i = 0; i < len; i++) {
                traceString.append(s[i]);
                traceString.append(Layout.LINE_SEP);
            }
        }
        logger.log(traceString.toString());
    }
}
 
開發者ID:aws,項目名稱:aws-lambda-java-libs,代碼行數:22,代碼來源:LambdaAppender.java

示例13: testMissingSprite

import org.apache.log4j.Layout; //導入依賴的package包/類
/**
 * Tests that the right logger message is executed if the sprite file is
 * invalid.
 */
@Test
public void testMissingSprite() {
	// Set up of logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Valid file name
	String inValidSpriteFile = "Sprite asdfsdfSheet";
	SpriteLoader spriteLoader = new SpriteLoader();

	try {
		// The functions to test
		spriteLoader.loadSpriteSheet(inValidSpriteFile, 32, 32);
		spriteLoader.getSprite(1, 0);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - You are trying to use a"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:29,代碼來源:SpriteLoaderTests.java

示例14: testNegativeDimensions

import org.apache.log4j.Layout; //導入依賴的package包/類
/**
 * Tests that the right logger message is executed if an incorrect position
 * (on the sprite sheet) is entered.
 */
@Test
public void testNegativeDimensions() {

	// Set up logger retrieval
	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	Layout layout = new SimpleLayout();
	Appender appender = new WriterAppender(layout, outputStream);
	LOGGER.addAppender(appender);

	// Valid file name
	String validSpriteFile = "peonSheet";
	SpriteLoader spriteLoader = new SpriteLoader();
	try {
		// The functions to test
		spriteLoader.loadSpriteSheet(validSpriteFile, 32, 32);
		spriteLoader.getSprite(-1, -1);

		String logMessage = outputStream.toString();
		assertNotNull(logMessage);
		assertTrue(logMessage.contains("ERROR - You are requesting a grid position"));
	} finally {
		LOGGER.removeAppender(appender);
	}
}
 
開發者ID:UQdeco2800,項目名稱:minesim,代碼行數:29,代碼來源:SpriteLoaderTests.java

示例15: invoke

import org.apache.log4j.Layout; //導入依賴的package包/類
public
Object invoke(String operationName, Object params[], String signature[])
  throws MBeanException,
  ReflectionException {

  if(operationName.equals("activateOptions") &&
                   appender instanceof OptionHandler) {
    OptionHandler oh = (OptionHandler) appender;
    oh.activateOptions();
    return "Options activated.";
  } else if (operationName.equals("setLayout")) {
    Layout layout = (Layout) OptionConverter.instantiateByClassName((String)
						      params[0],
						      Layout.class,
						      null);
    appender.setLayout(layout);
    registerLayoutMBean(layout);
  }
  return null;
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:21,代碼來源:AppenderDynamicMBean.java


注:本文中的org.apache.log4j.Layout類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。