/** * Creates a rotating file logger that logs the messages to files in the default directory. * * @throws FileNotFoundException if the current file cannot be opened or created. */ protected RotatingFileLogger() throws FileNotFoundException { super(getCurrentFile()); this.currentDate = new Date(); Files.directory.register((configuration, oldFile, newFile) -> rotate()); }
@Impure @Override @SuppressWarnings("deprecation") protected void log(@Nonnull Level level, @Nonnull String caller, @Nonnull String thread, @Nonnull String message, @Nullable Throwable throwable) { final Date date = new Date(); if (date.getDate() != this.currentDate.getDate()) { rotate(); } super.log(level, caller, thread, message, throwable); }
/** * Returns a rotating file logger that logs the messages to files in the default directory. * * @throws FileNotFoundException if the current file cannot be opened or created. */ @Pure public static @Capturable @Nonnull RotatingFileLogger withDefaultDirectory() throws FileNotFoundException { return new RotatingFileLogger(); }
/** * Logs the given message and throwable to make it easier to trace the execution of the program. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void verbose(@Nonnull CharSequence message, @Nullable Throwable throwable, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.VERBOSE, message, throwable, arguments); }
/** * Initializes the output file of the logger. */ @PureWithSideEffects @Initialize(target = Logger.class) public static void initializeLogger() throws FileNotFoundException { Logger.logger.set(FileLogger.with(Files.relativeToWorkingDirectory("target/test-logs/test.log"))); }
/** * Rotates the log file. */ @Impure private void rotate() { this.currentDate = new Date(); try { setFile(getCurrentFile()); } catch (@Nonnull FileNotFoundException exception) { throw UncheckedExceptionBuilder.withCause(exception).build(); } }
/** * Returns a standard output logger that logs the messages to the standard output. */ @Pure public static @Capturable @Nonnull StandardOutputLogger withNoArguments() { return new StandardOutputLogger(); }
/** * Initializes the logger with a rotating file logger. */ @PureWithSideEffects @Initialize(target = Logger.class) public static void initializeLogger() throws FileNotFoundException { if (Logger.logger.get() instanceof StandardOutputLogger) { Logger.logger.set(RotatingFileLogger.withDefaultDirectory()); Log.verbose("Replaced the default standard output logger with a rotating file logger."); } else { Log.verbose("Did not replace the non-default logger with a rotating file logger."); } }
/** * Logs the given message and throwable to help developers locate bugs in the code. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void debugging(@Nonnull CharSequence message, @Nullable Throwable throwable, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.DEBUGGING, message, throwable, arguments); }
/** * Initializes the output file of the logger with the given name. */ @Impure public static void initialize(@Nonnull String name) throws IllegalArgumentException, FileNotFoundException { Caller.index.set(6); Version.string.set("0.7"); LoggingFilter.filter.set(ConfigurationBasedLoggingFilter.with(Files.relativeToWorkingDirectory("config/" + name + ".conf"), LoggingRule.with(Level.INFORMATION))); Logger.logger.set(FileLogger.with(Files.relativeToWorkingDirectory("target/processor-logs/" + name + ".log"))); }
/** * Logs the given message to inform about important runtime events. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void information(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.INFORMATION, message, null, arguments); }
/** * Logs the given message to make it easier to trace the execution of the program. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void verbose(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.VERBOSE, message, null, arguments); }
/** * Logs the given message and throwable as an error from which the application can possibly recover. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void error(@Nonnull CharSequence message, @Nullable Throwable throwable, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.ERROR, message, throwable, arguments); }
/** * Logs the given message and throwable as a warning that indicate potential problems in the program. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void warning(@Nonnull CharSequence message, @Nullable Throwable throwable, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.WARNING, message, throwable, arguments); }
/** * Logs the given message and throwable to inform about important runtime events. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void information(@Nonnull CharSequence message, @Nullable Throwable throwable, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.INFORMATION, message, throwable, arguments); }
/** * Logs the given message as a fatal error that prevents the thread or process from continuing. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void fatal(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.FATAL, message, null, arguments); }
/** * Logs the given message as a warning that indicate potential problems in the program. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void warning(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.WARNING, message, null, arguments); }
/** * Logs the given message to help developers locate bugs in the code. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void debugging(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.DEBUGGING, message, null, arguments); }
/** * Logs the given message and throwable as a fatal error that prevents the thread or process from continuing. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void fatal(@Nonnull CharSequence message, @Nullable Throwable throwable, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.FATAL, message, throwable, arguments); }
/** * Logs the given message as an error from which the application can possibly recover. * Each dollar sign in the message is replaced with the corresponding argument. */ @Impure public static void error(@Nonnull CharSequence message, @NonCaptured @Unmodified @Nonnull @NullableElements Object... arguments) { Logger.log(Level.ERROR, message, null, arguments); }