use of ch.qos.logback.core.joran.spi.JoranException in project midpoint by Evolveum.
the class LoggingConfigurationManager method configure.
public static void configure(LoggingConfigurationType config, String version, OperationResult result) throws SchemaException {
OperationResult res = result.createSubresult(LoggingConfigurationManager.class.getName() + ".configure");
if (InternalsConfig.avoidLoggingChange) {
LOGGER.info("IGNORING change of logging configuration (current config version: {}, new version {}) because avoidLoggingChange=true", currentlyUsedVersion, version);
res.recordNotApplicableIfUnknown();
return;
}
if (currentlyUsedVersion != null) {
LOGGER.info("Applying logging configuration (currently applied version: {}, new version: {})", currentlyUsedVersion, version);
} else {
LOGGER.info("Applying logging configuration (version {})", version);
}
currentlyUsedVersion = version;
// JUL Bridge initialization was here. (SLF4JBridgeHandler)
// But it was moved to a later phase as suggested by http://jira.qos.ch/browse/LOGBACK-740
// Initialize JUL bridge
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
//Get current log configuration
LoggerContext lc = (LoggerContext) TraceManager.getILoggerFactory();
//Prepare configurator in current context
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(lc);
//Generate configuration file as string
String configXml = prepareConfiguration(config);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("New logging configuration:");
LOGGER.trace(configXml);
}
InputStream cis = new ByteArrayInputStream(configXml.getBytes());
LOGGER.info("Resetting current logging configuration");
lc.getStatusManager().clear();
//Set all loggers to error
for (Logger l : lc.getLoggerList()) {
LOGGER.trace("Disable logger: {}", l);
l.setLevel(Level.ERROR);
}
// Reset configuration
lc.reset();
//Switch to new logging configuration
lc.setName("MidPoint");
try {
configurator.doConfigure(cis);
LOGGER.info("New logging configuration applied");
} catch (JoranException e) {
System.out.println("Error during applying logging configuration: " + e.getMessage());
LOGGER.error("Error during applying logging configuration: " + e.getMessage(), e);
result.createSubresult("Applying logging configuration.").recordFatalError(e.getMessage(), e);
} catch (NumberFormatException e) {
System.out.println("Error during applying logging configuration: " + e.getMessage());
LOGGER.error("Error during applying logging configuration: " + e.getMessage(), e);
result.createSubresult("Applying logging configuration.").recordFatalError(e.getMessage(), e);
}
//Get messages if error occurred;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
StatusPrinter.setPrintStream(new PrintStream(baos));
StatusPrinter.print(lc);
String internalLog = null;
try {
internalLog = baos.toString("UTF8");
} catch (UnsupportedEncodingException e) {
// should never happen
LOGGER.error("Woops?", e);
}
if (!StringUtils.isEmpty(internalLog)) {
//Parse internal log
res.recordSuccess();
String[] internalLogLines = internalLog.split("\n");
for (int i = 0; i < internalLogLines.length; i++) {
if (internalLogLines[i].contains("|-ERROR"))
res.recordPartialError(internalLogLines[i]);
res.appendDetail(internalLogLines[i]);
}
LOGGER.trace("LogBack internal log:\n{}", internalLog);
} else {
res.recordSuccess();
}
// Initialize JUL bridge
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
return;
}
use of ch.qos.logback.core.joran.spi.JoranException in project sling by apache.
the class OsgiInternalAction method begin.
@SuppressWarnings("unchecked")
@Override
public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException {
ec.addInPlayListener(new ConfigCompleteListener(ec));
populateSubstitutionProperties(ec);
// TO CHECK Should we add the config fragment at end
final Collection<ConfigSourceInfo> providers = getFragmentProviders();
List<SaxEvent> consolidatedEventList = new ArrayList<SaxEvent>();
for (ConfigSourceInfo cp : providers) {
InputSource is = cp.getConfigProvider().getConfigSource();
try {
SaxEventRecorder recorder = new SaxEventRecorder(context);
recorder.recordEvents(is);
// remove the <included> tag from the beginning and </included>
// from the end
trimHeadAndTail(recorder);
consolidatedEventList.addAll(recorder.getSaxEventList());
} catch (JoranException e) {
addError("Error while parsing xml obtained from [" + cp + "]", e);
} finally {
Util.close(is);
}
}
// offset = 2, because we need to get past this element as well as the
// end element
ec.getJoranInterpreter().getEventPlayer().addEventsDynamically(consolidatedEventList, 2);
}
use of ch.qos.logback.core.joran.spi.JoranException in project GeoGig by boundlessgeo.
the class Logging method tryConfigureLogging.
static void tryConfigureLogging(Platform platform) {
// instantiate and call ResolveGeogigDir directly to avoid calling getGeogig() and hence get
// some logging events before having configured logging
final Optional<URL> geogigDirUrl = new ResolveGeogigDir(platform).call();
if (!geogigDirUrl.isPresent() || !"file".equalsIgnoreCase(geogigDirUrl.get().getProtocol())) {
// redirect java.util.logging to SLF4J anyways
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
return;
}
final File geogigDir;
try {
geogigDir = new File(geogigDirUrl.get().toURI());
} catch (URISyntaxException e) {
throw Throwables.propagate(e);
}
if (geogigDir.equals(geogigDirLoggingConfiguration)) {
return;
}
if (!geogigDir.exists() || !geogigDir.isDirectory()) {
return;
}
final URL loggingFile = getOrCreateLoggingConfigFile(geogigDir);
if (loggingFile == null) {
return;
}
try {
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
/*
* Set the geogigdir variable for the config file can resolve the default location
* ${geogigdir}/log/geogig.log
*/
loggerContext.putProperty("geogigdir", geogigDir.getAbsolutePath());
JoranConfigurator configurator = new JoranConfigurator();
configurator.setContext(loggerContext);
configurator.doConfigure(loggingFile);
// redirect java.util.logging to SLF4J
SLF4JBridgeHandler.removeHandlersForRootLogger();
SLF4JBridgeHandler.install();
geogigDirLoggingConfiguration = geogigDir;
} catch (JoranException e) {
LOGGER.error("Error configuring logging from file {}. '{}'", loggingFile, e.getMessage(), e);
}
}
use of ch.qos.logback.core.joran.spi.JoranException in project cdap by caskdata.
the class LogPipelineLoader method doLoad.
/**
* Loads the log pipeline configurations
*
* @param contextProvider a guice {@link Provider} for creating new instance of {@link LoggerContext}.
* @param ignoreOnError {@code true} to ignore pipeline configuration that has error.
* @param <T> Type of the {@link LoggerContext}
* @return a map from pipeline name to the {@link LogPipelineSpecification}
* @throws InvalidPipelineException if any of the pipeline configuration is invalid.
*/
private <T extends LoggerContext> Map<String, LogPipelineSpecification<T>> doLoad(Provider<T> contextProvider, boolean ignoreOnError) throws InvalidPipelineException {
Map<String, LogPipelineSpecification<T>> result = new HashMap<>();
Set<byte[]> checkpointPrefixes = new TreeSet<>(Bytes.BYTES_COMPARATOR);
checkpointPrefixes.addAll(RESERVED_CHECKPOINT_PREFIX);
for (URL configURL : getPipelineConfigURLs()) {
try {
LogPipelineSpecification<T> spec = load(contextProvider, configURL);
LogPipelineSpecification<T> existingSpec = result.get(spec.getName());
if (existingSpec != null) {
if (!ignoreOnError) {
throw new InvalidPipelineException("Duplicate pipeline with name " + spec.getName() + " at " + configURL + ". It was already defined at " + existingSpec.getSource());
}
LOG.warn("Pipeline {} already defined in {}. Ignoring the duplicated one from {}.", spec.getName(), existingSpec.getSource(), configURL);
continue;
}
if (!checkpointPrefixes.add(spec.getCheckpointPrefix())) {
if (!ignoreOnError) {
// Checkpoint prefix can't be the same, otherwise pipeline checkpoints will be overwriting each other.
throw new InvalidPipelineException("Checkpoint prefix " + Bytes.toStringBinary(spec.getCheckpointPrefix()) + " already exists. " + "Please either remove the property " + Constants.Logging.PIPELINE_CHECKPOINT_PREFIX_NUM + " or use a different value.");
}
LOG.warn("Pipeline {} has checkpoint prefix {} already defined by other pipeline. Ignoring one from {}.", spec.getName(), Bytes.toStringBinary(spec.getCheckpointPrefix()), spec.getSource());
continue;
}
if (SYSTEM_LOG_PIPELINE_NAME.equals(spec.getName())) {
// Make sure the byte prefix is correct
if (!Arrays.equals(spec.getCheckpointPrefix(), Constants.Logging.SYSTEM_PIPELINE_CHECKPOINT_PREFIX)) {
// This error cannot be ignored
throw new InvalidPipelineException("System pipeline '" + SYSTEM_LOG_PIPELINE_NAME + "' should have checkpoint prefix set to " + Bytes.toStringBinary(Constants.Logging.SYSTEM_PIPELINE_CHECKPOINT_PREFIX));
}
}
result.put(spec.getName(), spec);
} catch (JoranException e) {
if (!ignoreOnError) {
throw new InvalidPipelineException("Failed to process log processing pipeline config at " + configURL, e);
}
LOG.warn("Ignoring invalid log processing pipeline configuration in {} due to\n {}", configURL, e.getMessage());
}
}
Preconditions.checkState(result.containsKey(SYSTEM_LOG_PIPELINE_NAME), "The CDAP system log processing pipeline is missing. " + "Please check and fix any configuration error shown earlier in the log.");
return result;
}
Aggregations