diff --git a/Examples/SampleSwift/SampleSwift/ViewController.swift b/Examples/SampleSwift/SampleSwift/ViewController.swift index 5be2334..c2e9ba4 100644 --- a/Examples/SampleSwift/SampleSwift/ViewController.swift +++ b/Examples/SampleSwift/SampleSwift/ViewController.swift @@ -19,7 +19,7 @@ class ViewController: UIViewController { // Do any additional setup after loading the view, typically from a nib. let documentsDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] - let logsDirectory = URL(fileURLWithPath: documentsDirectory).appendingPathComponent("logs", isDirectory: true) + let logsDirectory = URL(fileURLWithPath: documentsDirectory).appendingPathComponent("SampleSwift", isDirectory: true) Loggly.logger.directory = logsDirectory.path Loggly.logger.enableEmojis = true loggly(LogType.Info, text: "Welcome to Swift Loggly") diff --git a/Sources/Loggly.swift b/Sources/Loggly.swift index 8c00de0..efacc64 100644 --- a/Sources/Loggly.swift +++ b/Sources/Loggly.swift @@ -141,7 +141,24 @@ public enum LogFormatType { open var maxFileCount = 4; ///The directory in which the log files will be written - open var directory = Loggly.defaultDirectory(); + open var directory : String = Loggly.defaultDirectory() { + didSet { + guard directory.count > 0 else { + print("Error changing logger directory. The value \(directory) is not valid. Using default value instead") + directory = Loggly.defaultDirectory() + return + } + let fileManager = FileManager.default + if !fileManager.fileExists(atPath: directory) { + do { + try fileManager.createDirectory(atPath: directory, withIntermediateDirectories: false, attributes: nil) + } catch _ { + print("Error changing logger directory. The value \(directory) is not valid. Using default value instead") + directory = Loggly.defaultDirectory() + } + } + } + } ///The reportDirectory in which the report files will be written var reportDirectory = Loggly.defaultReportDirectory(); diff --git a/SwiftLoggly.podspec b/SwiftLoggly.podspec index b9c3cf6..bba3ef3 100644 --- a/SwiftLoggly.podspec +++ b/SwiftLoggly.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "SwiftLoggly" - s.version = "1.0.6" + s.version = "1.0.7" s.summary = "Simple way to logging with rich feature framework and written in Swift 3." # This description is used to generate tags and improve search results. diff --git a/SwiftLogglyOSXTests/SwiftLogglyOSXTests.swift b/SwiftLogglyOSXTests/SwiftLogglyOSXTests.swift index 236ed55..41d5790 100644 --- a/SwiftLogglyOSXTests/SwiftLogglyOSXTests.swift +++ b/SwiftLogglyOSXTests/SwiftLogglyOSXTests.swift @@ -24,6 +24,43 @@ class SwiftLogglyOSXTests: XCTestCase { func testExample() { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. + let documentsDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + let logsDirectory = URL(fileURLWithPath: documentsDirectory).appendingPathComponent("vignesh", isDirectory: true) + Loggly.logger.directory = logsDirectory.path + Loggly.logger.enableEmojis = true + Loggly.logger.logFormatType = LogFormatType.Normal + + Loggly.logger.logEncodingType = String.Encoding.utf8; + + loggly(LogType.Info, text: "Welcome to Swift Loggly") + loggly(LogType.Verbose, text: "Fun") + + loggly(LogType.Debug, text: "is") + loggly(LogType.Warnings, text: "Matter") + loggly(LogType.Error, text: "here!!") + + print(getLogglyReportsOutput()); + loggly(LogType.Debug, text: "is") + loggly(LogType.Warnings, text: "Matter") + loggly(LogType.Error, text: "here!!") + + print(getLogglyReportsOutput()); + + loggly(LogType.Debug, text: "is") + loggly(LogType.Warnings, text: "Matter") + loggly(LogType.Error, text: "here!!") + + print(getLogCountBasedonType(LogType.Warnings)); + + let dict:NSMutableDictionary = NSMutableDictionary(); + dict.setValue("Vignesh", forKey: "name") ; + dict.setValue("Senior Engineer",forKey: "Position"); + + + loggly(LogType.Info, dictionary: dict) + + + } func testPerformanceExample() { diff --git a/SwiftLogglyTests/SwiftLogglyTests.swift b/SwiftLogglyTests/SwiftLogglyTests.swift index 3ca9ecc..2583035 100644 --- a/SwiftLogglyTests/SwiftLogglyTests.swift +++ b/SwiftLogglyTests/SwiftLogglyTests.swift @@ -24,6 +24,9 @@ class SwiftLogglyTests: XCTestCase { func testExample() { // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. + let documentsDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] + let logsDirectory = URL(fileURLWithPath: documentsDirectory).appendingPathComponent("vignesh", isDirectory: true) + Loggly.logger.directory = logsDirectory.path Loggly.logger.enableEmojis = true Loggly.logger.logFormatType = LogFormatType.Normal @@ -55,9 +58,6 @@ class SwiftLogglyTests: XCTestCase { loggly(LogType.Info, dictionary: dict) - - - } func testPerformanceExample() {