Search in sources :

Example 1 with TurboFilter

use of ch.qos.logback.classic.turbo.TurboFilter in project sling by apache.

the class TurboFilterTracker method addingService.

@Override
public Object addingService(ServiceReference reference) {
    TurboFilter tf = (TurboFilter) super.addingService(reference);
    tf.setContext(loggerContext);
    tf.start();
    attachFilter(tf);
    filters.put(reference, tf);
    return tf;
}
Also used : TurboFilter(ch.qos.logback.classic.turbo.TurboFilter)

Example 2 with TurboFilter

use of ch.qos.logback.classic.turbo.TurboFilter in project sling by apache.

the class TurboFilterTracker method removedService.

@Override
public void removedService(ServiceReference reference, Object service) {
    TurboFilter tf = (TurboFilter) service;
    filters.remove(reference);
    loggerContext.getTurboFilterList().remove(tf);
    super.removedService(reference, service);
}
Also used : TurboFilter(ch.qos.logback.classic.turbo.TurboFilter)

Example 3 with TurboFilter

use of ch.qos.logback.classic.turbo.TurboFilter in project sling by apache.

the class SlingLogPanel method appendTurboFilterData.

private void appendTurboFilterData(final PrintWriter pw, final String consoleAppRoot, final LoggerStateContext ctx) {
    if (ctx.loggerContext.getTurboFilterList().isEmpty()) {
        return;
    }
    pw.println("<div class='table'>");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>Turbo Filters</div>");
    pw.println("<table class='nicetable ui-widget'>");
    pw.println("<thead class='ui-widget-header'>");
    pw.println("<tr>");
    pw.println("<th>Turbo Filter</th>");
    pw.print("<th>");
    // no need to escape
    pw.print(getConfigColTitle(consoleAppRoot));
    pw.println("</th>");
    pw.println("</tr>");
    pw.println("</thead>");
    pw.println("<tbody class='ui-widget-content'>");
    for (final TurboFilter tf : ctx.loggerContext.getTurboFilterList()) {
        pw.println("<tr>");
        pw.println("<td>");
        pw.print(XmlUtil.escapeXml(getName(tf)));
        pw.println("</td>");
        pw.print("<td>");
        pw.print(formatPid(consoleAppRoot, tf, ctx));
        pw.println("</td>");
        pw.println("</tr>");
    }
    pw.println("</tbody>");
    pw.println("</table>");
    pw.println("</div>");
}
Also used : TurboFilter(ch.qos.logback.classic.turbo.TurboFilter)

Example 4 with TurboFilter

use of ch.qos.logback.classic.turbo.TurboFilter in project cassandra by apache.

the class ThreadAwareSecurityManager method install.

public static void install() {
    if (installed)
        return;
    System.setSecurityManager(new ThreadAwareSecurityManager());
    Logger l = LoggerFactory.getLogger(ThreadAwareSecurityManager.class);
    ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) l;
    LoggerContext ctx = logbackLogger.getLoggerContext();
    TurboFilterList turboFilterList = ctx.getTurboFilterList();
    for (int i = 0; i < turboFilterList.size(); i++) {
        TurboFilter turboFilter = turboFilterList.get(i);
        if (turboFilter instanceof ReconfigureOnChangeFilter) {
            ReconfigureOnChangeFilter reconfigureOnChangeFilter = (ReconfigureOnChangeFilter) turboFilter;
            turboFilterList.set(i, new SMAwareReconfigureOnChangeFilter(reconfigureOnChangeFilter));
            break;
        }
    }
    installed = true;
}
Also used : TurboFilterList(ch.qos.logback.classic.spi.TurboFilterList) Logger(org.slf4j.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) ReconfigureOnChangeFilter(ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter) TurboFilter(ch.qos.logback.classic.turbo.TurboFilter)

Example 5 with TurboFilter

use of ch.qos.logback.classic.turbo.TurboFilter in project sling by apache.

the class LogTracerTest method checkTracing.

@Test
public void checkTracing() throws Exception {
    HttpServletRequest request = mock(SlingHttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    when(request.getParameter(LogTracer.PARAM_TRACER_CONFIG)).thenReturn("a.b.c;level=trace,a.b;level=debug");
    activateTracer();
    Level oldLevel = rootLogger().getLevel();
    rootLogger().setLevel(Level.INFO);
    FilterChain chain = new FilterChain() {

        @Override
        public void doFilter(ServletRequest request, ServletResponse response) throws IOException, ServletException {
            TurboFilter turboFilter = context.getService(TurboFilter.class);
            assertNotNull(turboFilter);
            getLogContext().addTurboFilter(turboFilter);
            getLogger("a").info("a-info");
            getLogger("a").debug("a-debug");
            getLogger("a.b").info("a.b-info");
            getLogger("a.b").debug("a.b-debug");
            getLogger("a.b").trace("a.b-trace");
            getLogger("a.b.c").debug("a.b.c-debug");
            getLogger("a.b.c").trace("a.b.c-trace");
            getLogger("a.b.c.d").trace("a.b.c.d-trace");
            if (getLogger("a.b.c").isTraceEnabled()) {
                getLogger("a.b.c").trace("a.b.c-trace2");
            }
        }
    };
    Filter filter = getFilter(true);
    filter.doFilter(request, response, chain);
    assertNull(context.getService(TurboFilter.class));
    List<String> logs = logCollector.getLogs();
    assertThat(logs, hasItem("a-info"));
    assertThat(logs, not(hasItem("a-debug")));
    assertThat(logs, hasItem("a.b-info"));
    assertThat(logs, hasItem("a.b-debug"));
    assertThat(logs, not(hasItem("a.b-trace")));
    assertThat(logs, hasItem("a.b.c-debug"));
    assertThat(logs, hasItem("a.b.c-trace"));
    assertThat(logs, hasItem("a.b.c-trace2"));
    assertThat(logs, hasItem("a.b.c.d-trace"));
    rootLogger().setLevel(oldLevel);
}
Also used : SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) MockSlingHttpServletRequest(org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest) ServletRequest(javax.servlet.ServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletResponse(javax.servlet.ServletResponse) TurboFilter(ch.qos.logback.classic.turbo.TurboFilter) Filter(javax.servlet.Filter) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Level(ch.qos.logback.classic.Level) TurboFilter(ch.qos.logback.classic.turbo.TurboFilter) Test(org.junit.Test)

Aggregations

TurboFilter (ch.qos.logback.classic.turbo.TurboFilter)11 Test (org.junit.Test)5 FilterChain (javax.servlet.FilterChain)4 ServletRequest (javax.servlet.ServletRequest)4 ServletResponse (javax.servlet.ServletResponse)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 SlingHttpServletRequest (org.apache.sling.api.SlingHttpServletRequest)4 MockSlingHttpServletRequest (org.apache.sling.testing.mock.sling.servlet.MockSlingHttpServletRequest)4 LoggerContext (ch.qos.logback.classic.LoggerContext)3 TurboFilterList (ch.qos.logback.classic.spi.TurboFilterList)3 ReconfigureOnChangeFilter (ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter)3 Filter (javax.servlet.Filter)3 Logger (org.slf4j.Logger)2 Level (ch.qos.logback.classic.Level)1 Logger (ch.qos.logback.classic.Logger)1 ReconfigureOnChangeTask (ch.qos.logback.classic.joran.ReconfigureOnChangeTask)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 JsonObject (javax.json.JsonObject)1