<commit_before>'use strict';

import * as moment from 'moment';

import { LogLevel, getLevelName } from '../LogLevel';
import ILogger from '../Logger';
import DelegateLogManager from './Delegate';

export class ConsoleLogManager extends DelegateLogManager {
  constructor(defaultLevel: LogLevel) {
    super(this.logToConsole, defaultLevel);
  }

  private logToConsole(logger: ILogger, level: LogLevel, text: string) {
    console.log(String.format('[{0}][{1}][{2}] {3}', moment().format('HH:mm:ss.SSS'), getLevelName(level), logger.name, text));
  }
}

export let Default = new ConsoleLogManager(LogLevel.Debug);

export default Default;<commit_msg>console logging now applies style based on level<commit_after>'use strict';

import * as moment from 'moment';

import { LogLevel, getLevelName } from '../LogLevel';
import ILogger from '../Logger';
import DelegateLogManager from './Delegate';

export class ConsoleLogManager extends DelegateLogManager {
  constructor(defaultLevel: LogLevel) {
    super((action, level, text) => this.logAction(action, level, text), defaultLevel);
  }

  private getStyles(level: LogLevel) {
    // these colors should never get used
    let bgcolor = 'black';
    let color = 'white'

    if (level >= LogLevel.Fatal) {
      bgcolor = 'darkred';
      color = 'lightcoral';
    } else if (level >= LogLevel.Error) {
      bgcolor = 'lightcoral'
      color = 'black';
    } else if (level >= LogLevel.Warn) {
      bgcolor = 'blanchedalmond ';
      color = 'black';
    } else if (level >= LogLevel.Info) {
      bgcolor = 'lightblue ';
      color = 'black';
    } else if (level >= LogLevel.Debug) {
      bgcolor = 'lightcyan';
      color = 'black';
    } else {
      bgcolor = 'transparent';
      color = 'black';
    }

    return [
      String.format('background-color: {0}; color: {1}', bgcolor, color)
    ];
  }

  private logAction(logger: ILogger, level: LogLevel, text: string) {
    this.logToConsole(
      String.format('%c[{0}][{1}][{2}] {3}', moment().format('HH:mm:ss.SSS'), getLevelName(level), logger.name, text),
      ...this.getStyles(level)
    );
  }

  private logToConsole(text: string, ...formatting: string[]) {
    console.log(text, ...formatting);
  }
}

export let Default = new ConsoleLogManager(LogLevel.Debug);

export default Default;
{'fraction_non_alphanumeric': 0.15051903114186851, 'fraction_numerical': 0.004325259515570935, 'mean_word_length': 3.626, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '3731495', 'n_tokens_mistral': 722, 'n_tokens_neox': 715, 'n_words': 186}