<commit_before>package de.lmu.ifi.dbs.logging;

import de.lmu.ifi.dbs.utilities.Progress;
import de.lmu.ifi.dbs.utilities.Util;

import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
 * Abstract superclass for classes being loggable, i.e. classes intending to log messages.
 * <p/> Provides method implementations of the {@link Loggable} interface.
 *
 * @author <NAME>
 */
public abstract class AbstractLoggable implements Loggable {

  static {

    LoggingConfiguration.configureRoot(LoggingConfiguration.CLI);
  }


  /**
   * Holds the class specific debug status.
   */
  protected boolean debug;

  /**
   * The logger of the class.
   */
  private final Logger logger;

  /**
   * Initializes the logger and sets the debug status to the given value.
   *
   * @param debug the debug status.
   */
  protected AbstractLoggable(boolean debug) {
    this.logger = Logger.getLogger(this.getClass().getName());
    this.debug = debug;
  }


  /**
   * Initializes the logger with the given name and sets the debug status to the given value.
   *
   * @param debug the debub status.
   * @param name  the name of the logger.
   */
  protected AbstractLoggable(boolean debug, String name) {
    this.logger = Logger.getLogger(name);
    this.debug = debug;
  }

  /**
   * Log an EXCEPTION message.
   * <p/>
   * If the logger is currently enabled for the EXCEPTION message level then
   * the given message is forwarded to all the registered output Handler
   * objects.
   *
   * @param msg The String message
   * @see Loggable#exception(String, Throwable)
   */
  public void exception(String msg, Throwable e) {
    logger.log(LogLevel.EXCEPTION, msg, e);
  }

  /**
   * Log a WARNING message.
   * <p/>
   * If the logger is currently enabled for the WARNING message level then the
   * given message is forwarded to all the registered output Handler objects.
   *
   * @param msg The String message
   * @see Loggable#warning(String)
   */
  public void warning(String msg) {
    logger.log(LogLevel.WARNING, msg);
  }

  /**
   * Log a message with Level MESSAGE.
   * <p/>
   * If the logger is currently enabled for the MESSAGE level then the given
   * message is forwarded to all the registered output Handler objects.
   *
   * @param msg The String message
   * @see Loggable#message(String)
   */
  public void message(String msg) {
    logger.log(LogLevel.MESSAGE, msg);
  }

  /**
   * Log a PROGRESS message.
   * <p/>
   * If the logger is currently enabled for the PROGRESS message level then
   * the given message is forwarded to all the registered output Handler
   * objects.
   *
   * @param pgr The Progress to be logged.
   * @see Loggable#progress(de.lmu.ifi.dbs.utilities.Progress)
   */
  public void progress(Progress pgr) {
    logger.log(new ProgressLogRecord(LogLevel.PROGRESS,
                                     Util.status(pgr),
                                     pgr.getTask(),
                                     pgr.status()));
  }

  /**
   * Log a PROGRESS message.
   * <p/>
   * If the logger is currently enabled for the PROGRESS message level then
   * the given message is forwarded to all the registered output Handler
   * objects.
   *
   * @param pgr The Progress to be logged.
   * @param numClusters The current number of clusters
   * @see Loggable#progress(de.lmu.ifi.dbs.utilities.Progress)
   */
  public void progress(Progress pgr, int numClusters) {
    logger.log(new ProgressLogRecord(LogLevel.PROGRESS,
                                     Util.status(pgr, numClusters),
                                     pgr.getTask(),
                                     pgr.status()));
  }


  /**
   * Log a PROGRESS message.
   * <p/>
   * If the logger is currently enabled for the PROGRESS message level then
   * the given message is forwarded to all the registered output Handler
   * objects.
   *
   * @see Loggable#progress(java.util.logging.LogRecord)
   */
  public void progress(LogRecord record) {
    logger.log(record);
  }

  /**
   * Log a VERBOSE message.
   * <p/>
   * If the logger is currently enabled for the VERBOSE message level then the
   * given message is forwarded to all the registered output Handler objects.
   *
   * @param msg The string message
   * @see Loggable#verbose(String)
   */
  public void verbose(String msg) {
    logger.log(LogLevel.VERBOSE, msg + Character.LINE_SEPARATOR);
  }
  
  /**
   * Log an empty VERBOSE message.
   * <p/>
   * If the logger is currently enabled for the VERBOSE message level then the
   * given message is forwarded to all the registered output Handler objects.
   *
   * Use this method to insert a newline in the verbose log.
   * 
   * @see #verbose(String)<commit_msg>line separator<commit_after>package de.lmu.ifi.dbs.logging;

import de.lmu.ifi.dbs.utilities.Progress;
import de.lmu.ifi.dbs.utilities.Util;

import java.util.logging.LogRecord;
import java.util.logging.Logger;

/**
 * Abstract superclass for classes being loggable, i.e. classes intending to log messages.
 * <p/> Provides method implementations of the {@link Loggable} interface.
 *
 * @author <NAME>
 */
public abstract class AbstractLoggable implements Loggable {

  static {

    LoggingConfiguration.configureRoot(LoggingConfiguration.CLI);
  }


  /**
   * Holds the class specific debug status.
   */
  protected boolean debug;

  /**
   * The logger of the class.
   */
  private final Logger logger;

  /**
   * Initializes the logger and sets the debug status to the given value.
   *
   * @param debug the debug status.
   */
  protected AbstractLoggable(boolean debug) {
    this.logger = Logger.getLogger(this.getClass().getName());
    this.debug = debug;
  }


  /**
   * Initializes the logger with the given name and sets the debug status to the given value.
   *
   * @param debug the debub status.
   * @param name  the name of the logger.
   */
  protected AbstractLoggable(boolean debug, String name) {
    this.logger = Logger.getLogger(name);
    this.debug = debug;
  }

  /**
   * Log an EXCEPTION message.
   * <p/>
   * If the logger is currently enabled for the EXCEPTION message level then
   * the given message is forwarded to all the registered output Handler
   * objects.
   *
   * @param msg The String message
   * @see Loggable#exception(String, Throwable)
   */
  public void exception(String msg, Throwable e) {
    logger.log(LogLevel.EXCEPTION, msg, e);
  }

  /**
   * Log a WARNING message.
   * <p/>
   * If the logger is currently enabled for the WARNING message level then the
   * given message is forwarded to all the registered output Handler objects.
   *
   * @param msg The String message
   * @see Loggable#warning(String)
   */
  public void warning(String msg) {
    logger.log(LogLevel.WARNING, msg);
  }

  /**
   * Log a message with Level MESSAGE.
   * <p/>
   * If the logger is currently enabled for the MESSAGE level then the given
   * message is forwarded to all the registered output Handler objects.
   *
   * @param msg The String message
   * @see Loggable#message(String)
   */
  public void message(String msg) {
    logger.log(LogLevel.MESSAGE, msg);
  }

  /**
   * Log a PROGRESS message.
   * <p/>
   * If the logger is currently enabled for the PROGRESS message level then
   * the given message is forwarded to all the registered output Handler
   * objects.
   *
   * @param pgr The Progress to be logged.
   * @see Loggable#progress(de.lmu.ifi.dbs.utilities.Progress)
   */
  public void progress(Progress pgr) {
    logger.log(new ProgressLogRecord(LogLevel.PROGRESS,
                                     Util.status(pgr),
                                     pgr.getTask(),
                                     pgr.status()));
  }

  /**
   * Log a PROGRESS message.
   * <p/>
   * If the logger is currently enabled for the PROGRESS message level then
   * the given message is forwarded to all the registered output Handler
   * objects.
   *
   * @param pgr The Progress to be logged.
   * @param numClusters The current number of clusters
   * @see Loggable#progress(de.lmu.ifi.dbs.utilities.Progress)
   */
  public void progress(Progress pgr, int numClusters) {
    logger.log(new ProgressLogRecord(LogLevel.PROGRESS,
                                     Util.status(pgr, numClusters),
                                     pgr.getTask(),
                                     pgr.status()));
  }


  /**
   * Log a PROGRESS message.
   * <p/>
   * If the logger is currently enabled for the PROGRESS message level then
   * the given message is forwarded to all the registered output Handler
   * objects.
   *
   * @see Loggable#progress(java.util.logging.LogRecord)
   */
  public void progress(LogRecord record) {
    logger.log(record);
  }

  /**
   * Log a VERBOSE message.
   * <p/>
   * If the logger is currently enabled for the VERBOSE message level then the
   * given message is forwarded to all the registered output Handler objects.
   *
   * @param msg The string message
   * @see Loggable#verbose(String)
   */
  public void verbose(String msg) {
    logger.log(LogLevel.VERBOSE, msg + System.getProperty("line.separator"));
  }
  
  /**
   * Log an empty VERBOSE message.
   * <p/>
   * If the logger is currently enabled for the VERBOSE message level then the
   * given message is forwarded to all the registered output Handler objects.
   *
   * Use this method to insert a newline in the verbose log.
   * 
   * @see #verbose(String)
{'fraction_non_alphanumeric': 0.09092829232231492, 'fraction_numerical': 0.0, 'mean_word_length': 2.5349010824934677, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '247487', 'n_tokens_mistral': 2810, 'n_tokens_neox': 2721, 'n_words': 954}