-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from czechboy0/feature/lumberjack
Logging into file and console
- Loading branch information
Showing
20 changed files
with
181 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// | ||
// Logging.swift | ||
// Buildasaur | ||
// | ||
// Created by Honza Dvorsky on 12/04/2015. | ||
// Copyright (c) 2015 Honza Dvorsky. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
public protocol Logger { | ||
|
||
func description() -> String | ||
func log(message: String) | ||
} | ||
|
||
public class FileLogger: Logger { | ||
|
||
let filePath: NSURL | ||
let stream: NSOutputStream | ||
|
||
public init(filePath: NSURL) { | ||
self.filePath = filePath | ||
self.stream = NSOutputStream(URL: filePath, append: true)! | ||
self.stream.open() | ||
} | ||
|
||
deinit { | ||
self.stream.close() | ||
} | ||
|
||
public func description() -> String { | ||
return "File logger into file at path \(self.filePath)" | ||
} | ||
|
||
public func log(message: String) { | ||
let data: NSData = "\(message)\n".dataUsingEncoding(NSUTF8StringEncoding)! | ||
self.stream.write(UnsafePointer<UInt8>(data.bytes), maxLength: data.length) | ||
} | ||
} | ||
|
||
public class ConsoleLogger: Logger { | ||
|
||
public init() { | ||
// | ||
} | ||
|
||
public func description() -> String { | ||
return "Console logger" | ||
} | ||
|
||
public func log(message: String) { | ||
println(message) | ||
} | ||
} | ||
|
||
public class Log { | ||
|
||
static private var _loggers = [Logger]() | ||
public class func addLoggers(loggers: [Logger]) { | ||
for i in loggers { | ||
_loggers.append(i) | ||
println("Added logger: \(i)") | ||
} | ||
} | ||
|
||
private class func log(message: String) { | ||
for i in _loggers { | ||
i.log(message) | ||
} | ||
} | ||
|
||
public class func verbose(message: String) { | ||
Log.log("[VERBOSE]: " + message) | ||
} | ||
|
||
public class func info(message: String) { | ||
Log.log("[INFO]: " + message) | ||
} | ||
|
||
public class func error(message: String) { | ||
Log.log("[ERROR]: " + message) | ||
} | ||
|
||
public class func untouched(message: String) { | ||
Log.log(message) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.