             return nil
         }
     }
+
+    private func createFolder(path: NSURL) {
+        if NSFileManager.defaultManager().fileExistsAtPath(path.path!) {
+            return
+        }
+        
+        do {
+            try NSFileManager.defaultManager().createDirectoryAtURL(path, withIntermediateDirectories: true, attributes: nil)
+        } catch let error as NSError {
+            print("Create logs folder error \(error)")
+        }
+    }
     
     private func makeSureFileExists(atURL: NSURL) {
         if NSFileManager.defaultManager().fileExistsAtPath(atURL.path!) {


public class FileOutput: LogOutput {
    private var fileHandle: NSFileHandle!

    public init() {
        
    }
    
    public func printMessage(message: String) {

        if let handle = fileHandle {
            return handle
        }

        let dir = NSFileManager.defaultManager().URLsForDirectory(saveInDirectory, inDomains: NSSearchPathDomainMask.UserDomainMask).last as NSURL!
        let time = dateFormatter.stringFromDate(NSDate())
        let logsFolder = dir.URLByAppendingPathComponent("Logs")
        createFolder(logsFolder)
        let fileURL = logsFolder.URLByAppendingPathComponent("\(time).txt")
        
        makeSureFileExists(fileURL)
        
