<commit_before>//
//  LogController.swift
//  BMSCore
//
//  Created by Nana on 11/17/15.
//  Copyright © 2015 IBM. All rights reserved.
//

import UIKit
import BMSCore

class LogController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource{

    @IBOutlet weak var crashButton: UIButton!
    
    

    let logArray = ["debug", "info", "warn", "error", "fatal"]
    var level = "debug"
    var type = "debug"
    @IBOutlet weak var packageName: UITextField!
    @IBOutlet weak var levelPicker: UIPickerView!
    @IBOutlet weak var typePicker: UIPickerView!
    @IBOutlet weak var logText: UITextView!
    
    @IBOutlet weak var capture: UISwitch!

    @IBOutlet weak var logMessage: UITextField!
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    // The number of columns of data
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }
    
    // The number of rows of data
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return logArray.count
    }
    
    // The data to return for the row and component (column) that's being passed in
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return logArray[row]
    }
    
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        
        switch pickerView.tag{
            case 0:
                print("Selecting log type " + logArray[row])
                type = logArray[row]
            case 1:
                print("Selected log level " + logArray[row])
                level = logArray[row]
            default:
                print("should not happen")
            
        }
    }
    
    @IBAction func sendLogButton(sender: AnyObject) {
        var logger = Logger.getLoggerForName("SampleLogger")
        if(!packageName.text!.isEmpty){
            logger = Logger.getLoggerForName(packageName.text!)
        }
        
        if(capture.enabled){
                Logger.internalSDKLoggingEnabled = true
        } else {
            Logger.internalSDKLoggingEnabled = false
        }
        

        switch level {
            case "debug":
                Logger.logLevelFilter = LogLevel.Debug
            case "info":
                Logger.logLevelFilter = LogLevel.Info
            case "warn":
                Logger.logLevelFilter = LogLevel.Warn
            case "error":
                Logger.logLevelFilter = LogLevel.Error
            case "fatal":
                Logger.logLevelFilter = LogLevel.Fatal
            default:
                Logger.logLevelFilter = LogLevel.Debug
        }
        
        switch type {
            case "debug":
                logger.debug(logMessage.text!)
            case "info":
                logger.info(logMessage.text!)
            case "warn":
                logger.warn(logMessage.text!)
            case "error":
                logger.error(logMessage.text!)
            case "fatal":
                logger.fatal(logMessage.text!)
            default:
                logger.debug(logMessage.text!)
            
        }
        
        
      
    }
    
    @IBAction func crashAppButton(sender: AnyObject){
        let e = NSException(name:"crashApp", reason:"No reason at all just doing it for fun", userInfo:["user":"nana"])
        e.raise()
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.typePicker.delegate = self
        self.typePicker.dataSource = self
        self.typePicker.tag = 0
        
        self.levelPicker.delegate = self
        self.levelPicker.tag = 1
        self.levelPicker.dataSource = self
    }
    
    

}
<commit_msg>Updated logger controller to show and clear logs<commit_after>/*
*     Copyright 2015 IBM Corp.
*     Licensed under the Apache License, Version 2.0 (the "License");
*     you may not use this file except in compliance with the License.
*     You may obtain a copy of the License at
*     http://www.apache.org/licenses/LICENSE-2.0
*     Unless required by applicable law or agreed to in writing, software
*     distributed under the License is distributed on an "AS IS" BASIS,
*     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*     See the License for the specific language governing permissions and
*     limitations under the License.
*/

import UIKit
import BMSCore

class LogController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource{

    @IBOutlet weak var crashButton: UIButton!
    
    

    let logArray = ["debug", "info", "warn", "error", "fatal"]
    var level = "debug"
    var type = "debug"
    @IBOutlet weak var packageName: UITextField!
    @IBOutlet weak var levelPicker: UIPickerView!
    @IBOutlet weak var typePicker: UIPickerView!
    @IBOutlet weak var logText: UITextView!
    
    @IBOutlet weak var capture: UISwitch!

    @IBOutlet weak var logMessage: UITextField!
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    // The number of columns of data
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }
    
    // The number of rows of data
    func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return logArray.count
    }
    
    @IBAction func clearLogButton(sender: AnyObject) {
        let FILE = "mfpsdk.logger.log"
        let PATH = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] + "/"
        let pathToFile = PATH + FILE
        do {
            try NSFileManager().removeItemAtPath(pathToFile)
        } catch {
            
        }
    }
    @IBAction func updateLogText(sender: AnyObject) {
        let FILE = "mfpsdk.logger.log"
        let PATH = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] + "/"
        let pathToFile = PATH + FILE
        var formattedContents:String?
        
        do {
            formattedContents = try String(contentsOfFile: pathToFile, encoding: NSUTF8StringEncoding)
            if(formattedContents != nil){
                formattedContents = formattedContents!
                let fileContents = "[\(formattedContents)]"
                logText.text = fileContents
            } else {
                logText.text = "Empty Log"
            }
            
        } catch {
                logText.text = "Empty Log"
        }
//        let formattedContents = try! String(contentsOfFile: pathToFile, encoding: NSUTF8StringEncoding)
        
//        let fileContents = "[\(formattedContents)]"
  //      logText.text = fileContents
        
    }
    // The data to return for the row and component (column) that's being passed in
    func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return logArray[row]
    }
    
    func JSONString(var str: String) -> String {
        // \b = \u{8}
        // \f = \u{12}
        let insensitive = NSStringCompareOptions.CaseInsensitiveSearch
        str = str
            .stringByReplacingOccurrencesOfString("\"", withString: "\\\"", options: insensitive)
            .stringByReplacingOccurrencesOfString("/", withString: "\\/", options: insensitive)
            .stringByReplacingOccurrencesOfString("\n", withString: "\\n", options: insensitive)
            .stringByReplacingOccurrencesOfString("\u{8}", withString: "\\b", options: insensitive)
            .stringByReplacingOccurrencesOfString("\u{12}", withString: "\\f", options: insensitive)
            .stringByReplacingOccurrencesOfString("\r", withString: "\\r", options: insensitive)
            .stringByReplacingOccurrencesOfString("\t", withString: "\\t", options: insensitive)
        return str;
    }
    
    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        
        switch pickerView.tag{
            case 0:
                print("Selecting log type " + logArray[row])
                type = logArray[row]
            case 1:
                print("Selected log level " + logArray[row])
                level = logArray[row]
            default:
                print("should not happen")
            
        }
    }
    
    @IBAction func sendLogButton(sender: AnyObject) {
        var logger = Logger.getLoggerForName("SampleLogger")
        if(!packageName.text!.isEmpty){
            logger = Logger.getLoggerForName(packageName.text!)
        }
        
        if(capture.enabled){
                Logger.internalSDKLoggingEnabled = true
        } else {
            Logger.internalSDKLoggingEnabled = false
        }
        

        switch level {
            case "debug":
                Logger.logLevelFilter = LogLevel.Debug
            case "info":
                Logger.logLevelFilter = LogLevel.Info
            case "warn":
                Logger.logLevelFilter = LogLevel.Warn
            case "error":
                Logger.logLevelFilter = LogLevel.Error
            case "fatal":
                Logger.logLevelFilter = LogLevel.Fatal
            default:
                Logger.logLevelFilter = LogLevel.Debug
        }
        
        switch type {
            case "debug":
                logger.debug(logMessage.text!)
            case "info":
                logger.info(logMessage.text!)
            case "warn":
                logger.warn(logMessage.text!)
            case "error":
                logger.error(logMessage.text!)
            case "fatal":
                logger.fatal(logMessage.text!)
            default:
                logger.debug(logMessage.text!)
            
        }
        
        
      
    }
    
    
    
    
    @IBAction func crashAppButton(sender: AnyObject){
        let e = NSException(name:"crashApp", reason:"No reason at all just doing it for fun", userInfo:["user":"nana"])
        e.raise()
    }
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.typePicker.delegate = self
        self.typePicker.dataSource = self
        self.typePicker.tag = 0
        
        self.levelPicker.delegate = self
        self.levelPicker.tag = 1
        self.levelPicker.dataSource = self
    }
    
    
    
    

}

{'fraction_non_alphanumeric': 0.08970951205619898, 'fraction_numerical': 0.003607366622365673, 'mean_word_length': 1.8902606310013716, 'pattern_counts': {'":': 22, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '641731', 'n_tokens_mistral': 2984, 'n_tokens_neox': 2816, 'n_words': 722}