org.apache.logging.log4j.core.config.Configuration.getScriptManager()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中org.apache.logging.log4j.core.config.Configuration.getScriptManager()方法的一些代码示例,展示了Configuration.getScriptManager()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getScriptManager()方法的具体详情如下:
包路径:org.apache.logging.log4j.core.config.Configuration
类名称:Configuration
方法名:getScriptManager

Configuration.getScriptManager介绍

暂无

代码示例

代码示例来源:origin: org.apache.logging.log4j/log4j-core

assertEquals("Unexpected Configuration", "BuilderTest", config.getName());
assertThat(config.getAppenders(), hasSize(equalTo(1)));
assertNotNull("Filter script not found", config.getScriptManager().getScript("filter.groovy"));
assertNotNull("pattern selector script not found", config.getScriptManager().getScript("selectorScript"));

代码示例来源:origin: ops4j/org.ops4j.pax.logging

private ScriptFilter(final AbstractScript script, final Configuration configuration, final Result onMatch,
           final Result onMismatch) {
  super(onMatch, onMismatch);
  this.script = script;
  this.configuration = configuration;
  if (!(script instanceof ScriptRef)) {
    configuration.getScriptManager().addScript(script);
  }
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * Constructs a new ScriptCondition.
 * 
 * @param script the script that can select files to delete
 * @param configuration configuration containing the StrSubstitutor passed to the script
 */
public ScriptCondition(final AbstractScript script, final Configuration configuration) {
  this.script = Objects.requireNonNull(script, "script");
  this.configuration = Objects.requireNonNull(configuration, "configuration");
  if (!(script instanceof ScriptRef)) {
    configuration.getScriptManager().addScript(script);
  }
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public Routes build() {
  if (routes == null || routes.length == 0) {
    LOGGER.error("No Routes configured.");
    return null;
  }
  if (patternScript != null && pattern != null) {
    LOGGER.warn("In a Routes element, you must configure either a Script element or a pattern attribute.");
  }
  if (patternScript != null) {
    if (configuration == null) {
      LOGGER.error("No Configuration defined for Routes; required for Script");
    } else {
      configuration.getScriptManager().addScript(patternScript);
    }
  }
  return new Routes(configuration, patternScript, pattern, routes);
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * Returns the pattern.
 * @param event The log event passed to the script (if there is a script.)
 * @param scriptStaticVariables The script's static variables.
 * @return the pattern.
 */
public String getPattern(final LogEvent event, final ConcurrentMap<Object, Object> scriptStaticVariables) {
  if (patternScript != null) {
    final ScriptManager scriptManager = configuration.getScriptManager();
    final Bindings bindings = scriptManager.createBindings(patternScript);
    bindings.put(STATIC_VARIABLES_KEY, scriptStaticVariables);
    bindings.put(LOG_EVENT_KEY, event);
    final Object object = scriptManager.execute(patternScript.getName(), bindings);
    bindings.remove(LOG_EVENT_KEY);
    return Objects.toString(object, null);
  }
  return pattern;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@PluginFactory
public static ScriptRef createReference(
    // @formatter:off
    @PluginAttribute("ref") final String name,
    @PluginConfiguration final Configuration configuration) {
    // @formatter:on
  if (name == null) {
    LOGGER.error("No script name provided");
    return null;
  }
  return new ScriptRef(name, configuration.getScriptManager());
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public ScriptPatternSelector build() {
  if (script == null) {
    LOGGER.error("A Script, ScriptFile or ScriptRef element must be provided for this ScriptFilter");
    return null;
  }
  if (script instanceof ScriptRef) {
    if (configuration.getScriptManager().getScript(script.getName()) == null) {
      LOGGER.error("No script with name {} has been declared.", script.getName());
      return null;
    }
  }
  if (defaultPattern == null) {
    defaultPattern = PatternLayout.DEFAULT_CONVERSION_PATTERN;
  }
  if (properties == null || properties.length == 0) {
    LOGGER.warn("No marker patterns were provided");
    return null;
  }
  return new ScriptPatternSelector(script, properties, defaultPattern, alwaysWriteExceptions, disableAnsi,
      noConsoleNoAnsi, configuration);
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public Appender build() {
  if (name == null) {
    LOGGER.error("Name missing.");
    return null;
  }
  if (script == null) {
    LOGGER.error("Script missing for ScriptAppenderSelector appender {}", name);
    return null;
  }
  if (appenderSet == null) {
    LOGGER.error("AppenderSet missing for ScriptAppenderSelector appender {}", name);
    return null;
  }
  if (configuration == null) {
    LOGGER.error("Configuration missing for ScriptAppenderSelector appender {}", name);
    return null;
  }
  final ScriptManager scriptManager = configuration.getScriptManager();
  scriptManager.addScript(script);
  final Bindings bindings = scriptManager.createBindings(script);
  final Object object = scriptManager.execute(script.getName(), bindings);
  final String appenderName = Objects.toString(object, null);
  final Appender appender = appenderSet.createAppender(appenderName, name);
  return appender;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public PatternFormatter[] getFormatters(final LogEvent event) {
  final SimpleBindings bindings = new SimpleBindings();
  bindings.putAll(configuration.getProperties());
  bindings.put("substitutor", configuration.getStrSubstitutor());
  bindings.put("logEvent", event);
  final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
  if (object == null) {
    return defaultFormatters;
  }
  final PatternFormatter[] patternFormatter = formatterMap.get(object.toString());
  return patternFormatter == null ? defaultFormatters : patternFormatter;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * @deprecated Use {@link #newBuilder()} instead. This will be private in a future version.
 */
@Deprecated
public ScriptPatternSelector(final AbstractScript script, final PatternMatch[] properties, final String defaultPattern,
               final boolean alwaysWriteExceptions, final boolean disableAnsi,
               final boolean noConsoleNoAnsi, final Configuration config) {
  this.script = script;
  this.configuration = config;
  if (!(script instanceof ScriptRef)) {
    config.getScriptManager().addScript(script);
  }
  final PatternParser parser = PatternLayout.createPatternParser(config);
  for (final PatternMatch property : properties) {
    try {
      final List<PatternFormatter> list = parser.parse(property.getPattern(), alwaysWriteExceptions, disableAnsi, noConsoleNoAnsi);
      formatterMap.put(property.getKey(), list.toArray(new PatternFormatter[list.size()]));
      patternMap.put(property.getKey(), property.getPattern());
    } catch (final RuntimeException ex) {
      throw new IllegalArgumentException("Cannot parse pattern '" + property.getPattern() + "'", ex);
    }
  }
  try {
    final List<PatternFormatter> list = parser.parse(defaultPattern, alwaysWriteExceptions, disableAnsi, noConsoleNoAnsi);
    defaultFormatters = list.toArray(new PatternFormatter[list.size()]);
    this.defaultPattern = defaultPattern;
  } catch (final RuntimeException ex) {
    throw new IllegalArgumentException("Cannot parse pattern '" + defaultPattern + "'", ex);
  }
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public Result filter(final LogEvent event) {
  final SimpleBindings bindings = new SimpleBindings();
  bindings.put("logEvent", event);
  bindings.putAll(configuration.getProperties());
  bindings.put("substitutor", configuration.getStrSubstitutor());
  final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
  return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

if (configuration.getScriptManager().getScript(script.getName()) == null) {
  LOGGER.error("ScriptCondition: No script with name {} has been declared.", script.getName());
  return null;

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * Creates the ScriptFilter.
 * @param script The script to run. The script must return a boolean value. Either script or scriptFile must be 
 *      provided.
 * @param match The action to take if a match occurs.
 * @param mismatch The action to take if no match occurs.
 * @param configuration the configuration 
 * @return A ScriptFilter.
 */
@PluginFactory
public static ScriptFilter createFilter(
    @PluginElement("Script") final AbstractScript script,
    @PluginAttribute("onMatch") final Result match,
    @PluginAttribute("onMismatch") final Result mismatch,
    @PluginConfiguration final Configuration configuration) {
  if (script == null) {
    LOGGER.error("A Script, ScriptFile or ScriptRef element must be provided for this ScriptFilter");
    return null;
  }
  if (script instanceof ScriptRef) {
    if (configuration.getScriptManager().getScript(script.getName()) == null) {
      logger.error("No script with name {} has been declared.", script.getName());
      return null;
    }
  }
  return new ScriptFilter(script, configuration, match, mismatch);
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final Message msg,
           final Throwable t) {
  final SimpleBindings bindings = new SimpleBindings();
  bindings.put("logger", logger);
  bindings.put("level", level);
  bindings.put("marker", marker);
  bindings.put("message", msg);
  bindings.put("parameters", null);
  bindings.put("throwable", t);
  bindings.putAll(configuration.getProperties());
  bindings.put("substitutor", configuration.getStrSubstitutor());
  final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
  return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final String msg,
           final Object... params) {
  final SimpleBindings bindings = new SimpleBindings();
  bindings.put("logger", logger);
  bindings.put("level", level);
  bindings.put("marker", marker);
  bindings.put("message", new SimpleMessage(msg));
  bindings.put("parameters", params);
  bindings.put("throwable", null);
  bindings.putAll(configuration.getProperties());
  bindings.put("substitutor", configuration.getStrSubstitutor());
  final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
  return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

@Override
public Result filter(final Logger logger, final Level level, final Marker marker, final Object msg,
           final Throwable t) {
  final SimpleBindings bindings = new SimpleBindings();
  bindings.put("logger", logger);
  bindings.put("level", level);
  bindings.put("marker", marker);
  bindings.put("message", msg instanceof String ? new SimpleMessage((String)msg) : new ObjectMessage(msg));
  bindings.put("parameters", null);
  bindings.put("throwable", t);
  bindings.putAll(configuration.getProperties());
  bindings.put("substitutor", configuration.getStrSubstitutor());
  final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
  return object == null || !Boolean.TRUE.equals(object) ? onMismatch : onMatch;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

/**
 * Executes the script
 * 
 * @param baseDir
 * @param candidates
 * @return
 */
@SuppressWarnings("unchecked")
public List<PathWithAttributes> selectFilesToDelete(final Path basePath, final List<PathWithAttributes> candidates) {
  final SimpleBindings bindings = new SimpleBindings();
  bindings.put("basePath", basePath);
  bindings.put("pathList", candidates);
  bindings.putAll(configuration.getProperties());
  bindings.put("configuration", configuration);
  bindings.put("substitutor", configuration.getStrSubstitutor());
  bindings.put("statusLogger", LOGGER);
  final Object object = configuration.getScriptManager().execute(script.getName(), bindings);
  return (List<PathWithAttributes>) object;
}

代码示例来源:origin: ops4j/org.ops4j.pax.logging

error("No Configuration defined for RoutingAppender; required for Script element.");
} else {
  final ScriptManager scriptManager = configuration.getScriptManager();
  scriptManager.addScript(defaultRouteScript);
  final Bindings bindings = scriptManager.createBindings(defaultRouteScript);

相关文章