Skip to content

Commit

Permalink
- Coloured output log in Terminal for mac OS.
Browse files Browse the repository at this point in the history
- Support CocoaPods, mac OS and Vapor framework(Swift Package Manager).
  • Loading branch information
vignesh-kumar-p committed Feb 16, 2017
1 parent 4d4fcfc commit e5f07cf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 751 deletions.
73 changes: 36 additions & 37 deletions Sources/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)
}


20 changes: 16 additions & 4 deletions SwiftLoggly.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
0B3B6C8B1E3F8B48003AE9C4 /* SwiftLogglyOSX.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3B6C821E3F8B47003AE9C4 /* SwiftLogglyOSX.framework */; };
0B3B6C901E3F8B48003AE9C4 /* SwiftLogglyOSXTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3B6C8F1E3F8B48003AE9C4 /* SwiftLogglyOSXTests.swift */; };
0B3B6C921E3F8B48003AE9C4 /* SwiftLogglyOSX.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B3B6C841E3F8B47003AE9C4 /* SwiftLogglyOSX.h */; settings = {ATTRIBUTES = (Public, ); }; };
0B41130B1E55AA1B00ADEE0F /* Loggly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B41130A1E55AA1B00ADEE0F /* Loggly.swift */; };
0B411B2C1E55C13400ADEE0F /* Loggly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B411B2B1E55C13400ADEE0F /* Loggly.swift */; };
0B411B2D1E55C13400ADEE0F /* Loggly.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B411B2B1E55C13400ADEE0F /* Loggly.swift */; };
0B6915701E4DB54B007C9394 /* SwiftLoggly.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B3B6C001E3F6221003AE9C4 /* SwiftLoggly.h */; };
0B6915781E4DB71F007C9394 /* SwiftLogglyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B6915771E4DB71F007C9394 /* SwiftLogglyTests.swift */; };
0B69157A1E4DB71F007C9394 /* SwiftLoggly.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3B6BFD1E3F6221003AE9C4 /* SwiftLoggly.framework */; };
Expand Down Expand Up @@ -44,7 +45,7 @@
0B3B6C8A1E3F8B48003AE9C4 /* SwiftLogglyOSXTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftLogglyOSXTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
0B3B6C8F1E3F8B48003AE9C4 /* SwiftLogglyOSXTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftLogglyOSXTests.swift; sourceTree = "<group>"; };
0B3B6C911E3F8B48003AE9C4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0B41130A1E55AA1B00ADEE0F /* Loggly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Loggly.swift; sourceTree = "<group>"; };
0B411B2B1E55C13400ADEE0F /* Loggly.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Loggly.swift; sourceTree = "<group>"; };
0B6915751E4DB71F007C9394 /* SwiftLogglyTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftLogglyTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
0B6915771E4DB71F007C9394 /* SwiftLogglyTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftLogglyTests.swift; sourceTree = "<group>"; };
0B6915791E4DB71F007C9394 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -109,7 +110,7 @@
0B3B6BFF1E3F6221003AE9C4 /* SwiftLoggly */ = {
isa = PBXGroup;
children = (
0B41130A1E55AA1B00ADEE0F /* Loggly.swift */,
0B411B2A1E55C13400ADEE0F /* Sources */,
0B3B6C001E3F6221003AE9C4 /* SwiftLoggly.h */,
0B3B6C011E3F6221003AE9C4 /* Info.plist */,
);
Expand All @@ -134,6 +135,14 @@
path = SwiftLogglyOSXTests;
sourceTree = "<group>";
};
0B411B2A1E55C13400ADEE0F /* Sources */ = {
isa = PBXGroup;
children = (
0B411B2B1E55C13400ADEE0F /* Loggly.swift */,
);
path = Sources;
sourceTree = SOURCE_ROOT;
};
0B6915761E4DB71F007C9394 /* SwiftLogglyTests */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -327,14 +336,15 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0B41130B1E55AA1B00ADEE0F /* Loggly.swift in Sources */,
0B411B2C1E55C13400ADEE0F /* Loggly.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
0B3B6C7D1E3F8B47003AE9C4 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0B411B2D1E55C13400ADEE0F /* Loggly.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -578,6 +588,7 @@
0B3B6C971E3F8B48003AE9C4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 7FUQA46NH7;
Expand All @@ -594,6 +605,7 @@
0B3B6C981E3F8B48003AE9C4 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_IDENTITY = "-";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = 7FUQA46NH7;
Expand Down
Loading

0 comments on commit e5f07cf

Please sign in to comment.