本文整理汇总了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);
}
示例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> ");
sbuf.append(Transform.escapeTags(s[i]));
sbuf.append(Layout.LINE_SEP);
}
}
}
示例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();
}
示例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> ");
sbuf.append(Transform.escapeTags(s[i]));
sbuf.append(Layout.LINE_SEP);
}
}
}
示例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());
}
示例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());
}
示例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();
}
}
}
示例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;
}
示例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));
}
}
示例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;
}
}
示例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);
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
示例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;
}