java.lang.Object
org.noise_planet.noisemodelling.webserver.utilities.Logging

public class Logging extends Object
Utility functions related to logging features
  • Field Details

    • DEFAULT_LOG_FORMAT

      public static final String DEFAULT_LOG_FORMAT
      See Also:
    • LOG_PATTERN

      public static final Pattern LOG_PATTERN
    • LINE_SEPARATOR

      public static final String LINE_SEPARATOR
  • Constructor Details

    • Logging

      public Logging()
  • Method Details

    • initConsoleLogging

      public static void initConsoleLogging()
    • configureLoggerFromWorkingDirectory

      public static void configureLoggerFromWorkingDirectory(String workingDirectory, String loggingFileName, boolean verbose)
    • clearAppenders

      public static void clearAppenders()
    • createRollingFileAppender

      @NotNull public static org.apache.log4j.RollingFileAppender createRollingFileAppender(String workingDirectory, String loggingFileName)
    • formatThrowableAsHtml

      public static String formatThrowableAsHtml(Throwable throwable)
      Build an HTML-friendly stack trace string similar to what SLF4J would print, including the exception type, message, stack frames, causes, and suppressed exceptions.
    • appendSuppressed

      public static void appendSuppressed(StringBuilder sb, Throwable sup, IdentityHashMap<Throwable,Boolean> seen, String prefix)
    • getAllLines

      public static String getAllLines(String jobId, File loggingFile, int numberOfLines) throws IOException
      Return lines from the most recent to the old ones
      Parameters:
      jobId -
      numberOfLines -
      Returns:
      Throws:
      IOException
    • getLastLines

      public static String getLastLines(File logFile, int maximumLinesToFetch, String jobId, AtomicInteger fetchedLines) throws IOException
      Equivalent to "tail -n x file" linux command. Retrieve the n last lines from a file but from the most recent to the oldest one.
      Parameters:
      logFile -
      maximumLinesToFetch -
      Returns:
      Throws:
      IOException
    • formatSqlQueryResult

      public static String formatSqlQueryResult(groovy.sql.Sql sql, Object query)
      Executes a SQL query and return the result set as an ASCII table.
      Parameters:
      sql - An instance of groovy.sql.Sql
      query - A String or GString (allows for parameter injection)
    • formatSqlQueryResult

      public static String formatSqlQueryResult(groovy.sql.Sql sql, Object query, int maxColWidth)
      Executes a SQL query and return the result set as an ASCII table.
      Parameters:
      sql - An instance of groovy.sql.Sql
      query - A String or GString (allows for parameter injection)
      maxColWidth - Maximum width of a column before truncation