/** * Write pending messages to the log. */ public void flush() { if (sessionId == null) { // something went wrong before the session could have been initialized, just give all the messages some id. sessionId = UUID.randomUUID().toString(); } for (LogRecord logRecord : logRecords) { if (logRecord.printToSout) { System.out.println(formatLogMessage(logRecord.message, logRecord.type, logRecord.timestamp)); } else if (logRecord.logger.isLoggable(logRecord.loggingLevel)) { if (logRecord.t != null) { logRecord.logger.log(logRecord.loggingLevel, formatLogMessage(logRecord.message, logRecord.type, logRecord.timestamp), logRecord.t); } else { logRecord.logger.log(logRecord.loggingLevel, formatLogMessage(logRecord.message, logRecord.type, logRecord.timestamp)); } } } logRecords.clear(); }
/** * Write pending messages to the log. */ public void flush() { if (sessionId == null) { // something went wrong before the session could have been initialized, just give all the messages some id. sessionId = UUID.randomUUID().toString(); } for (LogRecord logRecord : logRecords) { if (logRecord.printToSout) { System.out.println(formatLogMessage(logRecord.message, logRecord.type, logRecord.timestamp)); } else if (logRecord.logger.isLoggable(logRecord.loggingLevel)) { if (logRecord.t != null) { logRecord.logger.log(logRecord.loggingLevel, formatLogMessage(logRecord.message, logRecord.type, logRecord.timestamp), logRecord.t); } else { logRecord.logger.log(logRecord.loggingLevel, formatLogMessage(logRecord.message, logRecord.type, logRecord.timestamp)); } } } logRecords.clear(); }
/** * Write a message to the standard output, the logging will be postponed until the message can be provided with * a session ID. Randomly generated session ID is used if a session has not been created. * * @param message message to be logged. * @param type type of the message. */ public void appendStandardOutputMessage(Type type, String message) { if (sessionId == null) { logRecords.add(new LogRecord(null, Level.OFF, type, message, null, true)); } else { System.out.println(formatLogMessage(message, type, System.nanoTime())); } }
/** * Write a message to the standard output, the logging will be postponed until the message can be provided with * a session ID. Randomly generated session ID is used if a session has not been created. * * @param message message to be logged. * @param type type of the message. */ public void appendStandardOutputMessage(Type type, String message) { if (sessionId == null) { logRecords.add(new LogRecord(null, Level.OFF, type, message, null, true)); } else { System.out.println(formatLogMessage(message, type, System.nanoTime())); } }
/** * Append a message to the log, the logging will be postponed until the message can be provided with a session ID. * Randomly generated session ID is used if a session has not been created. * * @param logger logger to be used to log the message. * @param loggingLevel message level. * @param type type of the message. * @param t throwable that has been thrown. * @param messageParts message parts that will be stringified and concatenated to create a log message. */ public void appendLogMessageWithThrowable(Logger logger, Level loggingLevel, Type type, Throwable t, Object... messageParts) { if (logger.isLoggable(loggingLevel)) { String message = stringifyMessageParts(messageParts); if (sessionId == null) { logRecords.add(new LogRecord(logger, loggingLevel, type, message, t, false)); } else { if (t != null) { logger.log(loggingLevel, formatLogMessage(message, type, System.nanoTime()), t); } else { logger.log(loggingLevel, formatLogMessage(message, type, System.nanoTime())); } } } }
/** * Append a message to the log, the logging will be postponed until the message can be provided with a session ID. * Randomly generated session ID is used if a session has not been created. * * @param logger logger to be used to log the message. * @param loggingLevel message level. * @param type type of the message. * @param t throwable that has been thrown. * @param messageParts message parts that will be stringified and concatenated to create a log message. */ public void appendLogMessageWithThrowable(Logger logger, Level loggingLevel, Type type, Throwable t, Object... messageParts) { if (logger.isLoggable(loggingLevel)) { String message = stringifyMessageParts(messageParts); if (sessionId == null) { logRecords.add(new LogRecord(logger, loggingLevel, type, message, t, false)); } else { if (t != null) { logger.log(loggingLevel, formatLogMessage(message, type, System.nanoTime()), t); } else { logger.log(loggingLevel, formatLogMessage(message, type, System.nanoTime())); } } } }