private static LogRecord newLogRecord(Level level, String message) { LogRecord record = new LogRecord(level, message); record.setMillis(123456789L); return record; }
@Override public String format(LoggingEvent event) { java.util.logging.Level level = convertLevel(event.getLevel()); LogRecord logRecord = new LogRecord(level, event.getMessage().toString()); logRecord.setLoggerName(event.getLoggerName()); logRecord.setMillis(event.getTimeStamp()); logRecord.setSourceClassName(event.getLoggerName()); logRecord.setSourceMethodName(event.getLocationInformation().getMethodName()); logRecord.setThreadID((int) Thread.currentThread().getId()); return logger.format(logRecord); }
/** * Append a log event at the appropriate JUL level, depending on the log4j level. */ @Override protected void append(LoggingEvent loggingEvent) { java.util.logging.Logger logger = java.util.logging.Logger.getLogger(loggingEvent.getLoggerName()); if (logger == null) { LogLog.warn(format("Cannot obtain JUL %s. Verify that this appender is used while an appropriate LogManager is active.", loggingEvent.getLoggerName())); return; } Level level = loggingEvent.getLevel(); java.util.logging.Level julLevel = convertLog4jLevel(level); LogRecord record = new LogRecord(julLevel, loggingEvent.getRenderedMessage()); record.setMillis(loggingEvent.getTimeStamp()); LocationInfo location = loggingEvent.getLocationInformation(); if (location != null) { record.setSourceClassName(location.getClassName()); record.setSourceMethodName(location.getMethodName()); } logger.log(record); }
private LogRecord eventToRecord(LoggingEvent event, Level julLevel) { String format = event.getMessage(); Object[] arguments = event.getArgumentArray(); FormattingTuple ft = MessageFormatter.arrayFormat(format, arguments); if (ft.getThrowable() != null && event.getThrowable() != null) { throw new IllegalArgumentException("both last element in argument array and last argument are of type Throwable"); } Throwable t = event.getThrowable(); if (ft.getThrowable() != null) { t = ft.getThrowable(); throw new IllegalStateException("fix above code"); } LogRecord record = new LogRecord(julLevel, ft.getMessage()); record.setLoggerName(event.getLoggerName()); record.setMillis(event.getTimeStamp()); record.setSourceClassName(EventConstants.NA_SUBST); record.setSourceMethodName(EventConstants.NA_SUBST); record.setThrown(t); return record; } }
@SuppressWarnings("deprecation") // setMillis is deprecated in JDK 9 protected Object writeReplace() { LogRecord serialized = new LogRecord(getLevel(), getMessage()); serialized.setLoggerName(getLoggerName()); serialized.setResourceBundle(getResourceBundle()); serialized.setResourceBundleName(getResourceBundleName()); serialized.setSourceClassName(getSourceClassName()); serialized.setSourceMethodName(getSourceMethodName()); serialized.setSequenceNumber(getSequenceNumber()); serialized.setParameters(getParameters()); serialized.setThreadID(getThreadID()); serialized.setMillis(getMillis()); serialized.setThrown(getThrown()); return serialized; } }
rec.setMillis(date.getTime());
protected Object writeReplace() { final LogRecord replacement = new LogRecord(getLevel(), getMessage()); replacement.setResourceBundle(getResourceBundle()); replacement.setLoggerName(getLoggerName()); replacement.setMillis(getMillis()); replacement.setParameters(getParameters()); replacement.setResourceBundleName(getResourceBundleName()); replacement.setSequenceNumber(getSequenceNumber()); replacement.setSourceClassName(getSourceClassName()); replacement.setSourceMethodName(getSourceMethodName()); replacement.setThreadID(getThreadID()); replacement.setThrown(getThrown()); return replacement; }
@Test public void testSyncWrite() { expect(options.getProjectId()).andReturn(PROJECT).anyTimes(); expect(options.getService()).andReturn(logging); LogEntry entry = LogEntry.newBuilder(Payload.StringPayload.of(MESSAGE)) .setSeverity(Severity.DEBUG) .addLabel("levelName", "FINEST") .addLabel("levelValue", String.valueOf(Level.FINEST.intValue())) .setTimestamp(123456789L) .build(); logging.setFlushSeverity(Severity.ERROR); expectLastCall().once(); logging.setWriteSynchronicity(Synchronicity.ASYNC); expectLastCall().once(); logging.setWriteSynchronicity(Synchronicity.SYNC); expectLastCall().once(); logging.write(ImmutableList.of(entry), DEFAULT_OPTIONS); expectLastCall().once(); replay(options, logging); LoggingHandler handler = new LoggingHandler(LOG_NAME, options, DEFAULT_RESOURCE); handler.setLevel(Level.ALL); handler.setSynchronicity(Synchronicity.SYNC); handler.setFormatter(new TestFormatter()); LogRecord record = new LogRecord(Level.FINEST, MESSAGE); record.setMillis(123456789L); handler.publish(record); }
public static void deserialize(SerializationStreamReader reader, LogRecord instance) throws SerializationException { String loggerName = reader.readString(); Long millis = reader.readLong(); SerializableThrowable thrown = (SerializableThrowable) reader.readObject(); instance.setLoggerName(loggerName); instance.setMillis(millis); instance.setThrown(thrown); }
public static LogRecord logRecordFromJson(String jsonString) throws InvalidJsonLogRecordFormatException { try { JSONObject lro = new JSONObject(jsonString); String level = lro.getString("level"); String loggerName = lro.getString("loggerName"); String msg = lro.getString("msg"); long timestamp = Long.parseLong(lro.getString("timestamp")); Throwable thrown = JsonLogRecordThrowable.fromJsonString(lro.getString("thrown")); LogRecord lr = new LogRecord(Level.parse(level), msg); lr.setLoggerName(loggerName); lr.setThrown(thrown); lr.setMillis(timestamp); return lr; } catch (JSONException e) { throw new InvalidJsonLogRecordFormatException(e); } }
rec.setMillis(date.getTime());
public static LogRecord asLogRecord(SerializableLogRecord serializableLogRecord) { LogRecord logRecord = new LogRecord(Level.parse(serializableLogRecord.level), serializableLogRecord.message); logRecord.setLoggerName(serializableLogRecord.loggerName); logRecord.setMillis(serializableLogRecord.millis); logRecord.setThrown(JsonLogRecordThrowable.fromJsonString(serializableLogRecord.thrown)); return logRecord; }
private LogRecord fixRecord(final LogRecord record) { record.getSourceClassName(); // force init otherwise we'll get null, see org.apache.openejb.util.JuliLogStream.OpenEJBLogRecord.OpenEJBLogRecord() if (record.getLoggerName() == null) { record.setLoggerName(loggerName); } if (record.getMillis() == 0) { record.setMillis(System.currentTimeMillis()); } return record; }
/** * */ public LogRecord createLogRecord(Level level, String msg, long time) { LogRecord lr = new CustomLogRecord(level, msg); lr.setMillis(time); return lr; }
/** * */ public LogRecord createLogRecord(Level level, String msg, long time) { LogRecord lr = new CustomLogRecord(level, msg); lr.setMillis(time); return lr; }
/** * */ public LogRecord createLogRecord(Level level, String msg, long time) { LogRecord lr = new CustomLogRecord(level, msg); lr.setMillis(time); return lr; }
private synchronized void log(Level level, String tag, String msg) { if (this.mLogger == null) { Log.w("LogFile", "File logger not configured"); } else { this.mLogRecord.setMillis(System.currentTimeMillis()); this.mLogRecord.setLevel(level); this.mLogRecord.setMessage(String.format("%s: %s", tag, msg)); this.mLogRecord.setThrown(null); this.mLogger.log(this.mLogRecord); } }
private synchronized void log(Level level, String tag, String msg, Throwable t) { if (this.mLogger == null) { Log.w("LogFile", "File logger not configured"); } else { this.mLogRecord.setMillis(System.currentTimeMillis()); this.mLogRecord.setLevel(level); this.mLogRecord.setMessage(String.format("%s: %s", tag, msg)); this.mLogRecord.setThrown(t); this.mLogger.log(this.mLogRecord); } }
public static void deserialize(SerializationStreamReader reader, LogRecord instance) throws SerializationException { String loggerName = reader.readString(); Long millis = reader.readLong(); SerializableThrowable thrown = (SerializableThrowable) reader.readObject(); instance.setLoggerName(loggerName); instance.setMillis(millis); instance.setThrown(thrown); }
@Override public String format(LoggingEvent event) { java.util.logging.Level level = convertLevel(event.getLevel()); LogRecord logRecord = new LogRecord(level, event.getMessage().toString()); logRecord.setLoggerName(event.getLoggerName()); logRecord.setMillis(event.getTimeStamp()); logRecord.setSourceClassName(event.getLoggerName()); logRecord.setSourceMethodName(event.getLocationInformation().getMethodName()); logRecord.setThreadID((int) Thread.currentThread().getId()); return logger.format(logRecord); }