Skip to content

Commit

Permalink
Fixed the log directory issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
vigneshuvi committed Jan 23, 2018
1 parent 002d91f commit 17345ff
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Examples/SampleSwift/SampleSwift/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 18 additions & 1 deletion Sources/Loggly.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion SwiftLoggly.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
37 changes: 37 additions & 0 deletions SwiftLogglyOSXTests/SwiftLogglyOSXTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions SwiftLogglyTests/SwiftLogglyTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -55,9 +58,6 @@ class SwiftLogglyTests: XCTestCase {


loggly(LogType.Info, dictionary: dict)



}

func testPerformanceExample() {
Expand Down

0 comments on commit 17345ff

Please sign in to comment.