Logger
open class Logger: NSObject
Simple single-file logging for Swift 3 Logging to XCode-Console, file (for error-reporting) or remote Web-API
-
Available Log-Message-Levels
See moreDeclaration
Swift
internal enum LogLevel: String
-
Allow logging to XCode-Console
Declaration
Swift
open static var AllowConsoleLog: Bool = true
-
Restrict console-output to these LogLevels
Declaration
Swift
open static var ConsoleLogLevels: [Logger.LogLevel] = [.Trace, .Debug, .Info, .Warning, .Error]
-
Allow logging to logfile
Declaration
Swift
open static var AllowLocalLog: Bool = true
-
Restrict logfile-output to these LogLevels
Declaration
Swift
open static var LocalLogLevels: [Logger.LogLevel] = [.Info, .Warning, .Error]
-
Name of the logfile in the application directory
Declaration
Swift
open static var LocalLogFile: String = "application.log"
-
Allow logging to Remote-Script
Declaration
Swift
open static var AllowRemoteLog: Bool = true
-
Restrict remote-output to these LogLevels
Declaration
Swift
open static var RemoteLogLevels: [Logger.LogLevel] = [.Warning, .Error]
-
URL of the Remote-Script
Declaration
Swift
open static var RemoteLogURL: String = ""
-
Identifyer-String of this session
Declaration
Swift
open static var RemoteIdentifier: String = ""
-
init(allowconsolelog:consoleloglevels:allowlocallog:localloglevels:locallogfile:allowremotelog:remoteloglevels:remotelogurl:remoteidentifier:)
Initialize Logger-Settings directly.
Declaration
Swift
open init(allowconsolelog: Bool = true, consoleloglevels: [Logger.LogLevel] = [.Trace, .Debug, .Info, .Warning, .Error], allowlocallog: Bool = true, localloglevels: [Logger.LogLevel] = [.Info, .Warning, .Error], locallogfile: String = "Application.log", allowremotelog: Bool = false, remoteloglevels: [Logger.LogLevel] = [.Warning, .Error], remotelogurl: String = "", remoteidentifier: String = "")
Parameters
allowconsolelog
Allow logging to XCode-Console
consoleloglevels
Restrict console-output to these LogLevels
allowlocallog
Allow logging to logfile
localloglevels
Restrict logfile-output to these LogLevels
locallogfile
Name of the logfile in the application directory
allowremotelog
Allow logging to Remote-Script
remoteloglevels
Restrict remote-output to these LogLevels
remotelogurl
URL of the Remote-Script
remoteidentifyer
Identifyer-String of this session
-
Log Function-Access as TRACE
Declaration
Swift
open static func access(_ file: String = #file, _ line: Int = #line, _ column: Int = #column, _ function: String = #function)
Parameters
file
Do not declare - passing the file-name along
line
Do not declare - passing the line-number along
column
Do not declare - passing the column-number along
function
Do not declare - passing the function-name along
-
Log Memory-Warning as WARNING
Declaration
Swift
open static func memory( _ file: String = #file, _ line: Int = #line, _ column: Int = #column, _ function: String = #function)
Parameters
file
Do not declare - passing the file-name along
line
Do not declare - passing the line-number along
column
Do not declare - passing the column-number along
function
Do not declare - passing the function-name along
-
Log a message as TRACE
Declaration
Swift
open static func trace(format: String, _ args: CVarArg..., _ file: String = #file, _ line: Int = #line, _ column: Int = #column, _ function: String = #function)
Parameters
format
Format or String of the message
args
Args used in format
file
Do not declare - passing the file-name along
line
Do not declare - passing the line-number along
column
Do not declare - passing the column-number along
function
Do not declare - passing the function-name along
-
Log a message as DEBUG
Declaration
Swift
open static func debug(format: String, _ args: CVarArg..., _ file: String = #file, _ line: Int = #line, _ column: Int = #column, _ function: String = #function)
Parameters
format
Format or String of the message
args
Args used in format
file
Do not declare - passing the file-name along
line
Do not declare - passing the line-number along
column
Do not declare - passing the column-number along
function
Do not declare - passing the function-name along
-
Log a message as INFO
Declaration
Swift
open static func info(format: String, _ args: CVarArg..., _ file: String = #file, _ line: Int = #line, _ column: Int = #column, _ function: String = #function)
Parameters
format
Format or String of the message
args
Args used in format
file
Do not declare - passing the file-name along
line
Do not declare - passing the line-number along
column
Do not declare - passing the column-number along
function
Do not declare - passing the function-name along
-
Log a message as WARNING
Declaration
Swift
open static func warning(format: String, _ args: CVarArg..., _ file: String = #file, _ line: Int = #line, _ column: Int = #column, _ function: String = #function)
Parameters
format
Format or String of the message
args
Args used in format
file
Do not declare - passing the file-name along
line
Do not declare - passing the line-number along
column
Do not declare - passing the column-number along
function
Do not declare - passing the function-name along
-
Log a message as ERROR
Declaration
Swift
open static func error(format: String, _ args: CVarArg..., _ file: String = #file, _ line: Int = #line, _ column: Int = #column, _ function: String = #function)
Parameters
format
Format or String of the message
args
Args used in format
file
Do not declare - passing the file-name along
line
Do not declare - passing the line-number along
column
Do not declare - passing the column-number along
function
Do not declare - passing the function-name along
-
Log an error as ERROR
Declaration
Swift
open static func error(error: Error, _ file: String = #file, _ line: Int = #line, _ column: Int = #column, _ function: String = #function)
Parameters
error
The Error-Object
file
Do not declare - passing the file-name along
line
Do not declare - passing the line-number along
column
Do not declare - passing the column-number along
function
Do not declare - passing the function-name along
-
Return and delete local log
Declaration
Swift
open static func flushLocalLog() -> String
Return Value
The current logfile-content before deletion
-
Remove local logfile
Declaration
Swift
open static func deleteLocalLog()
-
Log data to XCode-Console
Declaration
Swift
private static func consoleline(_ loglevel: Logger.LogLevel, _ timestamp: Date, _ message: String, _ position: String)
Parameters
loglevel
Loge-Level of log-call
timestamp
Synchronized timestamp of log-call
message
Pre-Parsed log-message
position
Pre-Parsed in-code-position of log-call
-
Log data to local file
Declaration
Swift
private static func localline(_ loglevel: Logger.LogLevel, _ timestamp: Date, _ message: String, _ position: String)
Parameters
loglevel
Loge-Level of log-call
timestamp
Synchronized timestamp of log-call
message
Pre-Parsed log-message
position
Pre-Parsed in-code-position of log-call
-
Log data to remote API
Declaration
Swift
private static func remoteline(_ loglevel: Logger.LogLevel, _ timestamp: Date, _ message: String, _ position: String)
Parameters
loglevel
Loge-Level of log-call
timestamp
Synchronized timestamp of log-call
message
Pre-Parsed log-message
position
Pre-Parsed in-code-position of log-call
-
Parse a Date-Object to a String
Declaration
Swift
private static func parseAccurateDate(date: Date) -> String
Parameters
date
The Date-Object to be parsed
Return Value
The String-Representation of date in format yyyy-MM-dd HH:mm:ss.SSS