/** * 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); }
/** * 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 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)); }
/** * 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 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); }
/** * Create the DynamicThresholdFilter. * @param key The name of the key to compare. * @param pairs An array of value and Level pairs. * @param levelName The default Level. * @param match The action to perform if a match occurs. * @param mismatch The action to perform if no match occurs. * @return The DynamicThresholdFilter. */ @PluginFactory public static DynamicThresholdFilter createFilter( @PluginAttribute("key") final String key, @PluginElement("Pairs") final KeyValuePair[] pairs, @PluginAttribute("defaultThreshold") final String levelName, @PluginAttribute("onMatch") final String match, @PluginAttribute("onMismatch") final String mismatch) { final Result onMatch = Result.toResult(match); final Result onMismatch = Result.toResult(mismatch); final Map<String, Level> map = new HashMap<String, Level>(); for (final KeyValuePair pair : pairs) { map.put(pair.getKey(), Level.toLevel(pair.getValue())); } final Level level = Level.toLevel(levelName, Level.ERROR); return new DynamicThresholdFilter(key, map, level, onMatch, onMismatch); }
@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 AsyncLoggerConfig(LogManager.ROOT_LOGGER_NAME, appenderRefs, filter, level, additive, properties, config, includeLocation(includeLocation)); }
@PluginFactory public static ListAppender createAppender( @PluginAttribute("name") final String name, @PluginAttribute("entryPerNewLine") final String newLine, @PluginAttribute("raw") final String raw, @PluginElement("Layout") final Layout<? extends Serializable> layout, @PluginElement("Filters") final Filter filter) { if (name == null) { LOGGER.error("No name provided for ListAppender"); return null; } final boolean nl = Boolean.parseBoolean(newLine); final boolean r = Boolean.parseBoolean(raw); return new ListAppender(name, filter, layout, nl, r); }