<commit_before>import { LoggerInterface } from '../Common/Logger/LoggerInterface';
import { Logger } from '../Common/Logger/Logger';
import { IRegisteredLoggingModule } from '../Common/Logger/RegisteredLoggingModule';
import { RegisteredLoggingModule } from '../Common/Logger/RegisteredLoggingModule';
import { IRegisteredLoggingModules } from '../Common/Logger/RegisteredLoggingModules';
import { RegisteredLoggingModules } from '../Common/Logger/RegisteredLoggingModules';
import { IRegisteredLoggingModulesSetting } from '../Common/Logger/RegisteredLoggingModulesSetting';
import { RegisteredLoggingModulesSetting } from '../Common/Logger/RegisteredLoggingModulesSetting';
import { ILogLevel } from '../Common/Logger/LogLevel';
import { LogLevel, LogLevelOff, LogLevelAll, LogLevelDebug, LogLevelError, LogLevelInfo, LogLevelWarn } from '../Common/Logger/LogLevel';
import { ILoggerLogLevelSetting } from '../Common/Logger/LoggerLogLevelSetting';
import { LoggerLogLevelSetting } from '../Common/Logger/LoggerLogLevelSetting';
import { RessourceSettingsPageLoggerHeading } from "../Common/Ressource"
import { RessourceSettingsPageLoggerIntro } from "../Common/Ressource"

export class SettingsLogging {
  private thisModule: string = "SettingsLogging";
  private loggingModule: IRegisteredLoggingModule;
  private log: LoggerInterface;
  private registeredLoggingModulesSetting: IRegisteredLoggingModulesSetting;
  private loggerLogLevelSetting: ILoggerLogLevelSetting;

  public ressourceHeading: String;
  public ressourceIntro: String;
  public loggingModules: Array<LoggingModule>;
  public loggingLevels2: Array<ILogLevel>;
  public loggerLogLevel: ILogLevel;

  constructor() {
    this.log = new Logger();
    this.registeredLoggingModulesSetting = this.log.registeredModulesSetting();
    this.loggingModule = new RegisteredLoggingModule(this.thisModule, new LogLevelError());
    this.log.registerModuleForLogging(this.loggingModule);
    this.loggerLogLevelSetting = this.log.loggerLogLevelSetting();

    this.ressourceHeading = new RessourceSettingsPageLoggerHeading().value();
    this.ressourceIntro = new RessourceSettingsPageLoggerIntro().value();

    this.loggerLogLevelSetting.logLevel()
      .then(logLevel =>
        this.loggerLogLevel = new LogLevel(logLevel.name(), logLevel.level()));

    this.collectLogLevels2();
    this.loggingModules = new Array<LoggingModule>();
    this.registeredLoggingModulesSetting.modules().then(modules => {
      modules.modules().forEach(m => {
        this.debug(`Loaded logging modules: ${m.name()}, ${JSON.stringify(m.logLevel())}`);
        this.loggingModules.push(new LoggingModule(m.name(), m.logLevel()));
      });
    });
  }

  public submit() {
    this.info(`Submitted called`);

    this.loggerLogLevelSetting
      .changeLogLevel(new LogLevel(this.loggerLogLevel.name(), this.loggerLogLevel.level()));

    this.registeredLoggingModulesSetting.changeModules(
      this.loggingModules.map(m => new RegisteredLoggingModule(m.name, m.logLevel)));
  }

  public logLevelMatcher = (logLevel1: ILogLevel, logLevel2: ILogLevel): Boolean => logLevel1.name() === logLevel2.name();

  private collectLogLevels2() {
    this.loggingLevels2 = new Array<ILogLevel>();
    this.loggingLevels2.push(new LogLevelOff());
    this.loggingLevels2.push(new LogLevelAll());
    this.loggingLevels2.push(new LogLevelDebug());
    this.loggingLevels2.push(new LogLevelWarn());
    this.loggingLevels2.push(new LogLevelError());
    this.loggingLevels2.push(new LogLevelInfo());
    this.debug(`Created array of log levels: ${this.loggingLevels2.map(ll => JSON.stringify(ll)).join(", ")}`);
  }

  private info(msg: string): void {
    this.log.info(this.thisModule, msg);
  }
  private debug(msg: string): void {
    this.log.debug(this.thisModule, msg);<commit_msg>sort array of log levels before presenting them on settings view<commit_after>import { LoggerInterface } from '../Common/Logger/LoggerInterface';
import { Logger } from '../Common/Logger/Logger';
import { IRegisteredLoggingModule } from '../Common/Logger/RegisteredLoggingModule';
import { RegisteredLoggingModule } from '../Common/Logger/RegisteredLoggingModule';
import { IRegisteredLoggingModules } from '../Common/Logger/RegisteredLoggingModules';
import { RegisteredLoggingModules } from '../Common/Logger/RegisteredLoggingModules';
import { IRegisteredLoggingModulesSetting } from '../Common/Logger/RegisteredLoggingModulesSetting';
import { RegisteredLoggingModulesSetting } from '../Common/Logger/RegisteredLoggingModulesSetting';
import { ILogLevel } from '../Common/Logger/LogLevel';
import { LogLevel, LogLevelOff, LogLevelAll, LogLevelDebug, LogLevelError, LogLevelInfo, LogLevelWarn } from '../Common/Logger/LogLevel';
import { ILoggerLogLevelSetting } from '../Common/Logger/LoggerLogLevelSetting';
import { LoggerLogLevelSetting } from '../Common/Logger/LoggerLogLevelSetting';
import { RessourceSettingsPageLoggerHeading } from "../Common/Ressource"
import { RessourceSettingsPageLoggerIntro } from "../Common/Ressource"

export class SettingsLogging {
  private thisModule: string = "SettingsLogging";
  private loggingModule: IRegisteredLoggingModule;
  private log: LoggerInterface;
  private registeredLoggingModulesSetting: IRegisteredLoggingModulesSetting;
  private loggerLogLevelSetting: ILoggerLogLevelSetting;

  public ressourceHeading: String;
  public ressourceIntro: String;
  public loggingModules: Array<LoggingModule>;
  public loggingLevels2: Array<ILogLevel>;
  public loggerLogLevel: ILogLevel;

  constructor() {
    this.log = new Logger();
    this.registeredLoggingModulesSetting = this.log.registeredModulesSetting();
    this.loggingModule = new RegisteredLoggingModule(this.thisModule, new LogLevelError());
    this.log.registerModuleForLogging(this.loggingModule);
    this.loggerLogLevelSetting = this.log.loggerLogLevelSetting();

    this.ressourceHeading = new RessourceSettingsPageLoggerHeading().value();
    this.ressourceIntro = new RessourceSettingsPageLoggerIntro().value();

    this.loggerLogLevelSetting.logLevel()
      .then(logLevel =>
        this.loggerLogLevel = new LogLevel(logLevel.name(), logLevel.level()));

    this.collectLogLevels2();
    this.loggingModules = new Array<LoggingModule>();
    this.registeredLoggingModulesSetting.modules().then(modules => {
      modules.modules().forEach(m => {
        this.debug(`Loaded logging modules: ${m.name()}, ${JSON.stringify(m.logLevel())}`);
        this.loggingModules.push(new LoggingModule(m.name(), m.logLevel()));
      });
    });
  }

  public submit() {
    this.info(`Submitted called`);

    this.loggerLogLevelSetting
      .changeLogLevel(new LogLevel(this.loggerLogLevel.name(), this.loggerLogLevel.level()));

    this.registeredLoggingModulesSetting.changeModules(
      this.loggingModules.map(m => new RegisteredLoggingModule(m.name, m.logLevel)));
  }

  public logLevelMatcher = (logLevel1: ILogLevel, logLevel2: ILogLevel): Boolean => logLevel1.name() === logLevel2.name();

  private collectLogLevels2() {
    this.loggingLevels2 = new Array<ILogLevel>();
    this.loggingLevels2.push(new LogLevelOff());
    this.loggingLevels2.push(new LogLevelAll());
    this.loggingLevels2.push(new LogLevelDebug());
    this.loggingLevels2.push(new LogLevelWarn());
    this.loggingLevels2.push(new LogLevelError());
    this.loggingLevels2.push(new LogLevelInfo());
    this.loggingLevels2 = this.loggingLevels2.sort((a, b) =>
      (a.level().valueOf() - b.level().valueOf()).valueOf());
    this.debug(`Created array of log levels: ${this.loggingLevels2.map(ll => JSON.stringify(ll)).join(", ")}`);
  }

  private info(msg: string): void {
    this.log.info(this.thisModule, msg);
  }
  private debug(msg: string): void {
    this.log.debug(this.thisModule, msg);
{'fraction_non_alphanumeric': 0.1273983115886416, 'fraction_numerical': 0.004093118444614991, 'mean_word_length': 5.275280898876405, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4652530', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2237, 'n_words': 402}