public String convert(ILoggingEvent le) { long timestamp = le.getTimeStamp(); return cachingDateFormatter.format(timestamp); } }
public void start() { String datePattern = getFirstOption(); if (datePattern == null) { datePattern = CoreConstants.ISO8601_PATTERN; } if (datePattern.equals(CoreConstants.ISO8601_STR)) { datePattern = CoreConstants.ISO8601_PATTERN; } try { cachingDateFormatter = new CachingDateFormatter(datePattern); // maximumCacheValidity = // CachedDateFormat.getMaximumCacheValidity(pattern); } catch (IllegalArgumentException e) { addWarn("Could not instantiate SimpleDateFormat with pattern " + datePattern, e); // default to the ISO8601 format cachingDateFormatter = new CachingDateFormatter(CoreConstants.ISO8601_PATTERN); } List<String> optionList = getOptionList(); // if the option list contains a TZ option, then set it. if (optionList != null && optionList.size() > 1) { TimeZone tz = TimeZone.getTimeZone((String) optionList.get(1)); cachingDateFormatter.setTimeZone(tz); } }
Scope scope = ActionUtil.stringToScope(scopeStr); CachingDateFormatter sdf = new CachingDateFormatter(datePatternStr); String val = sdf.format(timeReference);
@Test public void timeZoneIsTakenIntoAccount() throws ParseException { CachingDateFormatter cdf = new CachingDateFormatter(DATE_PATTERN); TimeZone perthTZ = TimeZone.getTimeZone("Australia/Perth"); cdf.setTimeZone(perthTZ); Date march26_2015_0949_UTC = sdf.parse("2015-03-26T09:49"); System.out.print(march26_2015_0949_UTC); String result = cdf.format(march26_2015_0949_UTC.getTime()); // AWST (Perth) is 8 hours ahead of UTC assertEquals("2015-03-26T17:49", result); } }
public void start() { this.datePattern = getFirstOption(); if (this.datePattern == null) { this.datePattern = DEFAULT_DATE_PATTERN; } final List<String> optionList = getOptionList(); if(optionList != null && optionList.size()> 1) { String secondOption = optionList.get(1); if(AUXILIARY_TOKEN.equalsIgnoreCase(secondOption)) { primary = false; } } cdf = new CachingDateFormatter(datePattern); }
@Test public void timestamp() throws JoranException, IOException, InterruptedException { String configFileAsStr = ClassicTestConstants.JORAN_INPUT_PREFIX + "timestamp-context.xml"; configure(configFileAsStr); String r = loggerContext.getProperty("testTimestamp"); assertNotNull(r); CachingDateFormatter sdf = new CachingDateFormatter("yyyy-MM"); String expected = sdf.format(System.currentTimeMillis()); assertEquals("expected \"" + expected + "\" but got " + r, expected, r); }
public void start() { this.datePattern = getFirstOption(); if (this.datePattern == null) { this.datePattern = DEFAULT_DATE_PATTERN; } final List<String> optionList = getOptionList(); if(optionList != null && optionList.size()> 1) { String secondOption = optionList.get(1); if(AUXILIARY_TOKEN.equalsIgnoreCase(secondOption)) { primary = false; } } cdf = new CachingDateFormatter(datePattern); }
return; CachingDateFormatter sdf = new CachingDateFormatter(datePatternStr); String val = sdf.format(timeReference);
@Override public String doLayout(ILoggingEvent event) { if (!isStarted()) { return CoreConstants.EMPTY_STRING; } StringBuilder sb = new StringBuilder(); long timestamp = event.getTimeStamp(); sb.append(cachingDateFormatter.format(timestamp)); sb.append(" ["); sb.append(event.getThreadName()); sb.append("] "); sb.append(event.getLevel().toString()); sb.append(" "); sb.append(event.getLoggerName()); sb.append(" - "); sb.append(event.getFormattedMessage()); sb.append(CoreConstants.LINE_SEPARATOR); IThrowableProxy tp = event.getThrowableProxy(); if (tp != null) { String stackTrace = tpc.convert(event); sb.append(stackTrace); } return sb.toString(); }
public void start() { String datePattern = getFirstOption(); if (datePattern == null) { datePattern = CoreConstants.ISO8601_PATTERN; } if (datePattern.equals(CoreConstants.ISO8601_STR)) { datePattern = CoreConstants.ISO8601_PATTERN; } try { cachingDateFormatter = new CachingDateFormatter(datePattern); // maximumCacheValidity = // CachedDateFormat.getMaximumCacheValidity(pattern); } catch (IllegalArgumentException e) { addWarn("Could not instantiate SimpleDateFormat with pattern " + datePattern, e); // default to the ISO8601 format cachingDateFormatter = new CachingDateFormatter(CoreConstants.ISO8601_PATTERN); } List optionList = getOptionList(); // if the option list contains a TZ option, then set it. if (optionList != null && optionList.size() > 1) { TimeZone tz = TimeZone.getTimeZone((String) optionList.get(1)); cachingDateFormatter.setTimeZone(tz); } }
public void start() { this.datePattern = getFirstOption(); if (this.datePattern == null) { this.datePattern = DEFAULT_DATE_PATTERN; } final List<String> optionList = getOptionList(); if(optionList != null && optionList.size()> 1) { String secondOption = optionList.get(1); if(AUXILIARY_TOKEN.equalsIgnoreCase(secondOption)) { primary = false; } } cdf = new CachingDateFormatter(datePattern); }
return; CachingDateFormatter sdf = new CachingDateFormatter(datePatternStr); String val = sdf.format(timeReference);
public String convert(Date date) { return cdf.format(date.getTime()); }
public void start() { this.datePattern = getFirstOption(); if (this.datePattern == null) { this.datePattern = DEFAULT_DATE_PATTERN; } final List<String> optionList = getOptionList(); if (optionList != null) { for (int optionIndex = 1; optionIndex < optionList.size(); optionIndex++) { String option = optionList.get(optionIndex); if (AUXILIARY_TOKEN.equalsIgnoreCase(option)) { primary = false; } else { timeZone = TimeZone.getTimeZone(option); } } } cdf = new CachingDateFormatter(datePattern); if (timeZone != null) { cdf.setTimeZone(timeZone); } }
@Override public void begin(InterpretationContext ec, String name, Attributes attributes) throws ActionException { String keyStr = attributes.getValue(KEY_ATTRIBUTE); if (OptionHelper.isEmpty(keyStr)) { addError("Attribute named [" + KEY_ATTRIBUTE + "] cannot be empty"); inError = true; } String datePatternStr = attributes.getValue(DATE_PATTERN_ATTRIBUTE); if (OptionHelper.isEmpty(datePatternStr)) { addError("Attribute named [" + DATE_PATTERN_ATTRIBUTE + "] cannot be empty"); inError = true; } String timeReferenceStr = attributes.getValue(TIME_REFERENCE_ATTRIBUTE); long timeReference; if (CONTEXT_BIRTH.equalsIgnoreCase(timeReferenceStr)) { addInfo("Using context birth as time reference."); timeReference = context.getBirthTime(); } else { timeReference = System.currentTimeMillis(); addInfo("Using current interpretation time, i.e. now, as time reference."); } if (inError) return; String scopeStr = attributes.getValue(SCOPE_ATTRIBUTE); Scope scope = ActionUtil.stringToScope(scopeStr); CachingDateFormatter sdf = new CachingDateFormatter(datePatternStr); String val = sdf.format(timeReference); addInfo("Adding property to the context with key=\"" + keyStr + "\" and value=\"" + val + "\" to the " + scope + " scope"); ActionUtil.setProperty(ec, keyStr, val, scope); }
public String convert(ILoggingEvent le) { long timestamp = le.getTimeStamp(); return cachingDateFormatter.format(timestamp); } }
public void start() { this.datePattern = getFirstOption(); if (this.datePattern == null) { this.datePattern = DEFAULT_DATE_PATTERN; } final List<String> optionList = getOptionList(); if (optionList != null) { for (int optionIndex = 1; optionIndex < optionList.size(); optionIndex++) { String option = optionList.get(optionIndex); if (AUXILIARY_TOKEN.equalsIgnoreCase(option)) { primary = false; } else { timeZone = TimeZone.getTimeZone(option); } } } cdf = new CachingDateFormatter(datePattern); if (timeZone != null) { cdf.setTimeZone(timeZone); } }
Scope scope = ActionUtil.stringToScope(scopeStr); CachingDateFormatter sdf = new CachingDateFormatter(datePatternStr); String val = sdf.format(timeReference);
private void printStatus(StringBuilder buf, Status s) { String trClass; if (count % 2 == 0) { trClass = "even"; } else { trClass = "odd"; } buf.append(" <tr class=\"").append(trClass).append("\">\r\n"); String dateStr = SDF.format(s.getDate()); buf.append(" <td class=\"date\">").append(dateStr).append("</td>\r\n"); buf.append(" <td class=\"level\">").append(statusLevelAsString(s)) .append("</td>\r\n"); buf.append(" <td>").append(abbreviatedOrigin(s)).append("</td>\r\n"); buf.append(" <td>").append(s.getMessage()).append("</td>\r\n"); buf.append(" </tr>\r\n"); if (s.getThrowable() != null) { printThrowable(buf, s.getThrowable()); } }
public void start() { this.datePattern = getFirstOption(); if (this.datePattern == null) { this.datePattern = DEFAULT_DATE_PATTERN; } final List<String> optionList = getOptionList(); if (optionList != null) { for (int optionIndex = 1; optionIndex < optionList.size(); optionIndex++) { String option = optionList.get(optionIndex); if (AUXILIARY_TOKEN.equalsIgnoreCase(option)) { primary = false; } else { timeZone = TimeZone.getTimeZone(option); } } } cdf = new CachingDateFormatter(datePattern); if (timeZone != null) { cdf.setTimeZone(timeZone); } }