org.apache.log4j.Layout Java Examples

The following examples show how to use org.apache.log4j.Layout. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LogUtilities.java    From render with GNU General Public License v2.0 6 votes vote down vote up
public static void setupExecutorLog4j(final String context,
                                      final String rootLoggerName) {

    final Logger logger = LogManager.getLogger(rootLoggerName);

    for (final Enumeration e = LogManager.getRootLogger().getAllAppenders(); e.hasMoreElements(); ) {
        final Appender a = (Appender) e.nextElement();
        if (a instanceof ConsoleAppender) {
            final Layout layout = a.getLayout();
            if (layout instanceof PatternLayout) {
                final PatternLayout patternLayout = (PatternLayout) layout;
                final String conversionPattern = "%d{ISO8601} [%t] [%X{context}] %-5p [%c] %m%n";
                if (! conversionPattern.equals(patternLayout.getConversionPattern())) {
                    a.setLayout(new PatternLayout(conversionPattern));
                }
            }
        }
    }

    MDC.put("context", context);

    logger.setLevel(Level.DEBUG);
}
 
Example #2
Source File: PatternLayoutBuilder.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Override
public Layout parseLayout(final Element layoutElement, final XmlConfiguration config) {
    NodeList params = layoutElement.getElementsByTagName("param");
    final int length = params.getLength();
    String pattern = null;
    for (int index = 0; index < length; ++ index) {
        Node currentNode = params.item(index);
        if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
            Element currentElement = (Element) currentNode;
            if (currentElement.getTagName().equals(PARAM_TAG)) {
                if (PATTERN.equalsIgnoreCase(currentElement.getAttribute("name"))) {
                    pattern = currentElement.getAttribute("value");
                    break;
                }
            }
        }
    }
    return createLayout(pattern, config);
}
 
Example #3
Source File: SystemTestAppender.java    From JVoiceXML with GNU Lesser General Public License v2.1 6 votes vote down vote up
public String getContents(final Layout layout) {
        final StringBuilder content = new StringBuilder();
        synchronized (events) {
            for (LoggingEvent event : events) {
                final String message = layout.format(event);
                content.append(message);
//                final String[] throwable = event.getThrowableStrRep();
//                final String lf = System.getProperty("line.separator");
//                if (throwable != null) {
//                    for (String str : throwable) {
//                        content.append(str);
//                        content.append(lf);
//                    }
//                }
            }
        }
        return content.toString();
    }
 
Example #4
Source File: ConsoleAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
private <T extends Log4j1Configuration> Appender createAppender(String name, Layout layout, Filter filter,
        String level, String target, T configuration) {
    org.apache.logging.log4j.core.Layout<?> consoleLayout = null;

    if (layout instanceof LayoutWrapper) {
        consoleLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        consoleLayout = new LayoutAdapter(layout);
    }
    org.apache.logging.log4j.core.Filter consoleFilter = buildFilters(level, filter);
    ConsoleAppender.Target consoleTarget = SYSTEM_ERR.equals(target)
            ? ConsoleAppender.Target.SYSTEM_ERR : ConsoleAppender.Target.SYSTEM_OUT;
    return new AppenderWrapper(ConsoleAppender.newBuilder()
            .setName(name)
            .setTarget(consoleTarget)
            .setLayout(consoleLayout)
            .setFilter(consoleFilter)
            .setConfiguration(configuration)
            .build());
}
 
Example #5
Source File: HtmlLayoutBuilder.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Override
public Layout parseLayout(Element layoutElement, XmlConfigurationFactory factory) {
    final Holder<String> title = new Holder<>();
    final Holder<Boolean> locationInfo = new BooleanHolder();
    forEachElement(layoutElement.getElementsByTagName("param"), (currentElement) -> {
        if (currentElement.getTagName().equals("param")) {
            if ("title".equalsIgnoreCase(currentElement.getAttribute("name"))) {
                title.set(currentElement.getAttribute("value"));
            } else if ("locationInfo".equalsIgnoreCase(currentElement.getAttribute("name"))) {
                locationInfo.set(Boolean.parseBoolean(currentElement.getAttribute("value")));
            }
        }
    });
    return new LayoutWrapper(HtmlLayout.newBuilder()
            .withTitle(title.get())
            .withLocationInfo(locationInfo.get())
            .build());
}
 
Example #6
Source File: TerminalLoggingAppender.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #7
Source File: XmlLayoutBuilder.java    From logging-log4j2 with Apache License 2.0 6 votes vote down vote up
@Override
public Layout parseLayout(Element layoutElement, XmlConfigurationFactory factory) {
    final Holder<Boolean> properties = new BooleanHolder();
    final Holder<Boolean> locationInfo = new BooleanHolder();
    forEachElement(layoutElement.getElementsByTagName("param"), (currentElement) -> {
        if ("properties".equalsIgnoreCase(currentElement.getAttribute("name"))) {
            properties.set(Boolean.parseBoolean(currentElement.getAttribute("value")));
        } else if ("locationInfo".equalsIgnoreCase(currentElement.getAttribute("name"))) {
            locationInfo.set(Boolean.parseBoolean(currentElement.getAttribute("value")));
        }
    });
    return new LayoutWrapper(XmlLayout.newBuilder()
            .setLocationInfo(locationInfo.get())
            .setProperties(properties.get())
            .build());
}
 
Example #8
Source File: ThreadGroupRenderer.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public
String  doRender(Object obj) {
    if(obj instanceof ThreadGroup) {
        StringBuilder sb = new StringBuilder();
        ThreadGroup threadGroup = (ThreadGroup) obj;
        sb.append("java.lang.ThreadGroup[name=");
        sb.append(threadGroup.getName());
        sb.append(", maxpri=");
        sb.append(threadGroup.getMaxPriority());
        sb.append("]");
        Thread[] threads = new Thread[threadGroup.activeCount()];
        threadGroup.enumerate(threads);
        for (Thread thread : threads) {
            sb.append(Layout.LINE_SEP);
            sb.append("   Thread=[");
            sb.append(thread.getName());
            sb.append(",");
            sb.append(thread.getPriority());
            sb.append(",");
            sb.append(thread.isDaemon());
            sb.append("]");
        }
        return sb.toString();
    } else {
        try {
            // this is the best we can do
            return obj.toString();
        } catch(Exception ex) {
            return ex.toString();
        }
    }
}
 
Example #9
Source File: Log4jAppenderTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void append(final LoggingEvent event) {
    counter++;
    final Layout layout = getLayout();
    if (layout != null) {
        messages.add(layout.format(event));
    } else {
        messages.add(event.getLogRecord().getFormattedMessage());
    }
}
 
Example #10
Source File: XmlLayoutBuilder.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Layout parseLayout(Element layoutElement, XmlConfiguration config) {
    final Holder<Boolean> properties = new BooleanHolder();
    final Holder<Boolean> locationInfo = new BooleanHolder();
    forEachElement(layoutElement.getElementsByTagName(PARAM_TAG), (currentElement) -> {
        if (PROPERTIES.equalsIgnoreCase(currentElement.getAttribute("name"))) {
            properties.set(Boolean.parseBoolean(currentElement.getAttribute("value")));
        } else if (LOCATION_INFO.equalsIgnoreCase(currentElement.getAttribute("name"))) {
            locationInfo.set(Boolean.parseBoolean(currentElement.getAttribute("value")));
        }
    });
    return createLayout(properties.get(), locationInfo.get());
}
 
Example #11
Source File: DOMConfigurator.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
    Used internally to parse a layout element.
 */  
 protected
 Layout parseLayout (Element layout_element) {
   String className = subst(layout_element.getAttribute(CLASS_ATTR));
   LogLog.debug("Parsing layout of class: \""+className+"\"");		 
   try {
     Object instance 	= Loader.loadClass(className).newInstance();
     Layout layout   	= (Layout)instance;
     PropertySetter propSetter = new PropertySetter(layout);
     
     NodeList params 	= layout_element.getChildNodes();
     final int length 	= params.getLength();

     for (int loop = 0; loop < length; loop++) {
Node currentNode = (Node)params.item(loop);
if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
  Element currentElement = (Element) currentNode;
  String tagName = currentElement.getTagName();
  if(tagName.equals(PARAM_TAG)) {
           setParameter(currentElement, propSetter);
  } else {
         parseUnrecognizedElement(instance, currentElement, props);
     }
}
     }
     
     propSetter.activate();
     return layout;
   }
   catch (Exception oops) {
     LogLog.error("Could not create the Layout. Reported error follows.",
	   oops);
     return null;
   }
 }
 
Example #12
Source File: TelnetAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/** Handles a log event.  For this appender, that means writing the
   message to each connected client.  */
 protected void append(LoggingEvent event) {
   sh.send(this.layout.format(event));
   if(layout.ignoresThrowable()) {
     String[] s = event.getThrowableStrRep();
     if (s != null) {
int len = s.length;
for(int i = 0; i < len; i++) {
  sh.send(s[i]);
  sh.send(Layout.LINE_SEP);
}
     }
   }
 }
 
Example #13
Source File: GenericTestUtils.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
private LogCapturer(Logger logger) {
  this.logger = logger;
  Appender defaultAppender = Logger.getRootLogger().getAppender("stdout");
  if (defaultAppender == null) {
    defaultAppender = Logger.getRootLogger().getAppender("console");
  }
  final Layout layout = (defaultAppender == null) ? new PatternLayout() :
      defaultAppender.getLayout();
  this.appender = new WriterAppender(layout, sw);
  logger.addAppender(this.appender);
}
 
Example #14
Source File: TestRegionServerReportForDuty.java    From hbase with Apache License 2.0 5 votes vote down vote up
LogCapturer(org.apache.log4j.Logger logger) {
  this.logger = logger;
  Appender defaultAppender = org.apache.log4j.Logger.getRootLogger().getAppender("stdout");
  if (defaultAppender == null) {
    defaultAppender = org.apache.log4j.Logger.getRootLogger().getAppender("console");
  }
  final Layout layout = (defaultAppender == null) ? new PatternLayout() :
      defaultAppender.getLayout();
  this.appender = new WriterAppender(layout, sw);
  this.logger.addAppender(this.appender);
}
 
Example #15
Source File: Log4jHookProxy.java    From uavstack with Apache License 2.0 5 votes vote down vote up
private LogProfileInfo getAppenderInfo(FileAppender fileAppender, String appid) {

        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put(LogProfileInfo.ENGINE, "log4j");
        
        Layout layout = fileAppender.getLayout();
        if (null != layout) {
            if (layout instanceof PatternLayout) {
                PatternLayout patternLayout = (PatternLayout) fileAppender.getLayout();
                attributes.put(LogProfileInfo.PATTERN, patternLayout.getConversionPattern());
            }
            else {
                attributes.put(LogProfileInfo.PATTERN, layout.getClass().getSimpleName());
            }
        }

        boolean useBuffIO = fileAppender.getBufferedIO();
        if (useBuffIO == true) {
            attributes.put(LogProfileInfo.BUFFER_SIZE, String.valueOf(fileAppender.getBufferSize()));
            attributes.put(LogProfileInfo.BUFFRT_IO, String.valueOf(useBuffIO));
        }
        
        LogProfileInfo logProfileInfo = new LogProfileInfo();
        logProfileInfo.setAppId(appid);
        logProfileInfo.setFilePath(fileAppender.getFile());
        logProfileInfo.setAttributes(attributes);
        logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);

        return logProfileInfo;

    }
 
Example #16
Source File: ThreadGroupRenderer.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
public
String  doRender(Object obj) {
    if(obj instanceof ThreadGroup) {
        StringBuilder sb = new StringBuilder();
        ThreadGroup threadGroup = (ThreadGroup) obj;
        sb.append("java.lang.ThreadGroup[name=");
        sb.append(threadGroup.getName());
        sb.append(", maxpri=");
        sb.append(threadGroup.getMaxPriority());
        sb.append("]");
        Thread[] threads = new Thread[threadGroup.activeCount()];
        threadGroup.enumerate(threads);
        for (Thread thread : threads) {
            sb.append(Layout.LINE_SEP);
            sb.append("   Thread=[");
            sb.append(thread.getName());
            sb.append(",");
            sb.append(thread.getPriority());
            sb.append(",");
            sb.append(thread.isDaemon());
            sb.append("]");
        }
        return sb.toString();
    } else {
        try {
            // this is the best we can do
            return obj.toString();
        } catch(Exception ex) {
            return ex.toString();
        }
    }
}
 
Example #17
Source File: TTCCLayoutBuilder.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private Layout createLayout(boolean threadPrinting, boolean categoryPrefixing, boolean contextPrinting,
        String dateFormat, String timezone, Log4j1Configuration config) {
    StringBuilder sb = new StringBuilder();
    if (dateFormat != null) {
        if (RELATIVE.equalsIgnoreCase(dateFormat)) {
            sb.append("%r ");
        } else {
            sb.append("%d{").append(dateFormat).append("}");
            if (timezone != null) {
                sb.append("{").append(timezone).append("}");
            }
            sb.append(" ");
        }
    }
    if (threadPrinting) {
        sb.append("[%t] ");
    }
    sb.append("%p ");
    if (categoryPrefixing) {
        sb.append("%c ");
    }
    if (contextPrinting) {
        sb.append("%notEmpty{%ndc }");
    }
    sb.append("- %m%n");
    return new LayoutWrapper(PatternLayout.newBuilder()
            .setPattern(sb.toString())
            .setConfiguration(config)
            .build());
}
 
Example #18
Source File: SyslogAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private Appender createAppender(final String name, final Log4j1Configuration configuration, Layout layout,
        String facility, final Filter filter, final String syslogHost, final String level) {
    Holder<String> host = new Holder<>();
    Holder<Integer> port = new Holder<>();
    resolveSyslogHost(syslogHost, host, port);
    org.apache.logging.log4j.core.Layout appenderLayout;
    if (layout instanceof LayoutWrapper) {
        appenderLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        appenderLayout = new LayoutAdapter(layout);
    } else {
        appenderLayout = SyslogLayout.newBuilder()
                .setFacility(Facility.toFacility(facility))
                .setConfiguration(configuration)
                .build();
    }

    org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
    return new AppenderWrapper(SyslogAppender.newBuilder()
            .setName(name)
            .setConfiguration(configuration)
            .setLayout(appenderLayout)
            .setFilter(fileFilter)
            .setPort(port.get())
            .setProtocol(Protocol.TCP)
            .setHost(host.get())
            .build());
}
 
Example #19
Source File: LogWriter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void setLayout( Layout layout ) {
  LogWriter.layout = layout; // save for later creation of new files...

  Enumeration<?> appenders = logWriter.pentahoLogger.getAllAppenders();
  while ( appenders.hasMoreElements() ) {
    Appender appender = (Appender) appenders.nextElement();
    if ( appender instanceof Log4jConsoleAppender || appender instanceof Log4jFileAppender ) {
      appender.setLayout( layout );
    }
  }
}
 
Example #20
Source File: ConsoleAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
@Override
public Appender parseAppender(final String name, final String appenderPrefix, final String layoutPrefix,
        final String filterPrefix, final Properties props, final PropertiesConfiguration configuration) {
    Layout layout = configuration.parseLayout(layoutPrefix, name, props);
    Filter filter = configuration.parseAppenderFilters(props, filterPrefix, name);
    String level = getProperty(THRESHOLD_PARAM);
    String target = getProperty(TARGET);
    return createAppender(name, layout, filter, level, target, configuration);
}
 
Example #21
Source File: LevelMatchFilterTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void accept() throws Exception {
  
  // set up appender
  Layout layout = new SimpleLayout();
  Appender appender = new FileAppender(layout, ACCEPT_FILE, false);
  
  // create LevelMatchFilter
  LevelMatchFilter matchFilter = new LevelMatchFilter();
 
   // attach match filter to appender
  appender.addFilter(matchFilter);
 
  // attach DenyAllFilter to end of filter chain to deny neutral
  // (non matching) messages
  appender.addFilter(new DenyAllFilter());
      
  // set appender on root and set level to debug
  root.addAppender(appender);
  root.setLevel(Level.TRACE);
  
  Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN, 
		      Level.ERROR, Level.FATAL};
  for (int x = 0; x < levelArray.length; x++) {
    // set the level to match
    matchFilter.setLevelToMatch(levelArray[x].toString());
    common("pass " + x + "; filter set to accept only " 
    + levelArray[x].toString() + " msgs");
  }
  
  Transformer.transform(ACCEPT_FILE, ACCEPT_FILTERED, new LineNumberFilter());
  assertTrue(Compare.compare(ACCEPT_FILTERED, ACCEPT_WITNESS));
}
 
Example #22
Source File: LevelMatchFilterTestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void deny() throws Exception {
  
  // set up appender
  Layout layout = new SimpleLayout();
  Appender appender = new FileAppender(layout, DENY_FILE, false);
  
  // create LevelMatchFilter, set to deny matches
  LevelMatchFilter matchFilter = new LevelMatchFilter();
  matchFilter.setAcceptOnMatch(false);
 
   // attach match filter to appender
  appender.addFilter(matchFilter);
         
  // set appender on root and set level to debug
  root.addAppender(appender);
  root.setLevel(Level.TRACE);
  
  Level[] levelArray = new Level[] {Level.TRACE, Level.DEBUG, Level.INFO, Level.WARN,
		      Level.ERROR, Level.FATAL};
  for (int x = 0; x < levelArray.length; x++) {
    // set the level to match
    matchFilter.setLevelToMatch(levelArray[x].toString());
    common("pass " + x + "; filter set to deny only " + levelArray[x].toString()
            + " msgs");
  }
  
  Transformer.transform(DENY_FILE, DENY_FILTERED, new LineNumberFilter());
  assertTrue(Compare.compare(DENY_FILTERED, DENY_WITNESS));
}
 
Example #23
Source File: SyslogAppenderTest.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Test two parameter constructor.
 */
public void testTwoParamConstructor() {
  Layout layout = new PatternLayout();
  SyslogAppender appender = new SyslogAppender(layout, 24);
  assertEquals("daemon", appender.getFacility());
  assertEquals(false, appender.getFacilityPrinting());
  assertEquals(layout, appender.getLayout());
  assertNull(appender.getSyslogHost());
  assertTrue(appender.requiresLayout());
}
 
Example #24
Source File: Log4jFileAppenderTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Test
public void doAppend() throws IOException {
  LoggingEvent loggingEvent = mock( LoggingEvent.class );
  Layout testLayout = mock( Layout.class );
  when( testLayout.format( loggingEvent ) ).thenReturn( "LOG_TEST_LINE" );
  log4jFileAppender.setLayout( testLayout );
  log4jFileAppender.doAppend( loggingEvent );
  verify( outputStream ).write( ( "LOG_TEST_LINE" + Const.CR ).getBytes() );
}
 
Example #25
Source File: DailyRollingFileAppenderBuilder.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private <T extends Log4j1Configuration> Appender createAppender(final String name, final Layout layout,
        final Filter filter, final String fileName, final boolean append, boolean immediateFlush,
        final String level, final boolean bufferedIo, final int bufferSize, final T configuration) {

    org.apache.logging.log4j.core.Layout<?> fileLayout = null;
    if (bufferedIo) {
        immediateFlush = true;
    }
    if (layout instanceof LayoutWrapper) {
        fileLayout = ((LayoutWrapper) layout).getLayout();
    } else if (layout != null) {
        fileLayout = new LayoutAdapter(layout);
    }
    org.apache.logging.log4j.core.Filter fileFilter = buildFilters(level, filter);
    if (fileName == null) {
        LOGGER.warn("Unable to create File Appender, no file name provided");
        return null;
    }
    String filePattern = fileName +"%d{yyy-MM-dd}";
    TriggeringPolicy policy = TimeBasedTriggeringPolicy.newBuilder().setModulate(true).build();
    RolloverStrategy strategy = DefaultRolloverStrategy.newBuilder()
            .setConfig(configuration)
            .setMax(Integer.toString(Integer.MAX_VALUE))
            .build();
    return new AppenderWrapper(RollingFileAppender.newBuilder()
            .setName(name)
            .setConfiguration(configuration)
            .setLayout(fileLayout)
            .setFilter(fileFilter)
            .setFileName(fileName)
            .setBufferSize(bufferSize)
            .setImmediateFlush(immediateFlush)
            .setFilePattern(filePattern)
            .setPolicy(policy)
            .setStrategy(strategy)
            .build());
}
 
Example #26
Source File: JListView.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public Component getListCellRendererComponent(JList list,
					Object value, 
					int index, // cell index
					boolean isSelected, 
					boolean cellHasFocus) {

     //      System.out.println(o + " ============== " + i++);
     //LogLog.error("=======", new Exception());
     //setIcon(longIcon);
     if(value instanceof LoggingEvent) {
LoggingEvent event = (LoggingEvent) value;
String str = layout.format(event);
String t = event.getThrowableInformation();

if(t != null) {
  setText(str + Layout.LINE_SEP + t);
} else {	
  setText(str);
}

     } else {
setText(value.toString());
     }


     return this;
   }
 
Example #27
Source File: KettleLogChannelAppender.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Create an appender that logs to the provided log channel
 *
 * @param log    Log channel to log to
 * @param layout layout to use
 * @throws NullPointerException If {@code log} is null
 */
public KettleLogChannelAppender( LogChannelInterface log, Layout layout ) {
  if ( log == null || layout == null ) {
    throw new NullPointerException();
  }
  setLayout( layout );
  this.log = log;
}
 
Example #28
Source File: PropertiesConfiguration.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private Layout buildLayout(String layoutPrefix, String className, String appenderName, Properties props) {
    Layout layout = newInstanceOf(className, "Layout");
    if (layout == null) {
        return null;
    }
    LOGGER.debug("Parsing layout options for \"{}\".", appenderName);
    PropertySetter.setProperties(layout, props, layoutPrefix + ".");
    LOGGER.debug("End of parsing for \"{}\".", appenderName);
    return layout;
}
 
Example #29
Source File: Log4JTaskLogs.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
private void appendEventToLogs(LoggingEvent logEvent, StringBuffer logs, Layout logFormat, boolean timeStamp) {
    if (timeStamp) {
        logs.append(StringUtils.stripEnd(logFormat.format(logEvent), null) + nl);
    } else {
        Object message = logEvent.getMessage();
        logs.append(StringUtils.stripEnd(message.toString(), null) + nl);
    }
}
 
Example #30
Source File: Log4JTaskLogs.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @see org.ow2.proactive.scheduler.common.task.TaskLogs#getStdoutLogs(boolean
 *      timeStamp)
 */
public synchronized String getStdoutLogs(boolean timeStamp) {
    restoreEvents();
    StringBuffer logs = new StringBuffer();
    Layout l = getTaskLogLayout();
    for (LoggingEvent e : this.allEvents) {
        if (Log4JTaskLogs.STDOUT_LEVEL.equals(e.getLevel())) {
            appendEventToLogs(e, logs, l, timeStamp);
        }
    }

    return logs.toString();
}