Java Code Examples for com.aliyun.openservices.log.common.LogItem#SetTime
The following examples show how to use
com.aliyun.openservices.log.common.LogItem#SetTime .
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: LoghubAppender.java From aliyun-log-logback-appender with Apache License 2.0 | 4 votes |
private void appendEvent(E eventObject) { //init Event Object if (!(eventObject instanceof LoggingEvent)) { return; } LoggingEvent event = (LoggingEvent) eventObject; List<LogItem> logItems = new ArrayList<LogItem>(); LogItem item = new LogItem(); logItems.add(item); item.SetTime((int) (event.getTimeStamp() / 1000)); if(formatter!=null){ DateTime dateTime = new DateTime(event.getTimeStamp()); item.PushBack("time", dateTime.toString(formatter)); }else { Instant instant = Instant.ofEpochMilli(event.getTimeStamp()); item.PushBack("time", formatter1.format(instant)); } item.PushBack("level", event.getLevel().toString()); item.PushBack("thread", event.getThreadName()); StackTraceElement[] caller = event.getCallerData(); if (caller != null && caller.length > 0) { item.PushBack("location", caller[0].toString()); } String message = event.getFormattedMessage(); item.PushBack("message", message); IThrowableProxy iThrowableProxy = event.getThrowableProxy(); if (iThrowableProxy != null) { String throwable = getExceptionInfo(iThrowableProxy); throwable += fullDump(event.getThrowableProxy().getStackTraceElementProxyArray()); item.PushBack("throwable", throwable); } if (this.encoder != null) { item.PushBack("log", new String(this.encoder.encode(eventObject))); } Optional.ofNullable(mdcFields).ifPresent( f->event.getMDCPropertyMap().entrySet().stream() .filter(v->Arrays.stream(f.split(",")).anyMatch(i->i.equals(v.getKey()))) .forEach(map-> item.PushBack(map.getKey(),map.getValue())) ); try { producer.send(projectConfig.getProject(), logStore, topic, source, logItems, new LoghubAppenderCallback<E>(this, projectConfig.getProject(), logStore, topic, source, logItems)); } catch (Exception e) { this.addError( "Failed to send log, project=" + project + ", logStore=" + logStore + ", topic=" + topic + ", source=" + source + ", logItem=" + logItems, e); } }
Example 2
Source File: LoghubAppender.java From aliyun-log-log4j2-appender with Apache License 2.0 | 4 votes |
@Override public void append(LogEvent event) { List<LogItem> logItems = new ArrayList<LogItem>(); LogItem item = new LogItem(); logItems.add(item); item.SetTime((int) (event.getTimeMillis() / 1000)); DateTime dateTime = new DateTime(event.getTimeMillis()); item.PushBack("time", dateTime.toString(formatter)); item.PushBack("level", event.getLevel().toString()); item.PushBack("thread", event.getThreadName()); StackTraceElement source = event.getSource(); if (source == null && (!event.isIncludeLocation())) { event.setIncludeLocation(true); source = event.getSource(); event.setIncludeLocation(false); } item.PushBack("location", source == null ? "Unknown(Unknown Source)" : source.toString()); String message = event.getMessage().getFormattedMessage(); item.PushBack("message", message); String throwable = getThrowableStr(event.getThrown()); if (throwable != null) { item.PushBack("throwable", throwable); } if (getLayout() != null) { item.PushBack("log", new String(getLayout().toByteArray(event))); } Optional.ofNullable(mdcFields).ifPresent( f->event.getContextMap().entrySet().stream() .filter(v->Arrays.stream(f.split(",")).anyMatch(i->i.equals(v.getKey()))) .forEach(map-> item.PushBack(map.getKey(),map.getValue())) ); try { producer.send(this.project, this.logStore, this.topic, this.source, logItems, new LoghubAppenderCallback(LOGGER, this.project, this.logStore, this.topic, this.source, logItems)); } catch (Exception e) { this.error( "Failed to send log, project=" + project + ", logStore=" + logStore + ", topic=" + topic + ", source=" + source + ", logItem=" + logItems, e); } }
Example 3
Source File: LoghubAppender.java From aliyun-log-log4j-appender with Apache License 2.0 | 4 votes |
@Override protected void append(LoggingEvent event) { LogItem logItem = new LogItem(); logItem.SetTime((int) (event.getTimeStamp() / 1000)); DateTime dateTime = new DateTime(event.getTimeStamp()); logItem.PushBack("time", dateTime.toString(formatter)); logItem.PushBack("level", event.getLevel().toString()); logItem.PushBack("thread", event.getThreadName()); logItem.PushBack("location", event.getLocationInformation().fullInfo); Object message = event.getMessage(); if(message==null){ logItem.PushBack("message", ""); }else{ logItem.PushBack("message", event.getMessage().toString()); } String throwable = getThrowableStr(event); if (throwable != null) { logItem.PushBack("throwable", throwable); } if (getLayout() != null) { logItem.PushBack("log", getLayout().format(event)); } Map properties = event.getProperties(); if (properties.size() > 0) { Object[] keys = properties.keySet().toArray(); Arrays.sort(keys); for (int i = 0; i < keys.length; i++) { logItem.PushBack(keys[i].toString(), properties.get(keys[i]) .toString()); } } try { producer.send(projectConfig.getProject(), logStore, topic, source, logItem, new LoghubAppenderCallback(projectConfig.getProject(), logStore, topic, source, logItem)); } catch (Exception e) { LogLog.error( "Failed to send log, project=" + project + ", logStore=" + logStore + ", topic=" + topic + ", source=" + source + ", logItem=" + logItem, e); } }