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));
}
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);
}
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;
}
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);
}
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());
}
Aggregations