+//////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //  Log.swift
 //

//  Copyright (c) 2014 Vluxe. All rights reserved.
//
//  Simple logging class.

import Foundation


        return Static.instance
    }
    ///write content to the current log file.
    public func write(text: String) -> NSError? {
        let path = "\(directory)/\(logName(0))"
        var error: NSError?
        text.writeToFile(path, atomically: true, encoding: NSUTF8StringEncoding, error: &error)
        cleanup()
        return error
    }
    ///do the checks and cleanup
    func cleanup() {
        let path = "\(directory)/\(logName(0))"
        let size = fileSize(path)
        let maxSize = maxFileSize*1024
        if size > 0 && size >= maxSize && maxSize > 0 && maxFileCount > 0 {
            rename(0)
            //delete the oldest file
            let deletePath = "\(directory)/\(logName(maxFileCount))"
            let fileManager = NSFileManager.defaultManager()
            fileManager.removeItemAtPath(deletePath, error: nil)
        }
    }
    ///check the size of a file
    func fileSize(path: String) -> Int {
