Declaration
Declaration
Swift
-public class HeliumStreamLogger<OutputStream: TextOutputStream> : HeliumLogger
+ public class HeliumStreamLogger<OutputStream> : HeliumLogger where OutputStream : TextOutputStream
diff --git a/README.md b/README.md index 035e8e1..ef25c99 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,14 @@ # HeliumLogger -Provides a lightweight Swift logging framework which supports logging to standard output. +Provides a lightweight logging implementation for Swift which logs to standard output. ## Features - Logs output to stdout by default. You can change the output stream, see example usage for [`HeliumStreamLogger.use(_:outputStream:)`](http://ibm-swift.github.io/HeliumLogger/Classes/HeliumStreamLogger.html#use). - Different logging levels such as Warning, Verbose, and Error - Enable/disable color output to terminal +- Enable/disable color output to terminal +- Support for the [IBM-Swift `LoggerAPI`](https://github.com/IBM-Swift/LoggerAPI) and [Swift-log `Logging`](https://github.com/apple/swift-log) logging APIs. ## Usage @@ -48,14 +49,22 @@ Add `HeliumLogger` to your target's dependencies: ``` #### Import packages +To use with LoggerAPI: + ```swift import HeliumLogger import LoggerAPI ``` +To use with swift-log: +```swift +import HeliumLogger +import Logging +``` + #### Initialize HeliumLogger -Initialize an instance of `HeliumLogger`. Set it as the logger used by `LoggerAPI`. +To use HeliumLogger as a logging backend for LoggerAPI: ```swift let logger = HeliumLogger() @@ -67,6 +76,19 @@ or, if you don't need to customize `HeliumLogger`: HeliumLogger.use() ``` +To use HeliumLogger as a logging backend for swift-log: + +```swift +let logger = HeliumLogger() +LoggingSystem.bootstrap(logger.makeLogHandler) +``` + +Or, as a convenience: +```swift +HeliumLogger.bootstrapSwiftLog() +``` + + #### Logging levels You can specify the level of output on initialization. You will see output of that level, and all levels below that. @@ -91,15 +113,17 @@ In this example, the logger will only show messages of type `warning` and `error HeliumLogger.use(.warning) ``` -#### Adjust logging levels at runtime +Note that when HeliumLogger is used in conjunction with swift-log, the logging level is determined by the `Logger`, and HeliumLogger's own logging level is unused. + +#### Adjust logging levels at runtime (LoggerAPI) Calling `HeliumLogger.use(LoggerMessageType)` will set the `LoggerAPI` to use this new HeliumLogger instance. If in a route you detect an error with your application, you could use this to dynamically increase the log level. This new instance will not have any customization which you applied to other instances (see list item 7). -#### Logging messages +#### Logging messages (LoggerAPI) -How to use HeliumLogger to log messages in your application: +How to use HeliumLogger to log messages in your application with LoggerAPI: ```swift Log.verbose("This is a verbose log message.") @@ -145,4 +169,4 @@ We love to talk server-side Swift, and Kitura. Join our [Slack](http://swift-at- ## License -This library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/IBM-Swift/HeliumLogger/blob/master/LICENSE.txt). \ No newline at end of file +This library is licensed under Apache 2.0. Full license text is available in [LICENSE](https://github.com/IBM-Swift/HeliumLogger/blob/master/LICENSE.txt). diff --git a/docs/Classes.html b/docs/Classes.html index 8ca3821..6987445 100644 --- a/docs/Classes.html +++ b/docs/Classes.html @@ -14,6 +14,7 @@
+ @@ -66,11 +67,22 @@Swift
-public class HeliumStreamLogger<OutputStream: TextOutputStream> : HeliumLogger
+ public class HeliumStreamLogger<OutputStream> : HeliumLogger where OutputStream : TextOutputStream
Swift
-public var colored: Bool = false
+ public var colored: Bool
Swift
-public var details: Bool = true
+ public var details: Bool
+
+
+
+
+ includeMetadata
+
+ A Boolean value indicating whether to include SwiftLog metadata in the logging format when a user +logging format is not specified.
+ +Swift
+public var includeMetadata: Bool
+
+
+
+
+ includeLabel
+
+ A Boolean value indicating whether to include SwiftLog label in the logging format when a user +logging format is not specified.
+ +Swift
+public var includeLabel: Bool
-
+
- fullFilePath
+ fullFilePath
Swift
-public var fullFilePath: Bool = false
+ public var fullFilePath: Bool
The user specified logging format, if format
is not nil
.
For example: [(%date)] [(%type)] [(%file):(%line) (%func)] (%msg)
.
For example: [(%date)] [(%label)] [(%type)] [(%file):(%line) (%func)] (%msg)
.
Swift
-public var format: String?
+ public var format: String? { get set }
-
+
- dateFormat
+ dateFormat
Swift
-public var dateFormat: String?
+ public var dateFormat: String? { get set }
Swift
-public var timeZone: TimeZone?
+ public var timeZone: TimeZone? { get set }
-
+
- defaultDateFormat
+ defaultDateFormat
Swift
-public static let defaultDateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
+ public static let defaultDateFormat: String
-
+
+
+ bootstrapSwiftLog(_:)
+
+ A one-time configuration function to bootstrap the SwiftLog logging system
+ using HeliumLogger
as the logging backend.
This bootstraps the SwiftLog logging system with a default
+ HeliumLogger
instance. The default HeliumLogger
instance will
+ be used as the logging backend for SwiftLog.
HeliumLogger.bootstrapSwiftLog()
+
+
+It’s also possible to customize the default HeliumLogger
instance using a configuration closure.
HeliumLogger.bootstrapSwiftLog { heliumLogger in
+ heliumLogger.colored = true
+}
+
+
+ Swift
+public static func bootstrapSwiftLog(_ configure: ((HeliumLogger) -> Void)? = nil)
+
+
+
+ configure
+
+ |
+
+
+
+ An optional closure that may be used to configure the default |
+
+
+
+ makeLogHandler(label:)
+
+ Creates a HeliumLogHandler
instance for use with the SwiftLog logging system.
This may be used to bootstrap the SwiftLog logging system with a
+ HeliumLogger
instance. The HeliumLogger
instance will
+ be used as the logging backend for SwiftLog.
let heliumLogger = HeliumLogger()
+LoggingSystem.bootstrap(heliumLogger.makeLogHandler)
+
+
+ Swift
+public func makeLogHandler(label: String) -> HeliumLogHandler
+
+
+
+ label
+
+ |
+
+
+
+ The label to use for a SwiftLog |
+
+
+
+ makeLogHandler(label:)
+
+ Creates a HeliumLogHandler
instance for use with the SwiftLog logging system.
This may be used to bootstrap the SwiftLog logging system with a default
+ HeliumLogger
instance. The default HeliumLogger
instance will
+ be used as the logging backend for SwiftLog.
LoggingSystem.bootstrap(HeliumLogger.makeLogHandler)
+
+
+ Swift
+public static func makeLogHandler(label: String) -> HeliumLogHandler
+
+
+
+ label
+
+ |
+
+
+
+ The label to use for a SwiftLog |
+
-
+
- isLogging(_:)
+ isLogging(_:)