Skip to content

Commit

Permalink
Added the coloured output for terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
vignesh-kumar-p committed Feb 16, 2017
1 parent a3f3057 commit 4d4fcfc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 39 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Simple way to logging with rich feature framework in Swift.
- Added the emojis for console log.
- Added the rich function for log tracking type.(Info, Verbose, Warnings, Debug, Error)
- Able to get logs count based on each type of log and export as CSV file.
- Support CocoaPods, mac OS, Vapor framework.
- Coloured output log in Terminal for mac OS.
- Support CocoaPods, mac OS and Vapor framework(Swift Package Manager).


## Screenshots
Expand Down Expand Up @@ -118,7 +119,7 @@ Then run:

pod install || pod update

### Add dependencies in Vapor and Installation
### Swift Package Manager for Vapor

You need to add to dependencies in your 'Package.swift' and fetch Swift module using terminal comment.

Expand Down
73 changes: 36 additions & 37 deletions SwiftLoggly/Loggly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,32 +53,33 @@ extension NSDictionary {

//MARK: - Struct for Color Log
struct ColorLog {
static let ESCAPE = "\u{001b}["

static let ESCAPE = "\u{001B}["

static let RESET_FG = ESCAPE + "fg;" // Clear any foreground color
static let RESET_BG = ESCAPE + "bg;" // Clear any background color
static let RESET = ESCAPE + ";" // Clear any foreground or background color
static let RESET = ESCAPE + "0m" // Clear any foreground or background color

static func red<T>(object: T) {
print("\(ESCAPE)fg255,0,0;\(object)\(RESET)")
print("\(ESCAPE)31m\(object)\(RESET)")
}

static func green<T>(object: T) {
print("\(ESCAPE)fg0,255,0;\(object)\(RESET)")
print("\(ESCAPE)32m\(object)\(RESET)")
}

static func blue<T>(object: T) {
print("\(ESCAPE)fg0,0,255;\(object)\(RESET)")
print("\(ESCAPE)34m\(object)\(RESET)")
}

static func yellow<T>(object: T) {
print("\(ESCAPE)fg255,255,0;\(object)\(RESET)")
print("\(ESCAPE)33m\(object)\(RESET)")
}

static func purple<T>(object: T) {
print("\(ESCAPE)fg255,0,255;\(object)\(RESET)")
print("\(ESCAPE)35m\(object)\(RESET)")
}

}

//MARK: - Enumaration for log type
Expand All @@ -92,8 +93,8 @@ public enum LogType {

//MARK: - Loggly Class
open class Loggly {

//MARK: - Log Report Properties
//MARK: - Log Report Properties

//The name of swift loggly report.
var logReportName = "SwiftLogglyReport";
Expand Down Expand Up @@ -160,7 +161,7 @@ open class Loggly {
return logReportName;
}

func loadLogCounts() {
func loadLogCounts() {
if logInfoCount == 0 && logVerboseCount == 0 && logWarnCount == 0 && logDebugCount == 0 && logErrorCount == 0 {
self.loadLogDetails()
}
Expand All @@ -178,23 +179,23 @@ open class Loggly {
let row = dict as! NSDictionary
for key in row.allKeys {
switch (key as! String) {
case "Info":
logInfoCount = (row.object(forKey: key) as! NSString).integerValue;
break
case "Verbose":
logVerboseCount = (row.object(forKey: key) as! NSString).integerValue;
break
case "Warnings":
logWarnCount = (row.object(forKey: key) as! NSString).integerValue;
break
case "Debug":
logDebugCount = (row.object(forKey: key) as! NSString).integerValue;
break
case "Error":
logErrorCount = (row.object(forKey: key) as! NSString).integerValue;
break
default :
break
case "Info":
logInfoCount = (row.object(forKey: key) as! NSString).integerValue;
break
case "Verbose":
logVerboseCount = (row.object(forKey: key) as! NSString).integerValue;
break
case "Warnings":
logWarnCount = (row.object(forKey: key) as! NSString).integerValue;
break
case "Debug":
logDebugCount = (row.object(forKey: key) as! NSString).integerValue;
break
case "Error":
logErrorCount = (row.object(forKey: key) as! NSString).integerValue;
break
default :
break
}

}
Expand Down Expand Up @@ -260,7 +261,7 @@ open class Loggly {
}
return count;
}


// Get the Loggly Info Count
open func getLogInfoCount() -> NSInteger{
Expand Down Expand Up @@ -294,7 +295,7 @@ open class Loggly {
let fileManager = FileManager.default
if fileManager.fileExists(atPath: path) {
return path;
}
}
return "";
}

Expand Down Expand Up @@ -459,9 +460,9 @@ open class Loggly {
case .Info:
logTypeStr = isEmojis ? "💙 Info - " : "Info - ";
case .Verbose:
logTypeStr = isEmojis ? "💜 Verbose - " : "Verbose - ";
logTypeStr = isEmojis ? "💜 Verbose - " : "Verbose - ";
case .Warnings:
logTypeStr = isEmojis ? "💛 Warnings - " : "Warnings - ";
logTypeStr = isEmojis ? "💛 Warnings - " : "Warnings - ";
case .Debug:
logTypeStr = isEmojis ? "💚 Debug - " : "Debug - ";
case .Error:
Expand Down Expand Up @@ -503,8 +504,8 @@ open class Loggly {
fileHandle.seekToEndOfFile()
fileHandle.write(writeText.data(using: String.Encoding.utf8)!)
fileHandle.closeFile()
writeText = "[\(logTypeName(type, isEmojis: true)) \(dateStr)]: \(text)\n"
print(writeText, terminator: "")
writeText = "[\(logTypeName(type, isEmojis: true)) \(dateStr)]: \(text)"
printLog(type, text:writeText)
cleanup()
}
self.increaseLogCount(type);
Expand Down Expand Up @@ -586,7 +587,7 @@ open class Loggly {

///a free function to make writing to the log with Log type
public func getLogglyReportsOutput() -> NSDictionary {
return Loggly.logger.getReportsOutput()
return Loggly.logger.getReportsOutput()
}

// Before logging details it return empty path. Once logging is done. Method return exact report path
Expand Down Expand Up @@ -707,5 +708,3 @@ public func loggly(_ type: LogType, dictionary: Dictionary<AnyHashable, Any>) {
public func loggly(_ type: LogType, dictionary: NSDictionary) {
Loggly.logger.write(type, text: dictionary.jsonString)
}


0 comments on commit 4d4fcfc

Please sign in to comment.