-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bf51190
Showing
10 changed files
with
731 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Created by https://www.gitignore.io/api/xcode | ||
|
||
### Xcode ### | ||
# Xcode | ||
# | ||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | ||
|
||
## Build generated | ||
.build/ | ||
build/ | ||
DerivedData | ||
Carthage/ | ||
Packages/ | ||
|
||
## Various settings | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
xcuserdata | ||
|
||
## Other | ||
*.xccheckout | ||
*.moved-aside | ||
*.xcuserstate | ||
*.xcscmblueprint |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 Zewo | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,9 @@ | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Log", | ||
dependencies: [ | ||
.Package(url: "https://github.com/Zewo/File.git", majorVersion: 0, minor: 2), | ||
.Package(url: "https://github.com/Zewo/CLibvenice.git", majorVersion: 0, minor: 2) | ||
] | ||
) |
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,97 @@ | ||
// Log.swift | ||
// | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015 Zewo | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
// SOFTWARE. | ||
|
||
@_exported import File | ||
|
||
public final class Log { | ||
public struct Level: OptionSetType { | ||
public let rawValue: Int32 | ||
|
||
public init(rawValue: Int32) { | ||
self.rawValue = rawValue | ||
} | ||
|
||
public static let Trace = Level(rawValue: 1 << 0) | ||
public static let Debug = Level(rawValue: 1 << 1) | ||
public static let Info = Level(rawValue: 1 << 2) | ||
public static let Warning = Level(rawValue: 1 << 3) | ||
public static let Error = Level(rawValue: 1 << 4) | ||
public static let Fatal = Level(rawValue: 1 << 5) | ||
public static let All = Level(rawValue: ~0) | ||
} | ||
|
||
public var stream: File | ||
public var levels: Level | ||
private let messageChannel = Channel<String>() | ||
private let once = Once() | ||
|
||
public init(stream: File = standardErrorStream, levels: Level = .All) { | ||
self.stream = stream | ||
self.levels = levels | ||
} | ||
|
||
deinit { | ||
messageChannel.close() | ||
} | ||
|
||
public func log(level: Level, item: Any, terminator: String = "\n", flush: Bool = true) { | ||
if levels.contains(level) { | ||
once.runInBackground { | ||
for message in self.messageChannel { | ||
do { | ||
try self.stream.write(message) | ||
} catch { | ||
print("Log error: \(error)") | ||
print("Log message: \(message)") | ||
} | ||
} | ||
} | ||
messageChannel.send(String(item) + terminator) | ||
} | ||
} | ||
|
||
public func trace(item: Any, terminator: String = "\n", flush: Bool = true) { | ||
log(.Trace, item: item, terminator: terminator, flush: flush) | ||
} | ||
|
||
public func debug(item: Any, terminator: String = "\n", flush: Bool = true) { | ||
log(.Debug, item: item, terminator: terminator, flush: flush) | ||
} | ||
|
||
public func info(item: Any, terminator: String = "\n", flush: Bool = true) { | ||
log(.Info, item: item, terminator: terminator, flush: flush) | ||
} | ||
|
||
public func warning(item: Any, terminator: String = "\n", flush: Bool = true) { | ||
log(.Warning, item: item, terminator: terminator, flush: flush) | ||
} | ||
|
||
public func error(item: Any, terminator: String = "\n", flush: Bool = true) { | ||
log(.Error, item: item, terminator: terminator, flush: flush) | ||
} | ||
|
||
public func fatal(item: Any, terminator: String = "\n", flush: Bool = true) { | ||
log(.Fatal, item: item, terminator: terminator, flush: flush) | ||
} | ||
} |
Oops, something went wrong.