/** * Create a default DEBUG logging fraction. * * @return The fully-configured fraction. */ public static LoggingFraction createDebugLoggingFraction() { return createDefaultLoggingFraction(Level.DEBUG); }
/** * Add a CustomFormatter to this logger * * @param name the name of the formatter * @param module the module that the logging handler depends on * @param className the logging handler class to be used * @return This fraction. */ public LoggingFraction customFormatter(String name, String module, String className) { return customFormatter(name, module, className, null); }
/** * Create a default logging fraction for the specified level. * * @return The fully-configured fraction. */ public static LoggingFraction createDefaultLoggingFraction(Level level) { return new LoggingFraction() .defaultColorFormatter() .consoleHandler(level, COLOR_PATTERN) .rootLogger(level, CONSOLE); }
/** * Create a default logging fraction for the specified level. * * @return The fully-configured fraction. */ public static LoggingFraction createDefaultLoggingFraction(Level level) { return new LoggingFraction().applyDefaults(level); }
@Override public LoggingFraction defaultFraction() { String prop = System.getProperty(LoggingProperties.LOGGING); if (prop != null) { prop = prop.trim().toLowerCase(); if (prop.equals("debug")) { return LoggingFraction.createDebugLoggingFraction(); } else if (prop.equals("trace")) { return LoggingFraction.createTraceLoggingFraction(); } } return LoggingFraction.createDefaultLoggingFraction(); }
/** * Get the list of CustomFormatter configurations * * @return The list of custom formatters */ public List<CustomFormatter> customFormatters() { return subresources().customFormatters(); }
@Override public void customize() { if (logstash.enabled()) { Properties handlerProps = new Properties(); handlerProps.put("hostname", this.logstash.hostname()); handlerProps.put("port", "" + this.logstash.port()); final CustomHandler<?> logstashHandler = new CustomHandler<>("logstash-handler") .module("org.jboss.logmanager.ext") .attributeClass("org.jboss.logmanager.ext.handlers.SocketHandler") .namedFormatter("logstash") .properties(handlerProps) .level(this.logstash.level()); this.logging .customFormatter("logstash", "org.jboss.logmanager.ext", "org.jboss.logmanager.ext.formatters.LogstashFormatter", this.logstash.formatterProperties()) .customHandler(logstashHandler) .subresources() .rootLogger() .handler(logstashHandler.getKey()); } } }
@Override public void initialize(Container.InitContext initContext) { final CustomHandler<?> logstashHandler = new CustomHandler<>("logstash-handler") .module("org.jboss.logmanager.ext") .attributeClass("org.jboss.logmanager.ext.handlers.SocketHandler") .namedFormatter("logstash") .properties(handlerProperties); initContext.fraction(new LoggingFraction() .customFormatter("logstash", "org.jboss.logmanager.ext", "org.jboss.logmanager.ext.formatters.LogstashFormatter", this.formatterProperties) .customHandler(logstashHandler) .rootLogger(this.level, logstashHandler.getKey())); }
public static LoggingFraction loggingFraction() { String prop = System.getProperty(LoggingProperties.LOGGING); LoggingFraction fraction = null; if (prop != null) { prop = prop.trim().toLowerCase(); if (prop.equals("debug")) { fraction = LoggingFraction.createDebugLoggingFraction(); } else if (prop.equals("trace")) { fraction = LoggingFraction.createTraceLoggingFraction(); } } if (fraction == null) { fraction = LoggingFraction.createDefaultLoggingFraction(); } fraction.logger(new Logger("org.openshift.ping") .level(Level.TRACE)); fraction.logger(new Logger("org.jgroups.protocols.openshift") .level(Level.TRACE)); return fraction; }
public LoggingFraction applyDefaults(Level level) { defaultColorFormatter() .consoleHandler(Level.ALL, COLOR_PATTERN) .rootLogger(level, CONSOLE); Properties allProps = System.getProperties(); for (String name : allProps.stringPropertyNames()) { if (isSimpleLoggerName(name)) { String logger = name.substring((LoggingProperties.LOGGING + ".").length()); try { Level loggerLevel = Level.valueOf(allProps.getProperty(name).trim().toUpperCase()); logger(logger, (l) -> { l.level(loggerLevel); l.category(logger); }); } catch (IllegalArgumentException e) { // apparently wasn't a logging category+level, ignore. } } } return this; }
/** * Add a CustomHandler to this logger * * @param name the name of the handler * @param module the module that the handler uses * @param className the handler class name * @param properties properties for the handler * @param formatter a pattern string for the formatter * @return this fraction */ public LoggingFraction customHandler(String name, String module, String className, Properties properties, String formatter) { Map<Object, Object> handlerProperties = new HashMap<>(); final Enumeration<?> names = properties.propertyNames(); while (names.hasMoreElements()) { final String nextElement = (String) names.nextElement(); handlerProperties.put(nextElement, properties.getProperty(nextElement)); } customHandler(new CustomHandler(name) .module(module) .attributeClass(className) .formatter(formatter) .properties(handlerProperties)); return this; }
/** * Add a root logger to this fraction * @param level the log level * @return this fraction */ public LoggingFraction rootLogger(String level) { return rootLogger(level, null); }
private void apply(LevelNode node, LoggingFraction fraction) { if (!node.getName().equals("")) { fraction.logger(node.getName(), (l) -> { l.level(Level.valueOf(node.getLevel().toString())); }); } for (LevelNode each : node.getChildren()) { apply(each, fraction); } }
/** * Add a ConsoleHandler to the list of handlers for this logger. * * @param level The logging level * @param formatter A pattern string for the console's formatter * @return This fraction */ public LoggingFraction consoleHandler(Level level, String formatter) { consoleHandler(new ConsoleHandler(CONSOLE) .level(level) .namedFormatter(formatter)); return this; }
/** * Get the list of PatternFormatter configurations * * @return The list of formatters */ public List<PatternFormatter> patternFormatters() { return subresources().patternFormatters(); }
@Override public void customize() { if (logstash.enabled()) { Properties handlerProps = new Properties(); handlerProps.put("hostname", this.logstash.hostname()); handlerProps.put("port", "" + this.logstash.port()); final CustomHandler<?> logstashHandler = new CustomHandler<>("logstash-handler") .module("org.jboss.logmanager.ext") .attributeClass("org.jboss.logmanager.ext.handlers.SocketHandler") .namedFormatter("logstash") .properties(handlerProps) .level(this.logstash.level()); this.logging .customFormatter("logstash", "org.jboss.logmanager.ext", "org.jboss.logmanager.ext.formatters.LogstashFormatter", this.logstash.formatterProperties()) .customHandler(logstashHandler) .subresources() .rootLogger() .handler(logstashHandler.getKey()); } } }
/** * Add a CustomHandler to this logger * * @param name the name of the handler * @param module the module that the handler uses * @param className the handler class name * @param properties properties for the handler * @param formatter a pattern string for the formatter * @return this fraction */ public LoggingFraction customHandler(String name, String module, String className, Properties properties, String formatter) { Map handlerProperties = new HashMap<>(); final Enumeration<?> names = properties.propertyNames(); while (names.hasMoreElements()) { final String nextElement = (String) names.nextElement(); handlerProperties.put(nextElement, properties.getProperty(nextElement)); } customHandler( new CustomHandler(name) .module(module) .attributeClass(className) .formatter(formatter) .properties(handlerProperties) ); return this; }
/** * Add a root logger to this fraction * @param level the log level * @param handlers a list of handlers * @return this fraction */ public LoggingFraction rootLogger(String level, String... handlers) { rootLogger( new RootLogger().level(level) .handlers(new ArrayList<>(Arrays.asList(handlers))) ); return this; }
private void apply(LevelNode node) { if (!node.getName().equals("")) { this.fraction.logger(node.getName(), (l) -> { l.level(Level.valueOf(node.getLevel().toString())); }); } for (LevelNode each : node.getChildren()) { apply(each); } } }
/** * Add a ConsoleHandler to the list of handlers for this logger. * * @param level The logging level * @param formatter A pattern string for the console's formatter * @return This fraction */ public LoggingFraction consoleHandler(Level level, String formatter) { consoleHandler(new ConsoleHandler(CONSOLE) .level(level) .namedFormatter(formatter)); return this; }