ch.qos.logback.core.util.OptionHelper Java Examples
The following examples show how to use
ch.qos.logback.core.util.OptionHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Minister.java From GOAi with GNU Affero General Public License v3.0 | 6 votes |
/** * 初始化日志 */ private Logger initLog(Integer id) { // 实例化log,每个实例存放地方不一致 ch.qos.logback.classic.Logger logger = ((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(this.secretary.strategyName + "-" + id)); LoggerContext context = logger.getLoggerContext(); TimeBasedRollingPolicy<ILoggingEvent> policy = new TimeBasedRollingPolicy<>(); policy.setFileNamePattern(OptionHelper.substVars( "logs/past/" + id + "/%d{yyyy-MM-dd}.log.gz", context)); policy.setMaxHistory(31); policy.setContext(context); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(context); encoder.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %5level - [%thread] %logger : %msg%n"); RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>(); appender.setContext(context); appender.setName(this.secretary.strategyName + "-" + id); appender.setFile(OptionHelper.substVars("logs/" + id + "/log.log", context)); appender.setAppend(true); // 同一文件多输入完整检查 appender.setPrudent(false); appender.setRollingPolicy(policy); appender.setEncoder(encoder); policy.setParent(appender); policy.start(); encoder.start(); appender.start(); logger.setLevel(Level.INFO); // 终端输出 logger.setAdditive(true); logger.addAppender(appender); return logger; }
Example #2
Source File: LogConfigurator.java From rdf4j with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * * @param appenderName * @return log reader */ public LogReader getLogReader(String appenderName) { if (appenderName != null) { String className = logReaderClassNames.get(appenderName); if (className != null) { try { LogReader logReader = (LogReader) OptionHelper.instantiateByClassName(className, org.eclipse.rdf4j.common.logging.LogReader.class, context); logReader.setAppender(appenders.get(appenderName)); return logReader; } catch (Exception ex) { System.err.println("Could not create logreader of type " + className + " !"); ex.printStackTrace(); } } else { System.err.println("Could not find logreader for appender " + appenderName + " !"); } } return null; }
Example #3
Source File: SpacedLogbackSystem.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
private Appender<ILoggingEvent> consoleAppender() { ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<>(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); String logPattern = this.patterns.getProperty("logging.pattern.console", FILE_LOG_PATTERN); encoder.setPattern(OptionHelper.substVars(logPattern, context)); encoder.setCharset(DEFAULT_CHARSET); appender.setEncoder(encoder); start(encoder); appender("console", appender); return appender; }
Example #4
Source File: LogbackMDCPatternConverter.java From skywalking with Apache License 2.0 | 5 votes |
@Override public void start() { super.start(); String[] key = OptionHelper.extractDefaultReplacement(getFirstOption()); if (null != key && key.length > 0 && CONVERT_KEY.equals(key[0])) { convert4TID = true; } }
Example #5
Source File: LogbackAccessJoranConfigurator.java From logback-access-spring-boot-starter with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void begin(InterpretationContext ic, String name, Attributes attributes) throws ActionException { depth++; if (depth != 1) { return; } String profiles = OptionHelper.substVars(attributes.getValue(NAME_ATTRIBUTE), ic, context); String[] normalizedProfiles = StringUtils.commaDelimitedListToStringArray(profiles); normalizedProfiles = StringUtils.trimArrayElements(normalizedProfiles); accepts = normalizedProfiles.length > 0 && environment.acceptsProfiles(normalizedProfiles); ic.addInPlayListener(this); }
Example #6
Source File: KonkerStatusListenerConfigHelper.java From konker-platform with Apache License 2.0 | 5 votes |
private static StatusListener createListenerPerClassName(KonkerLoggerContext loggerContext, String listenerClass) { try { return (StatusListener)OptionHelper.instantiateByClassName(listenerClass, StatusListener.class, loggerContext); } catch (Exception var3) { var3.printStackTrace(); return null; } }
Example #7
Source File: KonkerStatusListenerConfigHelper.java From konker-platform with Apache License 2.0 | 5 votes |
static void installIfAsked(KonkerLoggerContext loggerContext) { String slClass = OptionHelper.getSystemProperty("logback.statusListenerClass"); if(!OptionHelper.isEmpty(slClass)) { addStatusListener(loggerContext, slClass); } }
Example #8
Source File: KonkerSelectorStaticBinder.java From konker-platform with Apache License 2.0 | 5 votes |
public void init(KonkerLoggerContext defaultLoggerContext, Object key) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { if(this.key == null) { this.key = key; } else if(this.key != key) { throw new IllegalAccessException("Only certain classes can access this method."); } String contextSelectorStr = OptionHelper.getSystemProperty("logback.ContextSelector"); if(contextSelectorStr == null) { this.contextSelector = new KonkerDefaultContextSelector(defaultLoggerContext); } else { this.contextSelector = dynamicalContextSelector(defaultLoggerContext, contextSelectorStr); } }
Example #9
Source File: SpringProfileAction.java From super-cloudops with Apache License 2.0 | 5 votes |
private boolean acceptsProfiles(InterpretationContext ic, Attributes attributes) { String[] profileNames = StringUtils .trimArrayElements(StringUtils.commaDelimitedListToStringArray(attributes.getValue(NAME_ATTRIBUTE))); if (profileNames.length != 0) { for (String profileName : profileNames) { OptionHelper.substVars(profileName, ic, this.context); } return this.environment != null && this.environment.acceptsProfiles(profileNames); } return false; }
Example #10
Source File: EnhancedLogbackConfiguration.java From super-cloudops with Apache License 2.0 | 5 votes |
private Appender<ILoggingEvent> fileAppender(LogbackConfigurator config, String logFile) { RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<ILoggingEvent>(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); String logPattern = this.logging.getProperty("pattern.file", FILE_LOG_PATTERN); encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext())); appender.setEncoder(encoder); config.start(encoder); appender.setFile(logFile); setRollingPolicy(appender, config, logFile); setMaxFileSize(appender, config); config.appender("FILE", appender); return appender; }
Example #11
Source File: EnhancedLogbackConfiguration.java From super-cloudops with Apache License 2.0 | 5 votes |
private Appender<ILoggingEvent> consoleAppender(LogbackConfigurator config) { ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); String logPattern = this.logging.getProperty("pattern.console", CONSOLE_LOG_PATTERN); encoder.setPattern(OptionHelper.substVars(logPattern, config.getContext())); encoder.setCharset(UTF8); config.start(encoder); appender.setEncoder(encoder); config.appender("CONSOLE", appender); return appender; }
Example #12
Source File: SpringPropertyAction.java From super-cloudops with Apache License 2.0 | 5 votes |
@Override public void begin(InterpretationContext ic, String elementName, Attributes attributes) throws ActionException { String name = attributes.getValue(NAME_ATTRIBUTE); String source = attributes.getValue(SOURCE_ATTRIBUTE); Scope scope = ActionUtil.stringToScope(attributes.getValue(SCOPE_ATTRIBUTE)); String defaultValue = attributes.getValue(DEFAULT_VALUE_ATTRIBUTE); if (OptionHelper.isEmpty(name) || OptionHelper.isEmpty(source)) { addError("The \"name\" and \"source\" attributes of <springProperty> must be set"); } ActionUtil.setProperty(ic, name, getValue(source, defaultValue), scope); }
Example #13
Source File: DefaultLogbackReInitializer.java From sofa-common-tools with Apache License 2.0 | 5 votes |
private ConsoleAppender consoleAppender(LoggerContext loggerContext, Properties properties) { SystemPropertiesGetter propertiesGetter = new SystemPropertiesGetter(properties); ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); String logPattern = propertiesGetter.getProperty( SOFA_MIDDLEWARE_LOG_CONSOLE_LOGBACK_PATTERN, SOFA_MIDDLEWARE_LOG_CONSOLE_LOGBACK_PATTERN_DEFAULT); encoder.setPattern(OptionHelper.substVars(logPattern, loggerContext)); encoder.setContext(loggerContext); encoder.start(); appender.setEncoder(encoder); appender.setName("CONSOLE"); appender.start(); return appender; }
Example #14
Source File: SpacedLogbackSystem.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
protected Appender<ILoggingEvent> fileAppender(Space space) { RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); String logPattern = this.patterns.getProperty("logging.pattern.file", FILE_LOG_PATTERN); encoder.setPattern(OptionHelper.substVars(logPattern, context)); encoder.setCharset(DEFAULT_CHARSET); appender.setEncoder(encoder); start(encoder); // parse path and file // first consider spec.path, second, default_spec.path, third logging.path LogFile logFile = LogFile.get(patterns); Properties defaultProperties = new Properties(); if (logFile != null) { logFile.applyTo(defaultProperties); } String path = space.getSpec().getPath() != null ? space.getSpec().getPath() : space.getDefaultSpec().getPath() != null ? space.getDefaultSpec().getPath() : defaultProperties.contains(LoggingSystemProperties.LOG_PATH) ? defaultProperties.getProperty(LoggingSystemProperties.LOG_PATH) : DEFAULT_PATH; path = patterns.resolvePlaceholders(path); String file = space.getSpec().getFile() != null ? fileName(space.getSpec().getFile()) : fileName(space.getName()); file = patterns.resolvePlaceholders(file); appender.setFile(path + "/" + file); setRollingPolicy(appender, space, path, file); // threshold config ThresholdFilter thresholdFilter = new ThresholdFilter(); if (space.getSpec().getThreshold() != null) { thresholdFilter.setLevel(space.getSpec().getThreshold()); start(thresholdFilter); appender.addFilter(thresholdFilter); } appender("SPACE-" + space.getName(), appender); return appender; }
Example #15
Source File: LogAppender.java From nuls-v2 with MIT License | 4 votes |
/** * 通过传入的名字和级别,动态设置appender * * @param fileName * @return */ @SuppressWarnings("unchecked") public static RollingFileAppender getAppender(String fileName, Level level){ String rootPath = PROJECT_PATH; if(!rootPath.endsWith(File.separator)){ rootPath += File.separator; } if(fileName.startsWith(File.separator)){ fileName = fileName.substring(1); } LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory(); RollingFileAppender appender = new RollingFileAppender(); /*设置上下文,每个logger都关联到logger上下文,默认上下文名称为default。 但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改。*/ appender.setContext(context); //这里设置级别过滤器 LogFilter levelController = new LogFilter(); ThresholdFilter levelFilter = levelController.getThresholdFilter(level); levelFilter.start(); appender.addFilter(levelFilter); //设置文件名 appender.setFile(OptionHelper.substVars(rootPath+fileName + ".log",context)); appender.setAppend(true); appender.setPrudent(false); //设置文件创建时间及大小的类 SizeAndTimeBasedRollingPolicy policy = new SizeAndTimeBasedRollingPolicy(); //文件名格式 String fp = OptionHelper.substVars(rootPath+ fileName + ".%d{yyyy-MM-dd}.%i.zip",context); //最大日志文件大小 policy.setMaxFileSize(FileSize.valueOf("100MB")); //设置文件名模式 policy.setFileNamePattern(fp); //设置保存最近3天的日志 policy.setMaxHistory(3); //总大小限制 policy.setContext(context); policy.setTotalSizeCap(FileSize.valueOf("1GB")); //设置父节点是appender policy.setParent(appender); //设置上下文,每个logger都关联到logger上下文,默认上下文名称为default。 //但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改。 policy.start(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); //设置上下文,每个logger都关联到logger上下文,默认上下文名称为default。 //但可以使用<contextName>设置成其他名字,用于区分不同应用程序的记录。一旦设置,不能修改。 encoder.setContext(context); //设置格式 /*encoder.setPattern("%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%t] %replace(%caller{1}){'\\t|Caller.{1}0|\\r\\n', ''} - %msg%n");*/ encoder.setPattern("%d %p [%t] - %msg%n"); encoder.start(); //加入下面两个节点 appender.setRollingPolicy(policy); appender.setEncoder(encoder); appender.start(); return appender; }
Example #16
Source File: SMTPAppenderBase.java From lemon with Apache License 2.0 | 4 votes |
private Session buildSessionFromProperties() { Properties props = new Properties(OptionHelper.getSystemProperties()); if (smtpHost != null) { props.put("mail.smtp.host", smtpHost); } props.put("mail.smtp.port", Integer.toString(smtpPort)); if (localhost != null) { props.put("mail.smtp.localhost", localhost); } LoginAuthenticator loginAuthenticator = null; if (username != null) { loginAuthenticator = new LoginAuthenticator(username, password); props.put("mail.smtp.auth", "true"); } if (isSTARTTLS() && isSSL()) { addError("Both SSL and StartTLS cannot be enabled simultaneously"); } else { if (isSTARTTLS()) { // see also http://jira.qos.ch/browse/LBCORE-225 props.put("mail.smtp.starttls.enable", "true"); } if (isSSL()) { String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; props.put("mail.smtp.socketFactory.port", Integer.toString(smtpPort)); props.put("mail.smtp.socketFactory.class", SSL_FACTORY); props.put("mail.smtp.socketFactory.fallback", "true"); props.put("mail.smtp.ssl.enable", "true"); props.put("mail.transport.protocol", "smtps"); props.put("mail.smtps.ssl.trust", "*"); } } // props.put("mail.debug", "true"); return Session.getInstance(props, loginAuthenticator); }
Example #17
Source File: LogbackUtil.java From summerframework with Apache License 2.0 | 2 votes |
public RollingFileAppender getAppender(String name, Level level, String fileName) { DateFormat format = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.SIMPLIFIED_CHINESE); LoggerContext context = (LoggerContext)LoggerFactory.getILoggerFactory(); RollingFileAppender appender = new RollingFileAppender(); LevelFilter levelFilter = getLevelFilter(level); levelFilter.start(); appender.addFilter(levelFilter); appender.setContext(context); appender.setName(name); appender.setFile(OptionHelper.substVars("/opt/app/logs/" + fileName + ".json", context)); appender.setAppend(true); appender.setPrudent(false); SizeAndTimeBasedRollingPolicy policy = new SizeAndTimeBasedRollingPolicy(); String fp = OptionHelper.substVars( "/opt/app/logs/histroy" + fileName + format.format(new Date()) + "/.%d{yyyy-MM-dd}.%i.json", context); policy.setMaxFileSize(FileSize.valueOf("128MB")); policy.setFileNamePattern(fp); policy.setMaxHistory(7); policy.setTotalSizeCap(FileSize.valueOf("32GB")); policy.setParent(appender); policy.setContext(context); policy.start(); PatternLayoutEncoder encoder = new PatternLayoutEncoder(); encoder.setContext(context); encoder.setPattern("%d %p (%file:%line\\)- %m%n"); encoder.start(); appender.setRollingPolicy(policy); appender.setEncoder(encoder); appender.start(); return appender; }