public void start() { int errorCount = 0; String facilityStr = getFirstOption(); if (facilityStr == null) { addError("was expecting a facility string as an option"); return; } facility = SyslogAppenderBase.facilityStringToint(facilityStr); localHostName = getLocalHostname(); try { // hours should be in 0-23, see also http://jira.qos.ch/browse/LBCLASSIC-48 simpleMonthFormat = new SimpleDateFormat("MMM", Locale.US); simpleTimeFormat = new SimpleDateFormat("HH:mm:ss", Locale.US); } catch (IllegalArgumentException e) { addError("Could not instantiate SimpleDateFormat", e); errorCount++; } if(errorCount == 0) { super.start(); } }
public void start() { int errorCount = 0; final String facilityStr = getFirstOption(); if (facilityStr == null) { addError("was expecting a facility string as an option"); return; } facility = SyslogAppenderBase.facilityStringToint(facilityStr); localHostName = getLocalHostname(); try { isoFormatter = new DateTimeFormatterBuilder() .appendPattern("yyyy-MM-dd'T'HH:mm:ss.SSS") .appendTimeZoneOffset("Z", true, 2, 4) .toFormatter(); } catch (Exception e) { addError("Could not instantiate Joda DateTimeFormatter", e); errorCount++; } if (errorCount == 0) { super.start(); } }
private OutputStream getSyslogOutputStream() { Field f; try { f = SyslogAppenderBase.class.getDeclaredField("sos"); f.setAccessible(true); return (OutputStream) f.get(this); } catch (ReflectiveOperationException e) { throw Throwables.propagate(e); } }
public void start() { int errorCount = 0; final String facilityStr = getFirstOption(); if (facilityStr == null) { addError("was expecting a facility string as an option"); return; } facility = SyslogAppenderBase.facilityStringToint(facilityStr); localHostName = Optional.fromNullable(getContext().getProperty("hostname")) .or(getLocalHostname()); try { // ASL doesn't handle milliseconds. if (os.equals("Mac OS X")) { simpleFormat = new SimpleDateFormat("MMM dd HH:mm:ss", new DateFormatSymbols(Locale.US)); } else { simpleFormat = new SimpleDateFormat("MMM dd HH:mm:ss.SSS", new DateFormatSymbols(Locale.US)); } } catch (IllegalArgumentException e) { addError("Could not instantiate SimpleDateFormat", e); errorCount++; } if (errorCount == 0) { super.start(); } }
@Activate @SuppressWarnings("squid:S1149") protected void activate(ComponentContext ctx) { final Dictionary<?, ?> properties = ctx.getProperties(); final String[] loggers = PropertiesUtil.toStringArray(properties.get(PROP_LOGGERS), new String[] {ROOT}); final String suffixPattern = PropertiesUtil .toString(properties.get(PROP_SUFFIX_PATTERN), DEFAULT_SUFFIX_PATTERN); final int port = PropertiesUtil.toInteger(properties.get(PROP_PORT), DEFAULT_PORT); final String host = PropertiesUtil.toString(properties.get(PROP_HOST), null); final String facility = PropertiesUtil.toString(properties.get(PROP_FACILITY), DEFAULT_FACILITY); final String stackTracePattern = PropertiesUtil.toString(properties.get(PROP_STACK_TRACE_PATTERN), null); final boolean throwableExcluded = PropertiesUtil.toBoolean(properties.get(PROP_THROWABLE_EXCLUDED), DEFAULT_THROWABLE_EXCLUDED); if (host == null || port == -1) { throw new IllegalArgumentException( "Syslog Appender not configured correctly. Both host and port need to be provided."); } // throws a descriptive IllegalArgumentException if facility is not valid. SyslogAppenderBase.facilityStringToint(facility); final BundleContext bundleContext = ctx.getBundleContext(); appender = new ch.qos.logback.classic.net.SyslogAppender(); appender.setSyslogHost(host); appender.setPort(port); appender.setFacility(facility); appender.setSuffixPattern(suffixPattern); if (StringUtils.isNotEmpty(stackTracePattern)) { appender.setStackTracePattern(stackTracePattern); } appender.setThrowableExcluded(throwableExcluded); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("loggers", loggers); appenderRegistration = bundleContext.registerService(Appender.class.getName(), appender, props); }