use of ch.qos.logback.core.FileAppender in project sling by apache.
the class SlingConfigurationPrinter method getAttachments.
/**
* Attempts to determine all log files created even via rotation.
* if some complex rotation logic is used where rotated file get different names
* or get created in different directory then those files would not be
* included
*
* @see org.apache.felix.webconsole.AttachmentProvider#getAttachments(String)
*/
@SuppressWarnings("UnusedDeclaration")
public URL[] getAttachments(String mode) {
// we only provide urls for mode zip
if (MODE_ZIP.equals(mode)) {
final List<URL> urls = new ArrayList<URL>();
LogbackManager.LoggerStateContext ctx = logbackManager.determineLoggerState();
for (Appender<ILoggingEvent> appender : ctx.getAllAppenders()) {
if (appender instanceof FileAppender) {
final File[] files = getRotatedFiles((FileAppender) appender, getMaxOldFileCount());
for (File f : files) {
try {
urls.add(f.toURI().toURL());
} catch (MalformedURLException mue) {
// we just ignore this file then
}
}
}
}
if (urls.size() > 0) {
return urls.toArray(new URL[urls.size()]);
}
}
return null;
}
use of ch.qos.logback.core.FileAppender in project uavstack by uavorg.
the class LogBackHookProxy method figureoutLogConfiguration.
private void figureoutLogConfiguration(Logger Logger, LinkedList<LogProfileInfo> list, String appid) {
Iterator<Appender<ILoggingEvent>> appenders = Logger.iteratorForAppenders();
while (appenders != null && appenders.hasNext()) {
LogProfileInfo logProfileInfo = new LogProfileInfo();
if (appid != null) {
logProfileInfo.setAppId(appid);
}
logProfileInfo.setLogType(LogProfileInfo.LogType.Log4j);
Map<String, String> attributes = new HashMap<String, String>();
attributes.put(LogProfileInfo.ENGINE, "logback");
Appender<ILoggingEvent> appender = appenders.next();
if (!(appender instanceof FileAppender<?>)) {
continue;
}
FileAppender<ILoggingEvent> fileAppender = (FileAppender<ILoggingEvent>) appender;
@SuppressWarnings("rawtypes") LayoutWrappingEncoder encoder = (LayoutWrappingEncoder) fileAppender.getEncoder();
Layout<?> layout = encoder.getLayout();
if (null != layout) {
if (layout instanceof PatternLayout) {
PatternLayout patternLayout = (PatternLayout) encoder.getLayout();
attributes.put(LogProfileInfo.PATTERN, patternLayout.getPattern());
} else if (layout instanceof HTMLLayout) {
attributes.put(LogProfileInfo.PATTERN, "HTMLLayout");
} else if (layout instanceof XMLLayout) {
attributes.put(LogProfileInfo.PATTERN, "XMLLayout");
} else if (layout instanceof TTLLLayout) {
attributes.put(LogProfileInfo.PATTERN, "TTCCLayout");
}
}
logProfileInfo.setFilePath(fileAppender.getFile());
logProfileInfo.setAttributes(attributes);
list.add(logProfileInfo);
}
}
use of ch.qos.logback.core.FileAppender in project BIMserver by opensourceBIM.
the class JarBimServer method fixLogging.
/**
* Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
*
* @throws IOException
*/
private void fixLogging(BimServerConfig config) throws IOException {
Path logFolder = config.getHomeDir().resolve("logs");
if (!Files.isDirectory(logFolder)) {
Files.createDirectories(logFolder);
}
Path file = logFolder.resolve("bimserver.log");
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(lc);
ple.start();
FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
String filename = file.toAbsolutePath().toString();
if (lc instanceof LoggerContext) {
if (!lc.isStarted()) {
lc.start();
}
}
System.out.println("Logging to " + filename);
fileAppender.setFile(filename);
fileAppender.setEncoder(ple);
fileAppender.setContext(lc);
fileAppender.start();
for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
if (log.getLevel() != null) {
log.addAppender(fileAppender);
}
}
}
use of ch.qos.logback.core.FileAppender in project BIMserver by opensourceBIM.
the class LocalDevBimServerStarter method fixLogging.
/**
* Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
*
* @throws IOException
*/
private void fixLogging(BimServerConfig config) throws IOException {
Path logFolder = config.getHomeDir().resolve("logs");
if (!Files.isDirectory(logFolder)) {
Files.createDirectories(logFolder);
}
Path file = logFolder.resolve("bimserver.log");
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(lc);
ple.start();
FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
String filename = file.toAbsolutePath().toString();
if (lc instanceof LoggerContext) {
if (!lc.isStarted()) {
lc.start();
}
}
System.out.println("Logging to " + filename);
fileAppender.setFile(filename);
fileAppender.setEncoder(ple);
fileAppender.setContext(lc);
fileAppender.start();
for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
if (log.getLevel() != null) {
log.addAppender(fileAppender);
}
}
}
use of ch.qos.logback.core.FileAppender in project BIMserver by opensourceBIM.
the class WarServerInitializer method fixLogging.
/**
* Add a file appender to every logger we can find (the loggers should already have been configured via logback.xml)
*
* @throws IOException
*/
private void fixLogging(BimServerConfig config) throws IOException {
Path logFolder = config.getHomeDir().resolve("logs");
if (!Files.isDirectory(logFolder)) {
Files.createDirectories(logFolder);
}
Path file = logFolder.resolve("bimserver.log");
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%date %level [%thread] %logger{10} [%file:%line] %msg%n");
ple.setContext(lc);
ple.start();
FileAppender<ILoggingEvent> fileAppender = new FileAppender<ILoggingEvent>();
String filename = file.toAbsolutePath().toString();
if (lc instanceof LoggerContext) {
if (!lc.isStarted()) {
lc.start();
}
}
System.out.println("Logging to " + filename);
fileAppender.setFile(filename);
fileAppender.setEncoder(ple);
fileAppender.setContext(lc);
fileAppender.start();
for (ch.qos.logback.classic.Logger log : lc.getLoggerList()) {
if (log.getLevel() != null) {
log.addAppender(fileAppender);
}
}
}
Aggregations