-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add Logger and delete print and nslog
- Loading branch information
Pierre jonny cau
committed
May 24, 2018
1 parent
1e20877
commit 3f98157
Showing
5 changed files
with
71 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
LocalNotifications_Over_iOS10/NotificationManager/Helpers/Logger.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// | ||
// Logger.swift | ||
// LocalNotifications_Over_iOS10 | ||
// | ||
// Created by Pierre jonny cau on 24/05/2018. | ||
// Copyright © 2018 Robots and Pencils. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
|
||
// Enum for showing the type of Log Types | ||
enum LogEvent: String { | ||
case error = "[‼️]" // error | ||
case info = "[ℹ️]" // info | ||
case debug = "[💬]" // debug | ||
case verbose = "[🔬]" // verbose | ||
case warning = "[⚠️]" // warning | ||
case severe = "[🔥]" // severe | ||
} | ||
|
||
class Logger { | ||
|
||
static var dateFormat = "yyyy-MM-dd hh:mm:ssSSS" | ||
static var dateFormatter: DateFormatter { | ||
let formatter = DateFormatter() | ||
formatter.dateFormat = dateFormat | ||
formatter.locale = Locale.current | ||
formatter.timeZone = TimeZone.current | ||
return formatter | ||
} | ||
static var enabled = false //default state | ||
|
||
class func log(message: String, | ||
event: LogEvent, | ||
fileName: String = #file, | ||
line: Int = #line, | ||
column: Int = #column, | ||
funcName: String = #function) { | ||
if(!enabled) { | ||
return | ||
} | ||
|
||
#if DEBUG | ||
print("\(Date().toString()) \(event.rawValue)[\(sourceFileName(filePath: fileName))]:\(line) \(column) \(funcName) -> \(message)") | ||
#endif | ||
} | ||
private class func sourceFileName(filePath: String) -> String { | ||
let components = filePath.components(separatedBy: "/") | ||
return components.isEmpty ? "" : components.last! | ||
} | ||
} | ||
|
||
internal extension Date { | ||
func toString() -> String { | ||
return Logger.dateFormatter.string(from: self as Date) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters