diff --git a/Log.xcodeproj/project.pbxproj b/Log.xcodeproj/project.pbxproj index 9f94c56..1f747d4 100644 --- a/Log.xcodeproj/project.pbxproj +++ b/Log.xcodeproj/project.pbxproj @@ -391,7 +391,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0720; - LastUpgradeCheck = 0820; + LastUpgradeCheck = 0930; ORGANIZATIONNAME = delba; TargetAttributes = { 6D7C68021C89FBAB005782C9 = { @@ -411,11 +411,11 @@ }; 6DACCA391C89F89D001B63D9 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0930; }; 6DACCA421C89F89E001B63D9 = { CreatedOnToolsVersion = 7.2; - LastSwiftMigration = 0800; + LastSwiftMigration = 0930; }; }; }; @@ -604,14 +604,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -655,14 +663,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -793,6 +809,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.delba.Log-tvOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; TVOS_DEPLOYMENT_TARGET = 9.1; }; name = Debug; @@ -806,6 +823,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = appletvos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; TVOS_DEPLOYMENT_TARGET = 9.1; }; name = Release; @@ -871,6 +889,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.delba.Log-OSXTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; }; name = Debug; }; @@ -887,6 +906,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; }; name = Release; }; @@ -907,7 +927,8 @@ PRODUCT_BUNDLE_IDENTIFIER = io.delba.Log; PRODUCT_NAME = Log; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -929,7 +950,8 @@ PRODUCT_NAME = Log; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -941,7 +963,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "io.delba.Log-iOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -954,7 +977,8 @@ PRODUCT_BUNDLE_IDENTIFIER = "io.delba.Log-iOSTests"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Log.xcodeproj/xcshareddata/xcschemes/Log OSX.xcscheme b/Log.xcodeproj/xcshareddata/xcschemes/Log OSX.xcscheme index 74625de..786458c 100644 --- a/Log.xcodeproj/xcshareddata/xcschemes/Log OSX.xcscheme +++ b/Log.xcodeproj/xcshareddata/xcschemes/Log OSX.xcscheme @@ -1,6 +1,6 @@ String { let text = level.description - - if let color = logger.theme?.colors[level] { - return text.withColor(color) + + if let style = logger.theme.style(for: level) { + + var string = style.emoji + text + + if let color = style.color { + string = string.withColor(color) + } + + return string } - + return text } @@ -239,11 +246,14 @@ private extension Formatter { */ func format(description: String?) -> String { var text = "MEASURE" - - if let color = logger.theme?.colors[.debug] { - text = text.withColor(color) + + if let style = logger.theme.style(for: .debug) { + + text = style.emoji + text + if let color = style.color { + text = text.withColor(color) + } } - if let description = description { text = "\(text) \(description)" } diff --git a/Source/Logger.swift b/Source/Logger.swift index 2e2920b..47fd6f6 100644 --- a/Source/Logger.swift +++ b/Source/Logger.swift @@ -52,7 +52,7 @@ open class Logger { } /// The logger theme. - public var theme: Theme? + public var theme: Theme /// The minimum level of severity. public var minLevel: Level @@ -64,7 +64,7 @@ open class Logger { /// The logger colors public var colors: String { - return theme?.description ?? "" + return theme.description } /// The queue used for logging. @@ -79,7 +79,7 @@ open class Logger { - returns: A newly created logger. */ - public init(formatter: Formatter = .default, theme: Theme? = nil, minLevel: Level = .trace) { + public init(formatter: Formatter = .default, theme: Theme = .emojiHearts, minLevel: Level = .trace) { self.formatter = formatter self.theme = theme self.minLevel = minLevel diff --git a/Source/Theme.swift b/Source/Theme.swift index 221289c..ac4f800 100644 --- a/Source/Theme.swift +++ b/Source/Theme.swift @@ -25,13 +25,56 @@ public class Themes {} public class Theme: Themes { - /// The theme colors. - internal var colors: [Level: String] - + + /// Style object to hold color and emoji for each level. + public struct Style { + + /// Color for the syyle. + public let color: String? + /// Emoji for the style. + public let emoji: String + + /** + Creates and returns a style with the specified color or/and emoji. + + - parameter coloe: The color for the style. + - parameter debug: The emoji for the style. + + - returns: A style with the specified color or/and emoji. + */ + public init(color: String? = nil, emoji: String? = nil) { + + self.color = color + if let emoji = emoji { + self.emoji = emoji + " " + } else { + self.emoji = "" + } + } + } + + /// The theme styles. + private var styles: [Level: Style] + + /** + Returns style for the specified level. + + - parameter level: The level for which style needs to be selected. + + - returns: A style for specific level. + */ + internal func style(for level: Level) -> Style? { + return styles[level] + } + /// The theme textual representation. internal var description: String { - return colors.keys.sorted().map { - $0.description.withColor(colors[$0]!) + return styles.keys.sorted().map { + var string = (styles[$0]?.emoji ?? "") + $0.description + if let color = styles[$0]?.color { + string = string.withColor(color) + } + return string }.joined(separator: " ") } @@ -45,17 +88,49 @@ public class Theme: Themes { - parameter error: The color for the error level. - returns: A theme with the specified colors. + + - note: Deprecated. Use `init( trace: Style, debug: Style, info: Style, warning: Style, error: Style)` instead. */ + @available(*, deprecated) public init(trace: String, debug: String, info: String, warning: String, error: String) { - self.colors = [ - .trace: Theme.formatHex(trace), - .debug: Theme.formatHex(debug), - .info: Theme.formatHex(info), - .warning: Theme.formatHex(warning), - .error: Theme.formatHex(error) + + self.styles = [ + .trace: Style(color: Theme.formatHex(trace)), + .debug: Style(color: Theme.formatHex(debug)), + .info: Style(color: Theme.formatHex(info)), + .warning: Style(color: Theme.formatHex(warning)), + .error: Style(color: Theme.formatHex(error)) ] } - + + /** + Creates and returns a theme with the specified styles. + + - parameter trace: The style for the trace level. + - parameter debug: The style for the debug level. + - parameter info: The style for the info level. + - parameter warning: The style for the warning level. + - parameter error: The style for the error level. + + - returns: A theme with the specified styles. + */ + public init( + trace: Style, + debug: Style, + info: Style, + warning: Style, + error: Style + ) { + + self.styles = [ + .trace: trace, + .debug: debug, + .info: info, + .warning: warning, + .error: error + ] + } + /** Returns a string representation of the hex color.