Search in sources :

Example 76 with LoggerContext

use of ch.qos.logback.classic.LoggerContext in project chassis by Kixeye.

the class LoggingConfiguration method reloadLogging.

/**
	 * Reloads logging.
	 * 
	 * @param logbackConfig XML containing the logback configuration
	 */
public void reloadLogging(String logbackConfig) {
    LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(logContext);
        logContext.reset();
        configurator.doConfigure(new ByteArrayInputStream(logbackConfig.getBytes(Charsets.UTF_8)));
    } catch (JoranException je) {
    // StatusPrinter will handle this
    } catch (Exception ex) {
        // Just in case, so we see a stacktrace
        ex.printStackTrace();
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(logContext);
    applicationContext.publishEvent(new LoggingReloadedApplicationEvent(this));
}
Also used : LoggingReloadedApplicationEvent(com.kixeye.chassis.support.events.LoggingReloadedApplicationEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) JoranException(ch.qos.logback.core.joran.spi.JoranException) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) LoggerContext(ch.qos.logback.classic.LoggerContext) JoranException(ch.qos.logback.core.joran.spi.JoranException)

Example 77 with LoggerContext

use of ch.qos.logback.classic.LoggerContext in project Gadgetbridge by Freeyourgadget.

the class Logging method debugLoggingConfiguration.

public void debugLoggingConfiguration() {
    // For debugging problems with the logback configuration
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    // print logback's internal status
    StatusPrinter.print(lc);
//        Logger logger = LoggerFactory.getLogger(Logging.class);
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 78 with LoggerContext

use of ch.qos.logback.classic.LoggerContext in project OpenClinica by OpenClinica.

the class OpenRosaServices method getForm.

@GET
@Path("/{studyOID}/form")
@Produces(MediaType.TEXT_XML)
public XFormList getForm(@Context HttpServletRequest request, @Context HttpServletResponse response, @PathParam("studyOID") String studyOID, @QueryParam("formID") String uniqueId, @RequestHeader("Authorization") String authorization, @Context ServletContext context) throws Exception {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    // print logback's internal status
    StatusPrinter.print(lc);
    if (!mayProceedPreview(studyOID))
        return null;
    String flavor = getQuerySet(uniqueId);
    String formLayoutOid = getFormLayoutOid(uniqueId);
    FormLayout formLayout = formLayoutDao.findByOcOID(formLayoutOid);
    CrfBean crf = crfDao.findById(formLayout.getCrf().getCrfId());
    String xformOutput = "";
    String directoryPath = Utils.getCrfMediaFilePath(crf.getOcOid(), formLayout.getOcOid());
    File dir = new File(directoryPath);
    File[] directoryListing = dir.listFiles();
    if (directoryListing != null) {
        for (File child : directoryListing) {
            if (flavor.equals(QUERY_FLAVOR) && child.getName().endsWith(QUERY_SUFFIX) || flavor.equals(NO_FLAVOR) && child.getName().endsWith(NO_SUFFIX)) {
                xformOutput = new String(Files.readAllBytes(Paths.get(child.getPath())));
                break;
            }
        }
    }
    XFormList formList = null;
    try {
        formList = new XFormList();
        XForm form = new XForm(crf, formLayout);
        // TODO Uncomment this before checking in
        if (StringUtils.isNotEmpty(xformOutput)) {
            form.setHash(DigestUtils.md5Hex(xformOutput));
        }
        String urlBase = getCoreResources().getDataInfo().getProperty("sysURL").split("/MainMenu")[0];
        List<FormLayoutMedia> mediaList = formLayoutMediaDao.findByFormLayoutIdForNoteTypeMedia(formLayout.getFormLayoutId());
        if (flavor.equals(QUERY_FLAVOR)) {
            form.setDownloadURL(urlBase + "/rest2/openrosa/" + studyOID + "/formXml?formId=" + formLayout.getOcOid() + QUERY);
            form.setManifestURL(urlBase + "/rest2/openrosa/" + studyOID + "/manifest?formId=" + formLayout.getOcOid() + QUERY);
            form.setFormID(formLayout.getOcOid() + QUERY);
        } else {
            form.setDownloadURL(urlBase + "/rest2/openrosa/" + studyOID + "/formXml?formId=" + formLayout.getOcOid());
            form.setManifestURL(urlBase + "/rest2/openrosa/" + studyOID + "/manifest?formId=" + formLayout.getOcOid());
        }
        formList.add(form);
    } catch (Exception e) {
        LOGGER.error(e.getMessage());
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    // return "<Error>" + e.getMessage() + "</Error>";
    }
    return formList;
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) CrfBean(org.akaza.openclinica.domain.datamap.CrfBean) XFormList(org.akaza.openclinica.web.pform.formlist.XFormList) XForm(org.akaza.openclinica.web.pform.formlist.XForm) FormLayoutMedia(org.akaza.openclinica.domain.datamap.FormLayoutMedia) LoggerContext(ch.qos.logback.classic.LoggerContext) MediaFile(org.akaza.openclinica.web.pform.manifest.MediaFile) File(java.io.File) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 79 with LoggerContext

use of ch.qos.logback.classic.LoggerContext in project jackrabbit-oak by apache.

the class BroadcastTest method listen.

private static void listen() throws InterruptedException {
    String config = "key 123";
    ConsoleAppender<ILoggingEvent> ca = new ConsoleAppender<ILoggingEvent>();
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    ca.setContext(lc);
    PatternLayout pl = new PatternLayout();
    pl.setPattern("%msg%n");
    pl.setContext(lc);
    pl.start();
    ca.setLayout(pl);
    ca.start();
    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(TCPBroadcaster.class);
    logger.addAppender(ca);
    logger.setLevel(Level.DEBUG);
    TCPBroadcaster receiver = new TCPBroadcaster(config);
    receiver.addListener(new Broadcaster.Listener() {

        @Override
        public void receive(ByteBuffer buff) {
            int end = buff.position();
            StringBuilder sb = new StringBuilder();
            while (buff.remaining() > 0) {
                char c = (char) buff.get();
                if (c >= ' ' && c < 128) {
                    sb.append(c);
                } else if (c <= 9) {
                    sb.append((char) ('0' + c));
                } else {
                    sb.append('.');
                }
            }
            String dateTime = new Timestamp(System.currentTimeMillis()).toString().substring(0, 19);
            System.out.println(dateTime + " Received " + sb);
            buff.position(end);
        }
    });
    Random r = new Random();
    int x = r.nextInt();
    System.out.println("Sending " + x);
    for (int i = 0; i < 10; i++) {
        Thread.sleep(10);
        ByteBuffer buff = ByteBuffer.allocate(1024);
        buff.putInt(0);
        buff.putInt(x);
        buff.put(new byte[100]);
        buff.flip();
        receiver.send(buff);
        if (!receiver.isRunning()) {
            System.out.println("Did not start or already stopped");
            break;
        }
    }
    Thread.sleep(Integer.MAX_VALUE);
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) TCPBroadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster) PatternLayout(ch.qos.logback.classic.PatternLayout) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) ByteBuffer(java.nio.ByteBuffer) Timestamp(java.sql.Timestamp) Random(java.util.Random) Broadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.Broadcaster) TCPBroadcaster(org.apache.jackrabbit.oak.plugins.document.persistentCache.broadcast.TCPBroadcaster)

Example 80 with LoggerContext

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

the class ITDefaultConfig method testDefaultSettings.

/**
     * Checks the default settings. It runs the bundle with minimum dependencies
     */
@Test
public void testDefaultSettings() throws Exception {
    Logger slf4jLogger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    assertTrue("Default Log level should be INFO", slf4jLogger.isInfoEnabled());
    // Check for Logback being used
    assertTrue(LoggerFactory.getILoggerFactory() instanceof LoggerContext);
    assertTrue(slf4jLogger instanceof ch.qos.logback.classic.Logger);
    // Test that root logger has one FileAppender attached
    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) slf4jLogger;
    Iterator<Appender<ILoggingEvent>> itr = logger.iteratorForAppenders();
    assertTrue("One appender should be attached with root logger", itr.hasNext());
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(org.slf4j.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Aggregations

LoggerContext (ch.qos.logback.classic.LoggerContext)216 Test (org.junit.Test)134 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)43 Logger (ch.qos.logback.classic.Logger)41 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)26 FileAppender (ch.qos.logback.core.FileAppender)22 File (java.io.File)21 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)19 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)16 Appender (ch.qos.logback.core.Appender)14 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)14 JoranException (ch.qos.logback.core.joran.spi.JoranException)14 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)13 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)11 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)11 Logger (org.slf4j.Logger)10 IOException (java.io.IOException)8 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)7 URL (java.net.URL)7