Skip to content

Commit

Permalink
Merge pull request #1 from insidegui/refactor
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
abdullahselek authored Jan 2, 2017
2 parents 35e8c80 + 7e43931 commit 4e409b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 65 deletions.
8 changes: 0 additions & 8 deletions Lighty-iOSTests/LightyLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ class LightyLoggerTests: XCTestCase {
XCTAssertEqual(dateFormatter.timeStyle, DateFormatter.Style.medium)
}

func testGetAccessoryWithType() {
XCTAssertEqual(logger.getAccessoryWithType(messageType: .verbose), "💜")
XCTAssertEqual(logger.getAccessoryWithType(messageType: .debug), "💙")
XCTAssertEqual(logger.getAccessoryWithType(messageType: .info), "💚")
XCTAssertEqual(logger.getAccessoryWithType(messageType: .warn), "💛")
XCTAssertEqual(logger.getAccessoryWithType(messageType: .error), "❤️")
}

func testLog() {
let mocklogger = MockLightyLogger()
mocklogger.log(type: .error, message: "test")
Expand Down
8 changes: 0 additions & 8 deletions Lighty-macOSTests/LightyLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ class LightyLoggerTests: XCTestCase {
XCTAssertEqual(dateFormatter.dateStyle, DateFormatter.Style.short)
XCTAssertEqual(dateFormatter.timeStyle, DateFormatter.Style.medium)
}

func testGetAccessoryWithType() {
XCTAssertEqual(logger.getAccessoryWithType(messageType: .verbose), "💜")
XCTAssertEqual(logger.getAccessoryWithType(messageType: .debug), "💙")
XCTAssertEqual(logger.getAccessoryWithType(messageType: .info), "💚")
XCTAssertEqual(logger.getAccessoryWithType(messageType: .warn), "💛")
XCTAssertEqual(logger.getAccessoryWithType(messageType: .error), "❤️")
}

func testLog() {
let mocklogger = MockLightyLogger()
Expand Down
65 changes: 16 additions & 49 deletions Sources/LightyLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,16 @@
// SOFTWARE.

import Foundation
#if os(OSX)
import Cocoa
#elseif os(iOS) || os(tvOS)
import UIKit
#endif

/**
Message type for logging
*/
public enum LightyMessageType {
case verbose
case debug
case info
case warn
case error
}

private struct Emoji {
static let Empty = ""
static let Verbose = "💜"
static let Debug = "💙"
static let Info = "💚"
static let Warn = "💛"
static let Error = "❤️"
public enum LightyMessageType: String {
case verbose = "💜"
case debug = "💙"
case info = "💚"
case warn = "💛"
case error = "❤️"
}

/**
Expand Down Expand Up @@ -85,21 +71,6 @@ public class LightyLogger {
return dateFormatter
}

internal func getAccessoryWithType(messageType: LightyMessageType) -> String {
switch messageType {
case .verbose:
return Emoji.Verbose
case .debug:
return Emoji.Debug
case .info:
return Emoji.Info
case .warn:
return Emoji.Warn
case .error:
return Emoji.Error
}
}

/**
Main function print logs
- parameter type: LightyMessageType
Expand All @@ -113,12 +84,13 @@ public class LightyLogger {
file: String = #file,
function: String = #function,
line: Int = #line) {
let fileExtension = file.nsstring.lastPathComponent.nsstring.pathExtension
let fileName = file.nsstring.lastPathComponent.nsstring.deletingPathExtension
let fileUrl = URL(fileURLWithPath: file)
let fileExtension = fileUrl.pathExtension
let fileName = fileUrl.deletingPathExtension().lastPathComponent

let trackedString = "\(fileName).\(fileExtension):\(line) \(function)"
let emoji = getAccessoryWithType(messageType: type)
print(emoji + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + emoji)

print(type.rawValue + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + type.rawValue)
}

/**
Expand All @@ -135,19 +107,14 @@ public class LightyLogger {
function: String = #function,
line: Int = #line) {
#if DEBUG
let fileExtension = file.nsstring.lastPathComponent.nsstring.pathExtension
let fileName = file.nsstring.lastPathComponent.nsstring.deletingPathExtension
let fileUrl = URL(fileURLWithPath: file)
let fileExtension = fileUrl.pathExtension
let fileName = fileUrl.deletingPathExtension().lastPathComponent

let trackedString = "\(fileName).\(fileExtension):\(line) \(function)"
let emoji = getAccessoryWithType(messageType: type)
print(emoji + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + emoji)

print(type.rawValue + " " + dateFormatter.string(from: Date()) + separator + trackedString + separator + message + " " + type.rawValue)
#endif
}

}

private extension String {

var nsstring: NSString { return self as NSString }

}

0 comments on commit 4e409b3

Please sign in to comment.