<commit_before>'use strict';

import * as vscode from 'vscode';
import * as logging from '../logging';

export class OutputChannelLogger implements logging.ILogger {

  private logChannel: vscode.OutputChannel;

  // Minimum log level that is shown to users on logChannel
  private minimumUserLogLevel: logging.LogLevel = undefined;

  constructor() {
    this.logChannel = vscode.window.createOutputChannel("Puppet");

    let config = vscode.workspace.getConfiguration('puppet');
    let logLevelName = config['languageclient']['minimumUserLogLevel'];
    let logLevel = this.logLevelFromString(logLevelName);

    if(logLevel == undefined) {
      this.minimumUserLogLevel = logging.LogLevel.Normal;
      this.error("Logger could not interpret " + logLevelName + " as a log level setting");
    } else {
      this.minimumUserLogLevel = logLevel;
    }
  }

  public show() {
    this.logChannel.show();
  }

  public verbose(message: string) {
    this.logWithLevel(logging.LogLevel.Verbose, message);
  }

  public debug(message: string) {
    this.logWithLevel(logging.LogLevel.Debug, message);
  }

  public normal(message: string) {
    this.logWithLevel(logging.LogLevel.Normal, message);
  }

  public warning(message: string) {
    this.logWithLevel(logging.LogLevel.Warning, message);
  }

  public error(message: string) {
    this.logWithLevel(logging.LogLevel.Error, message);
  }

  private logWithLevel(level: logging.LogLevel, message) {
    let logMessage = this.logLevelPrefixAsString(level) + (new Date().toISOString()) + ' ' + message

    console.log(logMessage);
    if (level >= this.minimumUserLogLevel) {
      this.logChannel.appendLine(logMessage);
    }
  }

  private logLevelFromString(logLevelName: String): logging.LogLevel {
    switch (logLevelName.toLowerCase()) {
      case "verbose": return logging.LogLevel.Verbose;
      case "debug": return logging.LogLevel.Debug;
      case "normal": return logging.LogLevel.Normal;
      case "warning": return logging.LogLevel.Warning;
      case "error": return logging.LogLevel.Error;
      default:  return undefined;
    }
  }

  private logLevelPrefixAsString(level: logging.LogLevel): String {
    switch (level) {
      case logging.LogLevel.Verbose: return "VERBOSE: ";
      case logging.LogLevel.Debug: return "DEBUG: ";
      case logging.LogLevel.Warning: return "WARNING: ";
      case logging.LogLevel.Error: return "ERROR: ";
      default: return "";
    }
  }
}
<commit_msg>(maint) Fix tslint for Logging<commit_after>'use strict';

import * as vscode from 'vscode';
import * as logging from '../logging';

export class OutputChannelLogger implements logging.ILogger {

  private logChannel: vscode.OutputChannel;

  // Minimum log level that is shown to users on logChannel
  private minimumUserLogLevel: logging.LogLevel = logging.LogLevel.Normal;

  constructor() {
    this.logChannel = vscode.window.createOutputChannel("Puppet");

    let config = vscode.workspace.getConfiguration('puppet');
    let logLevelName = config['languageclient']['minimumUserLogLevel'];
    let logLevel = this.logLevelFromString(logLevelName);

    if (logLevel === undefined) {
      this.minimumUserLogLevel = logging.LogLevel.Normal;
      this.error("Logger could not interpret " + logLevelName + " as a log level setting");
    } else {
      this.minimumUserLogLevel = logLevel;
    }
  }

  public show() {
    this.logChannel.show();
  }

  public verbose(message: string) {
    this.logWithLevel(logging.LogLevel.Verbose, message);
  }

  public debug(message: string) {
    this.logWithLevel(logging.LogLevel.Debug, message);
  }

  public normal(message: string) {
    this.logWithLevel(logging.LogLevel.Normal, message);
  }

  public warning(message: string) {
    this.logWithLevel(logging.LogLevel.Warning, message);
  }

  public error(message: string) {
    this.logWithLevel(logging.LogLevel.Error, message);
  }

  private logWithLevel(level: logging.LogLevel, message: string) {
    let logMessage = this.logLevelPrefixAsString(level) + (new Date().toISOString()) + ' ' + message;

    console.log(logMessage);
    if (level >= this.minimumUserLogLevel) {
      this.logChannel.appendLine(logMessage);
    }
  }

  private logLevelFromString(logLevelName: String): logging.LogLevel {
    switch (logLevelName.toLowerCase()) {
      case "verbose": return logging.LogLevel.Verbose;
      case "debug": return logging.LogLevel.Debug;
      case "normal": return logging.LogLevel.Normal;
      case "warning": return logging.LogLevel.Warning;
      case "error": return logging.LogLevel.Error;
      default: return logging.LogLevel.Error;
    }
  }

  private logLevelPrefixAsString(level: logging.LogLevel): String {
    switch (level) {
      case logging.LogLevel.Verbose: return "VERBOSE: ";
      case logging.LogLevel.Debug: return "DEBUG: ";
      case logging.LogLevel.Warning: return "WARNING: ";
      case logging.LogLevel.Error: return "ERROR: ";
      default: return "";
    }
  }
}

{'fraction_non_alphanumeric': 0.117046818727491, 'fraction_numerical': 0.0, 'mean_word_length': 3.760952380952381, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 5, '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': '1436602', 'n_tokens_mistral': 1504, 'n_tokens_neox': 1460, 'n_words': 324}