Skip to content

Commit d9fe4a8

Browse files
committed
✨ Add use debugPrint, dump log
1 parent 85a6561 commit d9fe4a8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+275
-130
lines changed

.gitignore

100644100755
File mode changed.

.travis.yml

100644100755
File mode changed.

EPLogger.podspec

100644100755
+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'EPLogger'
11-
s.version = '1.1.0'
11+
s.version = '1.1.1'
1212
s.summary = 'Just simple Logger'
1313

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

3535
s.homepage = 'https://github.com/ElonPark/EPLogger'
3636
s.screenshots = 'https://user-images.githubusercontent.com/13270453/63907154-59416680-ca55-11e9-888c-3bbc2cde6f68.png',
37-
'https://user-images.githubusercontent.com/13270453/63907156-59416680-ca55-11e9-902c-93602e95c0d3.png'
37+
'https://user-images.githubusercontent.com/13270453/77232955-8c149d00-6be7-11ea-9396-773b36996e98.png'
3838
s.license = { :type => 'MIT', :file => 'LICENSE' }
3939
s.author = { 'Elon' => '[email protected]' }
4040
s.source = { :git => 'https://github.com/ElonPark/EPLogger.git', :tag => s.version.to_s }

EPLogger/Assets/.gitkeep

100644100755
File mode changed.

EPLogger/Classes/.gitkeep

100644100755
File mode changed.

EPLogger/Classes/EPLogger.swift

100644100755
+131-44
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ extension Log {
2626
}
2727

2828
fileprivate func intValue() -> Int {
29-
let _intValue: [Log.Level : Int] = [
30-
.verbose : 0,
31-
.debug : 1,
32-
.info : 2,
33-
.warning : 3,
34-
.error : 4
29+
let _intValue: [Log.Level: Int] = [
30+
.verbose: 0,
31+
.debug: 1,
32+
.info: 2,
33+
.warning: 3,
34+
.error: 4
3535
]
3636

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

4242
extension Log {
4343
public enum FormatType {
44-
/// [Level] Any...
44+
/// [Level] Any...
4545
case short
4646

47-
/// [Level] file:line (funcName) Any...
47+
/// [Level] file:line funcName Any...
4848
case medium
4949

50-
/// Time: [Level] file:line (funcName) Any...
50+
/// Time: [Level] file:line funcName Any...
5151
case long
5252

53-
/// Time: [Level] file:line (funcName) [Thread Name] Any...
53+
/// Time: [Level] file:line funcName [Thread Name] Any...
5454
case full
5555
}
5656
}
@@ -87,59 +87,56 @@ public struct Log {
8787
/// ```swift
8888
/// Log.config(customLevelHeader: [.verbose : "VERBOSE"])
8989
/// log.verbose("Hello, world!")
90-
/// // VERBOSE -> Hello, world!
90+
/// // VERBOSE Hello, world!
9191
/// ```
9292
public private(set) static var customLevelHeader = [Log.Level : String]()
9393

94-
9594
/// Separator
9695
///
96+
/// default is " ▷ "
97+
///
9798
/// ex)
9899
/// ```swift
99100
/// Log.config(separator: " : ")
100101
/// log.verbose("Hello, world!")
101102
/// // 📢 [VERBOSE] : Hello, world!
102103
/// ```
103-
public private(set) static var separator = " -> "
104+
public private(set) static var separator = " "
104105

105106
private init() {}
106-
107-
@available(*, deprecated, message: "setLevel() is will remove next version, use Log.config(level:)")
108-
public static func setLevel( _ config: Log.Level) {
109-
logLevel = config
110-
}
111-
107+
112108
/// Configration
109+
///
113110
/// - Parameters:
114111
/// - level: Log level. default: Log.Level.verbose
115112
/// - customLevelHeader: Custom log level header.
116113
/// - formatType: Log String FormatType. `default`: Log.FormatType.full
117-
/// - separator: Separator String. `default`: " -> "
114+
/// - separator: Separator String. `default`: " "
118115
/// - dateFormat: DateFormatter date fomat string. `default`: yyyy-MM-dd HH:mm:ss.SSS
119116
///
120117
/// ```swift
121118
///
122119
/// // dateFormat
123120
/// Log.config(dateFormat: "yyyy-MM-dd")
124121
/// Log.verbose("This is verbose")
125-
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) [com.apple.main-thread] -> This is verbose
122+
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 method() [com.apple.main-thread] This is verbose
126123
///
127124
/// // formatType
128125
/// Log.config(formatType: .short)
129126
/// Log.verbose("This is verbose")
130-
/// // 📢 [VERBOSE] -> This is verbose
127+
/// // 📢 [VERBOSE] This is verbose
131128
///
132129
/// Log.config(formatType: .medium)
133130
/// Log.verbose("This is verbose")
134-
/// // 📢 [VERBOSE] Code.swift:26 (method()) -> This is verbose
131+
/// // 📢 [VERBOSE] Code.swift:26 (method()) This is verbose
135132
///
136133
/// Log.config(formatType: .long)
137134
/// Log.verbose("This is verbose")
138-
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) -> This is verbose
135+
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) This is verbose
139136
///
140137
/// Log.config(formatType: .full)
141138
/// Log.verbose("This is verbose")
142-
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) [com.apple.main-thread] -> This is verbose
139+
/// // 2019-11-25: 📢 [VERBOSE] Code.swift:26 (method()) [com.apple.main-thread] This is verbose
143140
///
144141
/// // customLevelHeader
145142
/// Log.config(customLevelHeader: [
@@ -150,7 +147,7 @@ public struct Log {
150147
/// .error: "ERROR"
151148
/// ])
152149
/// log.verbose("Hello, world!")
153-
/// // VERBOSE -> Hello, world!
150+
/// // VERBOSE Hello, world!
154151
///
155152
/// // separator
156153
/// Log.config(separator: ": ")
@@ -188,93 +185,183 @@ public struct Log {
188185
case .short:
189186
return "\(level.string)"
190187
case .medium:
191-
return "\(level.string) (\(funcName))"
188+
return "\(level.string) \(funcName)"
192189
case .long:
193-
return "\(time): \(level.string) \(file):\(line) (\(funcName))"
190+
return "\(time): \(level.string) \(file):\(line) \(funcName)"
194191
case .full:
195192
let thread = threadName
196-
return "\(time): \(level.string) \(file):\(line) (\(funcName)) [\(thread)]"
193+
return "\(time): \(level.string) \(file):\(line) \(funcName) [\(thread)]"
197194
}
198195
}
199196

200-
private static func logger(_ level: Log.Level, fileName: String, line: UInt, funcName: String, output: Any) {
197+
private static func logger(
198+
_ level: Log.Level,
199+
fileName: String,
200+
line: UInt,
201+
funcName: String,
202+
useDebugPrint: Bool,
203+
useDump: Bool,
204+
output: Any
205+
) {
201206
#if DEBUG
202207
guard logLevel.intValue() <= level.intValue() else { return }
203-
var logString = Log.logString(
208+
let logString = Log.logString(
204209
level,
205210
fileName: fileName,
206211
line: line,
207212
funcName: funcName
208213
)
209-
214+
210215
internalQueue.sync {
211216
guard let items = output as? [Any] else {
212-
Swift.print(logString + separator + "\(output)")
217+
logPrinter(logString, useDebugPrint, useDump, value: output)
213218
return
214219
}
215220

216221
switch items.count {
217222
case 0:
218223
Swift.print(logString)
219224
case 1:
220-
Swift.print(logString + separator + "\(items[0])")
225+
logPrinter(logString, useDebugPrint, useDump, value: items[0])
221226
default:
222-
logString += "\(separator)\n"
223-
logString += items.map { "\($0)" }
224-
.joined(separator: "\n")
225-
226-
Swift.print(logString)
227+
multipleItemLogPrinter(logString, useDebugPrint, useDump, items: items)
227228
}
228229
}
229230
#endif
230231
}
231232

232-
public static func verbose(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
233+
private static func logPrinter(_ logString: String, _ useDebugPrint: Bool, _ useDump: Bool, value: Any) {
234+
if useDump {
235+
Swift.print("\(logString)\(separator)")
236+
Swift.dump(value, name: name(value), indent: 2)
237+
} else {
238+
Swift.print("\(logString)\(separator)", terminator: "")
239+
if useDebugPrint {
240+
Swift.debugPrint(value)
241+
} else {
242+
Swift.print(value)
243+
}
244+
}
245+
}
246+
247+
private static func multipleItemLogPrinter(
248+
_ logString: String,
249+
_ useDebugPrint: Bool,
250+
_ useDump: Bool,
251+
items: [Any]
252+
) {
253+
if useDump {
254+
Swift.print("\(logString)")
255+
for item in items {
256+
Swift.dump(item, name: name(item), indent: 2)
257+
}
258+
} else {
259+
Swift.print("\(logString)")
260+
for item in items {
261+
if useDebugPrint {
262+
Swift.debugPrint(item)
263+
} else {
264+
Swift.print(item)
265+
}
266+
}
267+
}
268+
}
269+
270+
private static func name(_ value: Any) -> String {
271+
return "\(type(of: value))"
272+
}
273+
274+
public static func verbose(
275+
fileName: String = #file,
276+
line: UInt = #line,
277+
funcName: String = #function,
278+
useDebugPrint: Bool = false,
279+
useDump: Bool = false,
280+
_ output: Any...
281+
) {
233282
logger(
234283
.verbose,
235284
fileName: fileName,
236285
line: line,
237286
funcName: funcName,
287+
useDebugPrint: useDebugPrint,
288+
useDump: useDump,
238289
output: output
239290
)
240291
}
241292

242-
public static func debug(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
293+
public static func debug(
294+
fileName: String = #file,
295+
line: UInt = #line,
296+
funcName: String = #function,
297+
useDebugPrint: Bool = false,
298+
useDump: Bool = false,
299+
_ output: Any...
300+
) {
243301
logger(
244302
.debug,
245303
fileName: fileName,
246304
line: line,
247305
funcName: funcName,
306+
useDebugPrint: useDebugPrint,
307+
useDump: useDump,
248308
output: output
249309
)
250310
}
251311

252-
public static func info(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
312+
public static func info(
313+
fileName: String = #file,
314+
line: UInt = #line,
315+
funcName: String = #function,
316+
useDebugPrint: Bool = false,
317+
useDump: Bool = false,
318+
_ output: Any...
319+
) {
253320
logger(
254321
.info,
255322
fileName: fileName,
256323
line: line,
257324
funcName: funcName,
325+
useDebugPrint: useDebugPrint,
326+
useDump: useDump,
258327
output: output
259328
)
260329
}
261330

262-
public static func warning(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
331+
public static func warning(
332+
fileName: String = #file,
333+
line: UInt = #line,
334+
funcName: String = #function,
335+
useDebugPrint: Bool = false,
336+
useDump: Bool = false,
337+
_ output: Any...
338+
) {
263339
logger(
264340
.warning,
265341
fileName: fileName,
266342
line: line,
267343
funcName: funcName,
344+
useDebugPrint: useDebugPrint,
345+
useDump: useDump,
268346
output: output
269347
)
270348
}
271349

272-
public static func error(fileName: String = #file, line: UInt = #line, funcName: String = #function, _ output: Any...) {
350+
public static func error(
351+
fileName: String = #file,
352+
line: UInt = #line,
353+
funcName: String = #function,
354+
useDebugPrint: Bool = false,
355+
useDump: Bool = false,
356+
_ output: Any...
357+
) {
273358
logger(
274359
.error,
275360
fileName: fileName,
276361
line: line,
277362
funcName: funcName,
363+
useDebugPrint: useDebugPrint,
364+
useDump: useDump,
278365
output: output
279366
)
280367
}

Example/EPLogger.xcodeproj/project.pbxproj

100644100755
+6-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
1616
607FACEC1AFB9204008FA782 /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACEB1AFB9204008FA782 /* Tests.swift */; };
1717
7521D16DFEDE9239F586CFF6 /* Pods_EPLogger_Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 21F113B3A1CE82F24AB56642 /* Pods_EPLogger_Tests.framework */; };
18+
DBFE192324266A8C00C466B4 /* SampleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBFE192224266A8C00C466B4 /* SampleModel.swift */; };
1819
/* End PBXBuildFile section */
1920

2021
/* Begin PBXContainerItemProxy section */
@@ -46,6 +47,7 @@
4647
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
4748
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
4849
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>"; };
50+
DBFE192224266A8C00C466B4 /* SampleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleModel.swift; sourceTree = "<group>"; };
4951
FE8AED9FCB39C4F244D03717 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
5052
/* End PBXFileReference section */
5153

@@ -103,6 +105,7 @@
103105
isa = PBXGroup;
104106
children = (
105107
607FACD51AFB9204008FA782 /* AppDelegate.swift */,
108+
DBFE192224266A8C00C466B4 /* SampleModel.swift */,
106109
607FACD71AFB9204008FA782 /* ViewController.swift */,
107110
607FACD91AFB9204008FA782 /* Main.storyboard */,
108111
607FACDC1AFB9204008FA782 /* Images.xcassets */,
@@ -333,6 +336,7 @@
333336
buildActionMask = 2147483647;
334337
files = (
335338
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */,
339+
DBFE192324266A8C00C466B4 /* SampleModel.swift in Sources */,
336340
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */,
337341
);
338342
runOnlyForDeploymentPostprocessing = 0;
@@ -486,7 +490,7 @@
486490
DEVELOPMENT_TEAM = M77W68G9P5;
487491
INFOPLIST_FILE = EPLogger/Info.plist;
488492
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
489-
MARKETING_VERSION = 1.1.0;
493+
MARKETING_VERSION = 1.1.1;
490494
MODULE_NAME = ExampleApp;
491495
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
492496
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -503,7 +507,7 @@
503507
DEVELOPMENT_TEAM = M77W68G9P5;
504508
INFOPLIST_FILE = EPLogger/Info.plist;
505509
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
506-
MARKETING_VERSION = 1.1.0;
510+
MARKETING_VERSION = 1.1.1;
507511
MODULE_NAME = ExampleApp;
508512
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
509513
PRODUCT_NAME = "$(TARGET_NAME)";

Example/EPLogger.xcodeproj/project.xcworkspace/contents.xcworkspacedata

100644100755
File mode changed.

Example/EPLogger.xcodeproj/xcshareddata/xcschemes/EPLogger-Example.xcscheme

100644100755
File mode changed.

Example/EPLogger.xcworkspace/contents.xcworkspacedata

100644100755
File mode changed.

Example/EPLogger.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist

100644100755
File mode changed.

0 commit comments

Comments
 (0)