/** * Creates a logger with the given name, level, and log message format, that will write all its messages * to the given OutputStream. * @param os The output stream. * @param loggerName The name of the logger. * @param level The level below which messages will be ignored. * @param format The log format. See {@link LogFormatter}. * @see LogFormatter */ public OSLogger(OutputStream os, String loggerName, @Nullable LogLevel level, @Nullable String format) { this(os, os, loggerName, level, format); }
/** * @return the message logged. */ @API public String getMessage() { return message; }
/** * Formats the given log message, with {@code null} as the throwable. * * @param level The level of the message. * @param format The format string. * @param message The log message. * @param loggerName The name of the logger. * @return The formatted log message. * @see LogFormatter */ public static String formatLogMessage(@NotNull LogLevel level, @NotNull String format, @Nullable String message, @Nullable String loggerName) { return LogFormatter.formatLogMessage(level, format, message, null, loggerName); }
protected DeadEvent(@NotNull Object event) { this.event = event; }
/** * @return the unhandled event. */ @API public Object getEvent() { return event; } }
/** * If the provided logger is not null, it is returned, otherwise a new {@link NullLogger} is returned * * @param logger A logger, or null * @return Either the provided logger if it is not null, or a new {@link NullLogger} */ @NotNull public static ILogger getLogger(@Nullable ILogger logger) { return logger == null ? new NullLogger() : logger; }
protected LogEvent(LogLevel level, String message, @Nullable Throwable throwable) { this.level = level; this.throwable = throwable; this.message = message; }
/** * Sets the level of the current logger. All messages below that level will be ignored. * @param level The level. * @return {@code this}, for using the builder pattern. */ @API public OSLogger setLevel(LogLevel level) { this.level = level; return this; }
/** * Returns the event that made the EventHandler throw the exception. * * @return the event that made the EventHandler throw the exception. */ @API public Object getEvent() { return event; } }
/** * @return the level of the logged message. */ @API public LogLevel getLevel() { return level; }
/** * Returns the EventHandler that threw the Throwable. * * @return the EventHandler that threw the Throwable. */ @API public EventHandler getThrower() { return handler; }
/** * Creates a builder for a OSLogger with the given name that prints to the file with the given path. * @param path The path of the file the logger will output to. * @param loggerName The name of the logger. * @throws FileNotFoundException If the file could not be found. */ @API public Builder(String path, String loggerName) throws FileNotFoundException { this(new File(path), loggerName); }
/** * @return an immutable copy of the loggers this multi-logger logs to. */ @API public Set<ILogger> getLoggers() { return ImmutableSet.copyOf(loggers); }
/** * Adds another logger to this multi-logger. * @param logger The logger to add. */ @API public void addLogger(ILogger logger) { this.loggers.add(logger); }
/** * Returns a logger with the given name that prints all the messages to standard output. * Guaranteed to create a new logger each time. * @param name The name of the logger. * @return a logger that prints to standard output. */ @API public static ILogger getSysoutLogger(String name) { return new OSLogger(System.out, name); }
/** * Returns a logger with the given name that will print messages with level {@link LogLevel#INFO INFO} and below to * standard output, and messages with level above {@link LogLevel#INFO INFO} to standard error. * Guaranteed to create a new logger each time. * @param name The name of the logger. * @return A logger that prints to the standard channels. */ @API public static ILogger getStdLogger(String name) { return new OSLogger(System.out, System.err, name); }
/** * Returns a cached logger that prints all the messages to standard output. * @return a logger that prints to standard output. */ @API public static ILogger getSysoutLogger() { if (OUT_LOGGER == null) OUT_LOGGER = new OSLogger(System.out, ""); return OUT_LOGGER; }
/** * Returns a logger with the given name that prints all the messages to standard error. * Guaranteed to create a new logger each time. * @param name The name of the logger. * @return a logger that prints to standard error. */ @API public static ILogger getSyserrLogger(String name) { return new OSLogger(System.err, name); }
/** * Closes the underlying output stream. */ @API public void close() { this.close(true); }