/** * Create appender cloud watch appender. * * @param name the name * @param awsLogStreamName the aws log stream name * @param awsLogGroupName the aws log group name * @param awsLogStreamFlushPeriodInSeconds the aws log stream flush period in seconds * @param credentialAccessKey the credential access key * @param credentialSecretKey the credential secret key * @param awsLogRegionName the aws log region name * @param layout the layout * @return the cloud watch appender */ @PluginFactory public static CloudWatchAppender createAppender(@PluginAttribute("name") final String name, @PluginAttribute("awsLogStreamName") final String awsLogStreamName, @PluginAttribute("awsLogGroupName") final String awsLogGroupName, @PluginAttribute("awsLogStreamFlushPeriodInSeconds") final String awsLogStreamFlushPeriodInSeconds, @PluginAttribute("credentialAccessKey") final String credentialAccessKey, @PluginAttribute("credentialSecretKey") final String credentialSecretKey, @PluginAttribute("awsLogRegionName") final String awsLogRegionName, @PluginElement("Layout") final Layout<Serializable> layout) { return new CloudWatchAppender( name, awsLogGroupName, awsLogStreamName, awsLogStreamFlushPeriodInSeconds, StringUtils.defaultIfBlank(credentialAccessKey, System.getProperty("AWS_ACCESS_KEY")), StringUtils.defaultIfBlank(credentialSecretKey, System.getProperty("AWS_SECRET_KEY")), StringUtils.defaultIfBlank(awsLogRegionName, System.getProperty("AWS_REGION_NAME")), layout); }
/** * Create a Console Appender. * @param layout The layout to use (required). * @param filter The Filter or null. * @param t The target ("SYSTEM_OUT" or "SYSTEM_ERR"). The default is "SYSTEM_OUT". * @param follow If true will follow changes to the underlying output stream. * @param name The name of the Appender (required). * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise * they are propagated to the caller. * @return The ConsoleAppender. */ @PluginFactory public static ConsoleAppender createAppender( @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filters") final Filter filter, @PluginAttribute("target") final String t, @PluginAttribute("name") final String name, @PluginAttribute("follow") final String follow, @PluginAttribute("ignoreExceptions") final String ignore) { if (name == null) { LOGGER.error("No name provided for ConsoleAppender"); return null; } if (layout == null) { layout = PatternLayout.createLayout(null, null, null, null, null); } final boolean isFollow = Boolean.parseBoolean(follow); final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true); final Target target = t == null ? Target.SYSTEM_OUT : Target.valueOf(t); return new ConsoleAppender(name, layout, filter, getManager(isFollow, target, layout), ignoreExceptions); }
/** * Creates the layout. * * @param locationInfo the location info * @param singleLine the single line * @param htmlSafe the html safe * @param plainContextMap the plain context map * @param charset the charset * @param userFields the user fields * @return the JSON log 4 j 2 layout */ @PluginFactory public static JSONLog4j2Layout createLayout( // @formatter:off @PluginConfiguration final Configuration config, @PluginAttribute("locationInfo") boolean locationInfo, @PluginAttribute("singleLine") boolean singleLine, @PluginAttribute("htmlSafe") boolean htmlSafe, @PluginAttribute("plainContextMap") boolean plainContextMap, @PluginAttribute("charset") Charset charset, @PluginElement("UserFields") final UserField[] userFields // @formatter:on ) { if(charset == null){ charset = Charset.forName("UTF-8"); } LOGGER.debug("Creating JSONLog4j2Layout {}",charset); return new JSONLog4j2Layout(locationInfo, singleLine, htmlSafe, plainContextMap, userFields, charset); }
@PluginFactory public static FluencyConfig createFluencyConfig( @PluginAttribute("ackResponseMode") final boolean ackResponseMode, @PluginAttribute("fileBackupDir") final String fileBackupDir, @PluginAttribute("bufferChunkInitialSize") final int bufferChunkInitialSize, @PluginAttribute("bufferChunkRetentionSize") final int bufferChunkRetentionSize, @PluginAttribute("maxBufferSize") final Long maxBufferSize, @PluginAttribute("waitUntilBufferFlushed") final int waitUntilBufferFlushed, @PluginAttribute("waitUntilFlusherTerminated") final int waitUntilFlusherTerminated, @PluginAttribute("flushIntervalMillis") final int flushIntervalMillis, @PluginAttribute("senderMaxRetryCount") final int senderMaxRetryCount) { FluencyConfig config = new FluencyConfig(); config.ackResponseMode = ackResponseMode; config.fileBackupDir = fileBackupDir; config.bufferChunkInitialSize = bufferChunkInitialSize; config.bufferChunkRetentionSize = bufferChunkRetentionSize; config.maxBufferSize = maxBufferSize; config.waitUntilBufferFlushed = waitUntilBufferFlushed; config.waitUntilFlusherTerminated = waitUntilFlusherTerminated; config.flushIntervalMillis = flushIntervalMillis; config.senderMaxRetryCount = senderMaxRetryCount; return config; }
/** * Factory method. Log4j will parse the configuration and call this factory * method to construct the appender with * the configured attributes. * * @param name Name of appender * @param layout Log layout of appender * @param filter Filter for appender * @return The TextAreaAppender */ @PluginFactory public static TextAreaAppender createAppender( @PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter) { if (name == null) { LOGGER.error("No name provided for TextAreaAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new TextAreaAppender(name, filter, layout, true); }
@PluginFactory public static TerminalConsoleAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Filters") Filter filter, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginAttribute("ignoreExceptions") String ignore) { if (name == null) { LOGGER.error("No name provided for TerminalConsoleAppender"); return null; } if (layout == null) { layout = PatternLayout.createLayout(null, null, null, null, null); } boolean ignoreExceptions = parseBoolean(ignore, true); // This is handled by jline System.setProperty("log4j.skipJansi", "true"); return new TerminalConsoleAppender(name, filter, layout, ignoreExceptions); }
@PluginFactory public static ReportPortalLog4j2Appender createAppender(@PluginAttribute("name") String name, @PluginElement("filter") Filter filter, @PluginElement("layout") Layout<? extends Serializable> layout) { if (name == null) { LOGGER.error("No name provided for ReportPortalLog4j2Appender"); return null; } if (layout == null) { LOGGER.error("No layout provided for ReportPortalLog4j2Appender"); return null; } return new ReportPortalLog4j2Appender(name, filter, layout); }
@PluginFactory public static ConsoleLogAppender createAppender(@PluginAttribute("name") final String name, @PluginAttribute("ignoreExceptions") final String ignore, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filters") final Filter filter, @PluginAttribute("target") String target) { final boolean ignoreExceptions = Boolean.parseBoolean(ignore); if (name == null) { ConsoleLogAppender.LOGGER.error("No name provided for ConsoleLogAppender"); return null; } if (target == null) { target = name; } ConsoleLogAppender.QUEUE_LOCK.writeLock().lock(); BlockingQueue<String> queue = ConsoleLogAppender.QUEUES.get(target); if (queue == null) { queue = new LinkedBlockingQueue<>(); ConsoleLogAppender.QUEUES.put(target, queue); } ConsoleLogAppender.QUEUE_LOCK.writeLock().unlock(); if (layout == null) { layout = PatternLayout.createLayout(null, null, null, null, true, !Nukkit.useConsole, null, null); } return new ConsoleLogAppender(name, filter, layout, ignoreExceptions, queue); }
@PluginFactory public static WorkspaceLogAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter) { if (name == null) { LOGGER.error("No name provided for WorkspaceLogAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new WorkspaceLogAppender(name, filter, layout, true); }
@PluginFactory public static SlackAppender createAppender( @PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter, @PluginAttribute("webhookUrl") URL webhookUrl, @PluginAttribute("channel") String channel, @PluginAttribute(value = "username", defaultString = "Blazkowicz") String username, @PluginAttribute(value = "meltdownProtection", defaultBoolean = true) boolean meltdownProtection, @PluginAttribute(value = "similarMessageSize", defaultInt = 50) int similarMessageSize, @PluginAttribute(value = "timeBetweenSimilarLogsMs", defaultInt = 60000) int timeBetweenSimilarLogsMs, @PluginAttribute(value = "packagesToMute", defaultString = "") String packagesToMute, @PluginAttribute(value = "httpClientImpl", defaultString = "") String httpClientImpl) { if (name == null) { LOGGER.error("No name provided for MyCustomAppenderImpl"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } Client client = findClientImpl(httpClientImpl); SlackAppender slackAppender = new SlackAppender(name, filter, layout, webhookUrl, username, channel, meltdownProtection, similarMessageSize, timeBetweenSimilarLogsMs, client); slackAppender.setPackagesToMute(packagesToMute); return slackAppender; }
@PluginFactory public static DebuggerAppender createAppender(@PluginAttribute("name") String name, @PluginElement("Layout") Layout<?> layout, @PluginElement("Filters") Filter filter, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions) { if (name == null) { LOGGER.error("No name provided for JTextAreaAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new DebuggerAppender(name, layout, filter, ignoreExceptions); }
/** * A custom appender needs to declare a factory method annotated with `@PluginFactory`. * Log4j will parse the configuration and call this factory method to construct an appender instance with * the configured attributes. * * @param name - the logger name * @param layout - the layout * @param filter - the filter * @param otherAttribute - other attributes * @return a text area logger */ @PluginFactory public static TextAreaLogger createAppender( @PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter, @PluginAttribute("otherAttribute") String otherAttribute) { if (name == null) { LOGGER.error("No name provided for MyCustomAppenderImpl"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new TextAreaLogger(name, filter, layout, true); }
@PluginFactory public static MongoFXMessageAppender createAppender(@PluginAttribute("name") String name, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filters") Filter filter) { if (name == null) { LOGGER.error("No name provided for StubAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } return new MongoFXMessageAppender(name, filter, layout, ignoreExceptions); }
/** * Factory method for the appender * * @param name The Appender name * @param filter The Filter to associate with the Appender * @param apiUrl API URL * @param apiKey API Key * @param application Application name * @param environment Environment * @param skipJson Mark messages w/ JSON w/ #SKIPJSON * @param maskEnabled Mask Enabled * @param masks Masks * @return StackifyLogAppender */ @PluginFactory public static StackifyLogAppender createAppender(@PluginAttribute("name") final String name, @PluginElement("filters") final Filter filter, @PluginAttribute("apiUrl") final String apiUrl, @PluginAttribute("apiKey") final String apiKey, @PluginAttribute("application") final String application, @PluginAttribute("environment") final String environment, @PluginAttribute("skipJson") final String skipJson, @PluginAttribute("maskEnabled") final String maskEnabled, @PluginElement("mask") final Mask[] masks) { return new StackifyLogAppender(name, filter, apiUrl, apiKey, application, environment, skipJson == null || Boolean.parseBoolean(skipJson), maskEnabled == null || Boolean.parseBoolean(maskEnabled), masks); }
@PluginFactory public static MemoryAppender createAppender( @PluginAttribute("name") String name, @PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filter") final Filter filter, @PluginAttribute("numberOfLines") String numberOfLines) { if (name == null) { LOGGER.error("No name provided for MemoryAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } if (numberOfLines != null) { logsize = Integer.valueOf(numberOfLines); } return new MemoryAppender(name, filter, layout, true); }
@PluginFactory public static ConsoleWindowAppender createAppender(@PluginAttribute("name") String name, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, @PluginElement("Layout") Layout layout, @PluginElement("Filters") Filter filter) { if (name == null) { LOGGER.error("No name provided for StubAppender"); return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } //noinspection unchecked return new ConsoleWindowAppender(name, filter, layout, ignoreExceptions); }
@PluginFactory public static JesterJAppender createAppender(@PluginAttribute("name") String name, @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, @PluginElement("Layout") Layout layout, @PluginElement("Filters") Filter filter) { if (name == null) { LOGGER.error("No name provided for JesterJAppender"); return null; } manager = createManager(); if (manager == null) { return null; } if (layout == null) { layout = PatternLayout.createDefaultLayout(); } cassandra.addStatement(FTI_INSERT_Q, INSERT_FTI); cassandra.addStatement(REG_INSERT_Q, INSERT_REG); return new JesterJAppender(name, layout, filter, manager, ignoreExceptions); }
/** * Factory method called by the log4j initialization framework * <p> * @param name * @param ignoreExceptions * @param layout * @param filter * @return */ @PluginFactory public static SdiReportAppender createAppender( @PluginAttribute( "name" ) String name, @PluginAttribute( "ignoreExceptions" ) boolean ignoreExceptions, @PluginElement( "Layout" ) Layout<?> layout, @PluginElement( "Filters" ) Filter filter ) { if ( name == null ) { LOGGER.error( "No name provided for SdiReportAppender" ); return null; } return new SdiReportAppender( name, null, null ); }
@PluginFactory public static TerminalConsoleAppender createAppender( @PluginElement("Layout") @Nullable Layout<? extends Serializable> layout, @PluginAttribute("name") String name, @PluginElement("Filter") Filter filter, @PluginAttribute(value = "ignoreExceptions", defaultBoolean = true) boolean ignoreExceptions) { if (name == null) { LOGGER.error("No name provided for TerminalConsoleAppender"); return null; } if (layout == null) { layout = PatternLayout.createLayout(null, null, null, null, null, false, false, null, null); } // This is handled by jline System.setProperty("log4j.skipJansi", "true"); return new TerminalConsoleAppender(name, filter, layout, ignoreExceptions); }
@PluginFactory public static JLineConsoleAppender createAppender(@PluginElement("Layout") Layout<? extends Serializable> layout, @PluginElement("Filters") final Filter filter, @PluginAttribute("target") final String t, @PluginAttribute("name") final String name, @PluginAttribute("follow") final String follow, @PluginAttribute("ignoreExceptions") final String ignore) { if (name == null) { LOGGER.error("No name provided for ConsoleAppender"); return null; } if (layout == null) { layout = PatternLayout.newBuilder().build(); } final boolean isFollow = Boolean.parseBoolean(follow); final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true); final Target target = t == null ? Target.SYSTEM_OUT : Target.valueOf(t); FactoryData data = new FactoryData(getStream(isFollow, target), layout); return new JLineConsoleAppender(name, layout, filter, getManager(isFollow, target, data), getHeldManager(isFollow, target, data), ignoreExceptions); }
/** * Create an Agent. * @param host The host name. * @param port The port number. * @return The Agent. */ @PluginFactory public static Agent createAgent(@PluginAttribute("host") String host, @PluginAttribute("port") final String port) { if (host == null) { host = DEFAULT_HOST; } int portNum; try { portNum = Integers.parseInt(port, DEFAULT_PORT); } catch (final Exception ex) { LOGGER.error("Error parsing port number " + port, ex); return null; } return new Agent(host, portNum); }
/** * Create an Appender reference. * @param ref The name of the Appender. * @param levelName The Level to filter against. * @param filter The filter(s) to use. * @return The name of the Appender. */ @PluginFactory public static AppenderRef createAppenderRef( @PluginAttribute("ref") final String ref, @PluginAttribute("level") final String levelName, @PluginElement("Filters") final Filter filter) { if (ref == null) { LOGGER.error("Appender references must contain a reference"); return null; } Level level = null; if (levelName != null) { level = Level.toLevel(levelName, null); if (level == null) { LOGGER.error("Invalid level " + levelName + " on Appender reference " + ref); } } return new AppenderRef(ref, level, filter); }
@PluginFactory public static LoggerConfig createLogger( @PluginAttribute("additivity") final String additivity, @PluginAttribute("level") final String levelName, @PluginAttribute("includeLocation") final String includeLocation, @PluginElement("AppenderRef") final AppenderRef[] refs, @PluginElement("Properties") final Property[] properties, @PluginConfiguration final Configuration config, @PluginElement("Filters") final Filter filter) { final List<AppenderRef> appenderRefs = Arrays.asList(refs); Level level; try { level = Level.toLevel(levelName, Level.ERROR); } catch (final Exception ex) { LOGGER.error( "Invalid Log level specified: {}. Defaulting to Error", levelName); level = Level.ERROR; } final boolean additive = Booleans.parseBoolean(additivity, true); return new LoggerConfig(LogManager.ROOT_LOGGER_NAME, appenderRefs, filter, level, additive, properties, config, includeLocation(includeLocation)); }
/** * 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. */ // TODO Consider refactoring to use AbstractFilter.AbstractFilterBuilder @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); }
/** * Create a RewriteAppender. * @param name The name of the Appender. * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise * they are propagated to the caller. * @param appenderRefs An array of Appender names to call. * @param config The Configuration. * @param rewritePolicy The policy to use to modify the event. * @param filter A Filter to filter events. * @return The created RewriteAppender. */ @PluginFactory public static RewriteAppender createAppender( @PluginAttribute("name") final String name, @PluginAttribute("ignoreExceptions") final String ignore, @PluginElement("AppenderRef") final AppenderRef[] appenderRefs, @PluginConfiguration final Configuration config, @PluginElement("RewritePolicy") final RewritePolicy rewritePolicy, @PluginElement("Filter") final Filter filter) { final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true); if (name == null) { LOGGER.error("No name provided for RewriteAppender"); return null; } if (appenderRefs == null) { LOGGER.error("No appender references defined for RewriteAppender"); return null; } return new RewriteAppender(name, filter, ignoreExceptions, appenderRefs, rewritePolicy, config); }
/** * Create the Route. * @param appenderRef The Appender reference. * @param key The key. * @param node The Node. * @return A Route. */ @PluginFactory public static Route createRoute( @PluginAttribute("ref") final String appenderRef, @PluginAttribute("key") final String key, @PluginNode final Node node) { if (node != null && node.hasChildren()) { for (final Node child : node.getChildren()) { } if (appenderRef != null) { LOGGER.error("A route cannot be configured with an appender reference and an appender definition"); return null; } } else { if (appenderRef == null) { LOGGER.error("A route must specify an appender reference or an appender definition"); return null; } } return new Route(node, appenderRef, key); }
/** * Create a RoutingAppender. * @param name The name of the Appender. * @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise * they are propagated to the caller. * @param routes The routing definitions. * @param config The Configuration (automatically added by the Configuration). * @param rewritePolicy A RewritePolicy, if any. * @param filter A Filter to restrict events processed by the Appender or null. * @return The RoutingAppender */ @PluginFactory public static RoutingAppender createAppender( @PluginAttribute("name") final String name, @PluginAttribute("ignoreExceptions") final String ignore, @PluginElement("Routes") final Routes routes, @PluginConfiguration final Configuration config, @PluginElement("RewritePolicy") final RewritePolicy rewritePolicy, @PluginElement("Filters") final Filter filter) { final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true); if (name == null) { LOGGER.error("No name provided for RoutingAppender"); return null; } if (routes == null) { LOGGER.error("No routes defined for RoutingAppender"); return null; } return new RoutingAppender(name, filter, ignoreExceptions, routes, rewritePolicy, config); }
/** * Factory method for creating a connection source within the plugin manager. * * @param jndiName The full JNDI path where the data source is bound. Should start with java:/comp/env or * environment-equivalent. * @return the created connection source. */ @PluginFactory public static DataSourceConnectionSource createConnectionSource(@PluginAttribute("jndiName") final String jndiName) { if (Strings.isEmpty(jndiName)) { LOGGER.error("No JNDI name provided."); return null; } try { final InitialContext context = new InitialContext(); final DataSource dataSource = (DataSource) context.lookup(jndiName); if (dataSource == null) { LOGGER.error("No data source found with JNDI name [" + jndiName + "]."); return null; } return new DataSourceConnectionSource(jndiName, dataSource); } catch (final NamingException e) { LOGGER.error(e.getMessage(), e); return null; } }