mirror of
https://github.com/wnagrodzki/SwiftLogger.git
synced 2025-04-06 12:31:51 +02:00
Added ConsoleLogger, NullLogger and AgregateLogger
This commit is contained in:
parent
b65fbcee40
commit
9ebabca38b
4 changed files with 139 additions and 0 deletions
|
@ -9,6 +9,9 @@
|
|||
/* Begin PBXBuildFile section */
|
||||
2EBF4B3E2122AA34008E4117 /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B3D2122AA34008E4117 /* Logger.swift */; };
|
||||
2EBF4B452122ACD6008E4117 /* LogStringConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B442122ACD6008E4117 /* LogStringConvertible.swift */; };
|
||||
2EBF4B4A2122AF53008E4117 /* AgregateLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B472122AF53008E4117 /* AgregateLogger.swift */; };
|
||||
2EBF4B4B2122AF53008E4117 /* ConsoleLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B482122AF53008E4117 /* ConsoleLogger.swift */; };
|
||||
2EBF4B4C2122AF53008E4117 /* NullLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2EBF4B492122AF53008E4117 /* NullLogger.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
|
@ -27,6 +30,9 @@
|
|||
2EBF4B3A2122AA34008E4117 /* libLogger.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libLogger.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
2EBF4B3D2122AA34008E4117 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
|
||||
2EBF4B442122ACD6008E4117 /* LogStringConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogStringConvertible.swift; sourceTree = "<group>"; };
|
||||
2EBF4B472122AF53008E4117 /* AgregateLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AgregateLogger.swift; sourceTree = "<group>"; };
|
||||
2EBF4B482122AF53008E4117 /* ConsoleLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConsoleLogger.swift; sourceTree = "<group>"; };
|
||||
2EBF4B492122AF53008E4117 /* NullLogger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NullLogger.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -61,10 +67,21 @@
|
|||
children = (
|
||||
2EBF4B442122ACD6008E4117 /* LogStringConvertible.swift */,
|
||||
2EBF4B3D2122AA34008E4117 /* Logger.swift */,
|
||||
2EBF4B462122AF53008E4117 /* Loggers */,
|
||||
);
|
||||
path = Logger;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
2EBF4B462122AF53008E4117 /* Loggers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
2EBF4B472122AF53008E4117 /* AgregateLogger.swift */,
|
||||
2EBF4B482122AF53008E4117 /* ConsoleLogger.swift */,
|
||||
2EBF4B492122AF53008E4117 /* NullLogger.swift */,
|
||||
);
|
||||
path = Loggers;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
|
@ -122,7 +139,10 @@
|
|||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
2EBF4B4C2122AF53008E4117 /* NullLogger.swift in Sources */,
|
||||
2EBF4B3E2122AA34008E4117 /* Logger.swift in Sources */,
|
||||
2EBF4B4B2122AF53008E4117 /* ConsoleLogger.swift in Sources */,
|
||||
2EBF4B4A2122AF53008E4117 /* AgregateLogger.swift in Sources */,
|
||||
2EBF4B452122ACD6008E4117 /* LogStringConvertible.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
|
|
39
Logger/Loggers/AgregateLogger.swift
Normal file
39
Logger/Loggers/AgregateLogger.swift
Normal file
|
@ -0,0 +1,39 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2018 Wojciech Nagrodzki
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class AgregateLogger: Logger {
|
||||
private let loggers: [Logger]
|
||||
|
||||
public init(loggers: [Logger]) {
|
||||
self.loggers = loggers
|
||||
}
|
||||
|
||||
public func log(time: String, level: LogLevel, location: String, object: String) {
|
||||
for logger in self.loggers {
|
||||
logger.log(time: time, level: level, location: location, object: object)
|
||||
}
|
||||
}
|
||||
}
|
34
Logger/Loggers/ConsoleLogger.swift
Normal file
34
Logger/Loggers/ConsoleLogger.swift
Normal file
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2018 Wojciech Nagrodzki
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public final class ConsoleLogger: Logger {
|
||||
public init() {
|
||||
}
|
||||
|
||||
public func log(time: String, level: LogLevel, location: String, object: String) {
|
||||
print(time + " <" + level.rawValue + "> " + location + " " + object)
|
||||
}
|
||||
}
|
46
Logger/Loggers/NullLogger.swift
Normal file
46
Logger/Loggers/NullLogger.swift
Normal file
|
@ -0,0 +1,46 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2018 Wojciech Nagrodzki
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class NullLogger: Logger {
|
||||
public init() {
|
||||
}
|
||||
|
||||
public func log(time: String, level: LogLevel, location: String, object: String) {
|
||||
// noop
|
||||
}
|
||||
|
||||
public func description(for date: Date) -> String {
|
||||
return ""
|
||||
}
|
||||
|
||||
public func description(for file: String, line: Int, function: String) -> String {
|
||||
return ""
|
||||
}
|
||||
|
||||
public func description(for object: Any) -> String {
|
||||
return ""
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue