Skip to content

Commit

Permalink
🎨 change useDebugPrint, useDump parameter to printerType
Browse files Browse the repository at this point in the history
  • Loading branch information
ElonPark committed Apr 5, 2020
1 parent ee3c0f5 commit 34add4b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 63 deletions.
2 changes: 1 addition & 1 deletion EPLogger.podspec
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.3'
s.version = '1.2.3'
s.summary = 'Just simple Logger'

# This description is used to generate tags and improve search results.
Expand Down
92 changes: 49 additions & 43 deletions EPLogger/Classes/EPLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ fileprivate extension DispatchQueue {
return String(validatingUTF8: __dispatch_queue_get_label(nil))
}
}
extension Log {
public enum PrinterType {
/// use `print()`
case `default`

/// use `debugPrint()`
case debug

/// use `dump()`
case dump
}
}

extension Log {
public enum Level: String {
Expand Down Expand Up @@ -80,7 +92,7 @@ public struct Log {
return String(format: "%p", Thread.current)
}
}

/// Custom Level Header
///
/// ex)
Expand Down Expand Up @@ -199,8 +211,7 @@ public struct Log {
fileName: String,
line: UInt,
funcName: String,
useDebugPrint: Bool,
useDump: Bool,
printerType: Log.PrinterType,
output: Any
) {
#if DEBUG
Expand All @@ -214,55 +225,60 @@ public struct Log {

internalQueue.sync {
guard let items = output as? [Any] else {
logPrinter(logString, useDebugPrint, useDump, value: output)
logPrinter(logString, printerType, value: output)
return
}

switch items.count {
case 0:
Swift.print(logString)
case 1:
logPrinter(logString, useDebugPrint, useDump, value: items[0])
logPrinter(logString, printerType, value: items[0])
default:
multipleItemLogPrinter(logString, useDebugPrint, useDump, items: items)
multipleItemLogPrinter(logString, printerType, items: items)
}
}
#endif
}

private static func logPrinter(_ logString: String, _ useDebugPrint: Bool, _ useDump: Bool, value: Any) {
if useDump {
private static func logPrinter(_ logString: String, _ printType: Log.PrinterType, value: Any) {
switch printType {
case .debug:
Swift.print("\(logString)\(separator)", terminator: "")
Swift.debugPrint(value)

case .dump:
Swift.print("\(logString)\(separator)")
Swift.dump(value, name: name(value), indent: 2)
} else {

case .default:
Swift.print("\(logString)\(separator)", terminator: "")
if useDebugPrint {
Swift.debugPrint(value)
} else {
Swift.print(value)
}
Swift.print(value)
}
}

private static func multipleItemLogPrinter(
_ logString: String,
_ useDebugPrint: Bool,
_ useDump: Bool,
_ printType: Log.PrinterType,
items: [Any]
) {
if useDump {
switch printType {
case .debug:
Swift.print("\(logString)")
for item in items {
Swift.debugPrint(item)
}

case .dump:
Swift.print("\(logString)")
for item in items {
Swift.dump(item, name: name(item), indent: 2)
}
} else {

case .default:
Swift.print("\(logString)")
for item in items {
if useDebugPrint {
Swift.debugPrint(item)
} else {
Swift.print(item)
}
Swift.print(item)
}
}
}
Expand All @@ -275,17 +291,15 @@ public struct Log {
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
printBy printerType: Log.PrinterType = .default,
_ output: Any...
) {
logger(
.verbose,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
printerType: printerType,
output: output
)
}
Expand All @@ -294,17 +308,15 @@ public struct Log {
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
printBy printerType: Log.PrinterType = .default,
_ output: Any...
) {
logger(
.debug,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
printerType: printerType,
output: output
)
}
Expand All @@ -313,17 +325,15 @@ public struct Log {
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
printBy printerType: Log.PrinterType = .default,
_ output: Any...
) {
logger(
.info,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
printerType: printerType,
output: output
)
}
Expand All @@ -332,17 +342,15 @@ public struct Log {
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
printBy printerType: Log.PrinterType = .default,
_ output: Any...
) {
logger(
.warning,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
printerType: printerType,
output: output
)
}
Expand All @@ -351,17 +359,15 @@ public struct Log {
fileName: String = #file,
line: UInt = #line,
funcName: String = #function,
useDebugPrint: Bool = false,
useDump: Bool = false,
printBy printerType: Log.PrinterType = .default,
_ output: Any...
) {
logger(
.error,
fileName: fileName,
line: line,
funcName: funcName,
useDebugPrint: useDebugPrint,
useDump: useDump,
printerType: printerType,
output: output
)
}
Expand Down
4 changes: 2 additions & 2 deletions Example/EPLogger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@
DEVELOPMENT_TEAM = M77W68G9P5;
INFOPLIST_FILE = EPLogger/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.1.3;
MARKETING_VERSION = 1.2.3;
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -507,7 +507,7 @@
DEVELOPMENT_TEAM = M77W68G9P5;
INFOPLIST_FILE = EPLogger/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MARKETING_VERSION = 1.1.3;
MARKETING_VERSION = 1.2.3;
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
20 changes: 10 additions & 10 deletions Example/EPLogger/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ final class ViewController: UIViewController {

let text = "Sample String!"
Log.verbose(text)
Log.verbose(useDebugPrint: true, text)
Log.verbose(useDump: true, text)
Log.verbose(printBy: .debug, text)
Log.verbose(printBy: .dump, text)

print("")

let sample = SampleStruct()
Log.debug(sample)
Log.debug(useDebugPrint: true, sample)
Log.debug(useDump: true, sample)
Log.debug(printBy: .debug, sample)
Log.debug(printBy: .dump, sample)

print("")

Log.verbose(StringEnum.normal)
Log.verbose(useDebugPrint: true, StringEnum.vip)
Log.verbose(useDump: true, StringEnum.vvip)
Log.verbose(printBy: .debug, StringEnum.vip)
Log.verbose(printBy: .dump, StringEnum.vvip)

print("")

Log.debug(IntEnum.one)
Log.debug(useDebugPrint: true, IntEnum.one)
Log.debug(useDump: true, IntEnum.two)
Log.debug(printBy: .debug, IntEnum.one)
Log.debug(printBy: .dump, IntEnum.two)
}

private func logItems() {
Expand All @@ -61,8 +61,8 @@ final class ViewController: UIViewController {
let text = "Sample String2!"
let sample = SampleStruct()
Log.verbose(text, sample, StringEnum.vvip, IntEnum.two)
Log.verbose(useDebugPrint: true, text, sample, StringEnum.vvip, IntEnum.two)
Log.verbose(useDump: true, text, sample, StringEnum.vvip, IntEnum.two)
Log.verbose(printBy: .debug, text, sample, StringEnum.vvip, IntEnum.two)
Log.verbose(printBy: .dump, text, sample, StringEnum.vvip, IntEnum.two)
}

private func changeFormat() {
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- EPLogger (1.1.3)
- EPLogger (1.2.3)

DEPENDENCIES:
- EPLogger (from `../`)
Expand All @@ -9,7 +9,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
EPLogger: 930e32636081f0e1804a02997ebb89761d1bcfbc
EPLogger: bb3e393551103894bd1d96bad4556cb54519a32d

PODFILE CHECKSUM: a8631a7901040d7ddac01ffc59b141f98c4bef73

Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/EPLogger.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 34add4b

Please sign in to comment.