Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonPark committed Mar 21, 2020
2 parents 328b958 + d9fe4a8 commit 0f2056d
Show file tree
Hide file tree
Showing 52 changed files with 275 additions and 130 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified .travis.yml
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions EPLogger.podspec
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'EPLogger'
s.version = '1.1.0'
s.version = '1.1.1'
s.summary = 'Just simple Logger'

# This description is used to generate tags and improve search results.
Expand All @@ -34,7 +34,7 @@ Just simple Logger

s.homepage = 'https://github.com/ElonPark/EPLogger'
s.screenshots = 'https://user-images.githubusercontent.com/13270453/63907154-59416680-ca55-11e9-888c-3bbc2cde6f68.png',
'https://user-images.githubusercontent.com/13270453/63907156-59416680-ca55-11e9-902c-93602e95c0d3.png'
'https://user-images.githubusercontent.com/13270453/77232955-8c149d00-6be7-11ea-9396-773b36996e98.png'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Elon' => 'sungwoon.park92@gmail.com' }
s.source = { :git => 'https://github.com/ElonPark/EPLogger.git', :tag => s.version.to_s }
Expand Down
Empty file modified EPLogger/Assets/.gitkeep
100644 → 100755
Empty file.
Empty file modified EPLogger/Classes/.gitkeep
100644 → 100755
Empty file.
175 changes: 131 additions & 44 deletions EPLogger/Classes/EPLogger.swift
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ extension Log {
}

fileprivate func intValue() -> Int {
let _intValue: [Log.Level : Int] = [
.verbose : 0,
.debug : 1,
.info : 2,
.warning : 3,
.error : 4
let _intValue: [Log.Level: Int] = [
.verbose: 0,
.debug: 1,
.info: 2,
.warning: 3,
.error: 4
]

return _intValue[self] ?? 4
Expand All @@ -41,16 +41,16 @@ extension Log {

extension Log {
public enum FormatType {
/// [Level] Any...
/// [Level] Any...
case short

/// [Level] file:line (funcName) Any...
/// [Level] file:line funcName Any...
case medium

/// Time: [Level] file:line (funcName) Any...
/// Time: [Level] file:line funcName Any...
case long

/// Time: [Level] file:line (funcName) [Thread Name] Any...
/// Time: [Level] file:line funcName [Thread Name] Any...
case full
}
}
Expand Down Expand Up @@ -87,59 +87,56 @@ public struct Log {
/// ```swift
/// Log.config(customLevelHeader: [.verbose : "VERBOSE"])
/// log.verbose("Hello, world!")
/// // VERBOSE -> Hello, world!
/// // VERBOSE Hello, world!
/// ```
public private(set) static var customLevelHeader = [Log.Level : String]()


/// Separator
///
/// default is " ▷ "
///
/// ex)
/// ```swift
/// Log.config(separator: " : ")
/// log.verbose("Hello, world!")
/// // 📢 [VERBOSE] : Hello, world!
/// ```
public private(set) static var separator = " -> "
public private(set) static var separator = " "

private init() {}

@available(*, deprecated, message: "setLevel() is will remove next version, use Log.config(level:)")
public static func setLevel( _ config: Log.Level) {
logLevel = config
}


/// Configration
///
/// - Parameters:
/// - level: Log level. default: Log.Level.verbose
/// - customLevelHeader: Custom log level header.
/// - formatType: Log String FormatType. `default`: Log.FormatType.full
/// - separator: Separator String. `default`: " -> "
/// - separator: Separator String. `default`: " "
/// - dateFormat: DateFormatter date fomat string. `default`: yyyy-MM-dd HH:mm:ss.SSS
///
/// ```swift
///
/// // dateFormat
/// Log.config(dateFormat: "yyyy-MM-dd")
/// Log.verbose("This is verbose")
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) [com.apple.main-thread] -> This is verbose
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 method() [com.apple.main-thread] This is verbose
///
/// // formatType
/// Log.config(formatType: .short)
/// Log.verbose("This is verbose")
/// // 📢 [VERBOSE] -> This is verbose
/// // 📢 [VERBOSE] This is verbose
///
/// Log.config(formatType: .medium)
/// Log.verbose("This is verbose")
/// // 📢 [VERBOSE] Code.swift:26 (method()) -> This is verbose
/// // 📢 [VERBOSE] Code.swift:26 (method()) This is verbose
///
/// Log.config(formatType: .long)
/// Log.verbose("This is verbose")
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) -> This is verbose
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) This is verbose
///
/// Log.config(formatType: .full)
/// Log.verbose("This is verbose")
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) [com.apple.main-thread] -> This is verbose
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) [com.apple.main-thread] This is verbose
///
/// // customLevelHeader
/// Log.config(customLevelHeader: [
Expand All @@ -150,7 +147,7 @@ public struct Log {
/// .error: "ERROR"
/// ])
/// log.verbose("Hello, world!")
/// // VERBOSE -> Hello, world!
/// // VERBOSE Hello, world!
///
/// // separator
/// Log.config(separator: ": ")
Expand Down Expand Up @@ -188,93 +185,183 @@ public struct Log {
case .short:
return "\(level.string)"
case .medium:
return "\(level.string) (\(funcName))"
return "\(level.string) \(funcName)"
case .long:
return "\(time): \(level.string) \(file):\(line) (\(funcName))"
return "\(time): \(level.string) \(file):\(line) \(funcName)"
case .full:
let thread = threadName
return "\(time): \(level.string) \(file):\(line) (\(funcName)) [\(thread)]"
return "\(time): \(level.string) \(file):\(line) \(funcName) [\(thread)]"
}
}

private static func logger(_ level: Log.Level, fileName: String, line: UInt, funcName: String, output: Any) {
private static func logger(
_ level: Log.Level,
fileName: String,
line: UInt,
funcName: String,
useDebugPrint: Bool,
useDump: Bool,
output: Any
) {
#if DEBUG
guard logLevel.intValue() <= level.intValue() else { return }
var logString = Log.logString(
let logString = Log.logString(
level,
fileName: fileName,
line: line,
funcName: funcName
)

internalQueue.sync {
guard let items = output as? [Any] else {
Swift.print(logString + separator + "\(output)")
logPrinter(logString, useDebugPrint, useDump, value: output)
return
}

switch items.count {
case 0:
Swift.print(logString)
case 1:
Swift.print(logString + separator + "\(items[0])")
logPrinter(logString, useDebugPrint, useDump, value: items[0])
default:
logString += "\(separator)\n"
logString += items.map { "\($0)" }
.joined(separator: "\n")

Swift.print(logString)
multipleItemLogPrinter(logString, useDebugPrint, useDump, items: items)
}
}
#endif
}

public static func verbose(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
private static func logPrinter(_ logString: String, _ useDebugPrint: Bool, _ useDump: Bool, value: Any) {
if useDump {
Swift.print("\(logString)\(separator)")
Swift.dump(value, name: name(value), indent: 2)
} else {
Swift.print("\(logString)\(separator)", terminator: "")
if useDebugPrint {
Swift.debugPrint(value)
} else {
Swift.print(value)
}
}
}

private static func multipleItemLogPrinter(
_ logString: String,
_ useDebugPrint: Bool,
_ useDump: Bool,
items: [Any]
) {
if useDump {
Swift.print("\(logString)")
for item in items {
Swift.dump(item, name: name(item), indent: 2)
}
} else {
Swift.print("\(logString)")
for item in items {
if useDebugPrint {
Swift.debugPrint(item)
} else {
Swift.print(item)
}
}
}
}

private static func name(_ value: Any) -> String {
return "\(type(of: value))"
}

public static func verbose(
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
_ output: Any...
) {
logger(
.verbose,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
output: output
)
}

public static func debug(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
public static func debug(
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
_ output: Any...
) {
logger(
.debug,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
output: output
)
}

public static func info(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
public static func info(
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
_ output: Any...
) {
logger(
.info,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
output: output
)
}

public static func warning(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
public static func warning(
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
_ output: Any...
) {
logger(
.warning,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
output: output
)
}

public static func error(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
public static func error(
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
_ output: Any...
) {
logger(
.error,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
output: output
)
}
Expand Down
8 changes: 6 additions & 2 deletions Example/EPLogger.xcodeproj/project.pbxproj
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
7521D16DFEDE9239F586CFF6 /* Pods_EPLogger_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F113B3A1CE82F24AB56642 /* Pods_EPLogger_Tests.framework */; };
DBFE192324266A8C00C466B4 /* SampleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBFE192224266A8C00C466B4 /* SampleModel.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -46,6 +47,7 @@
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
DB5314428E299D8C4DFCA4C6 /* Pods-EPLogger_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EPLogger_Example.release.xcconfig"; path = "Target Support Files/Pods-EPLogger_Example/Pods-EPLogger_Example.release.xcconfig"; sourceTree = "<group>"; };
DBFE192224266A8C00C466B4 /* SampleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleModel.swift; sourceTree = "<group>"; };
FE8AED9FCB39C4F244D03717 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -103,6 +105,7 @@
isa = PBXGroup;
children = (
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
DBFE192224266A8C00C466B4 /* SampleModel.swift */,
607FACD71AFB9204008FA782 /* ViewController.swift */,
607FACD91AFB9204008FA782 /* Main.storyboard */,
607FACDC1AFB9204008FA782 /* Images.xcassets */,
Expand Down Expand Up @@ -333,6 +336,7 @@
buildActionMask = 2147483647;
files = (
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
DBFE192324266A8C00C466B4 /* SampleModel.swift in Sources */,
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -486,7 +490,7 @@
DEVELOPMENT_TEAM = M77W68G9P5;
INFOPLIST_FILE = EPLogger/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -503,7 +507,7 @@
DEVELOPMENT_TEAM = M77W68G9P5;
INFOPLIST_FILE = EPLogger/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.1.0;
MARKETING_VERSION = 1.1.1;
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
Empty file.
Empty file.
Empty file modified Example/EPLogger.xcworkspace/contents.xcworkspacedata
100644 → 100755
Empty file.
Empty file.
Loading

0 comments on commit 0f2056d

Please sign in to comment.