Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ability to change log file location #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Sources/Convenience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ extension MySQLStORM {
do {
try exec(deleteSQL(self.table(), idName: idname), params: [String(describing: idval)])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -32,7 +32,7 @@ extension MySQLStORM {
do {
try exec(deleteSQL(self.table(), idName: idname), params: [String(describing: id)])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -44,7 +44,7 @@ extension MySQLStORM {
do {
try select(whereclause: "\(idname) = ?", params: [String(describing: id)], orderby: [])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -56,7 +56,7 @@ extension MySQLStORM {
do {
try select(whereclause: "\(idname) = ?", params: [String(describing: idval)], orderby: [])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -76,7 +76,7 @@ extension MySQLStORM {
do {
try select(whereclause: set.joined(separator: " AND "), params: paramsString, orderby: [idname])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -97,7 +97,7 @@ extension MySQLStORM {
do {
try select(whereclause: set.joined(separator: " AND "), params: paramsString, orderby: [idname])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/Delete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension MySQLStORM {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [String(id)])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -36,7 +36,7 @@ extension MySQLStORM {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [id])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -49,7 +49,7 @@ extension MySQLStORM {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [id.string])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Insert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension MySQLStORM {
do {
return try insert(cols: keys, params: vals)
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -43,7 +43,7 @@ extension MySQLStORM {
do {
return try insert(cols: keys, params: vals)
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -56,7 +56,7 @@ extension MySQLStORM {
do {
return try insert(cols: cols, params: params, idcolumn: idname)
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -72,13 +72,13 @@ extension MySQLStORM {
}
let str = "INSERT INTO \(self.table()) (\(cols.joined(separator: ","))) VALUES(\(substString.joined(separator: ",")))"

if StORMdebug { LogFile.info("insert statement: \(str), params: \(paramString)", logFile: "./StORMlog.txt") }
if StORMDebug.active { LogFile.info("insert statement: \(str), params: \(paramString)", logFile: StORMDebug.location) }

do {
_ = try exec(str, params: paramString, isInsert: true)
return results.insertedID
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/MySQLConnect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ open class MySQLConnect: StORMConnect {

guard status else {
// verify connection success
LogFile.error("MySQL network connection error: \(server.errorMessage())", logFile: "./StORMlog.txt")
LogFile.error("MySQL network connection error: \(server.errorMessage())", logFile: StORMDebug.location)
resultCode = .error(server.errorMessage())
return
}
Expand All @@ -69,7 +69,7 @@ open class MySQLConnect: StORMConnect {

guard status else {
// verify connection success
LogFile.error("MySQL socket connection error: \(server.errorMessage())", logFile: "./StORMlog.txt")
LogFile.error("MySQL socket connection error: \(server.errorMessage())", logFile: StORMDebug.location)
resultCode = .error(server.errorMessage())
return
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/MySQLStORM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ open class MySQLStORM: StORM, StORMProtocol {
}

private func printDebug(_ statement: String, _ params: [String]) {
if StORMdebug { LogFile.debug("StORM Debug: \(statement) : \(params.joined(separator: ", "))", logFile: "./StORMlog.txt") }
if StORMDebug.active { LogFile.debug("StORM Debug: \(statement) : \(params.joined(separator: ", "))", logFile: StORMDebug.location) }
}

// Internal function which executes statements, with parameter binding
Expand Down Expand Up @@ -230,7 +230,7 @@ open class MySQLStORM: StORM, StORMProtocol {
try update(data: asData(1), idName: idname, idValue: idval)
}
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -250,7 +250,7 @@ open class MySQLStORM: StORM, StORMProtocol {
try update(data: asData(1), idName: idname, idValue: idval)
}
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -260,7 +260,7 @@ open class MySQLStORM: StORM, StORMProtocol {
do {
try insert(asData())
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -282,7 +282,7 @@ open class MySQLStORM: StORM, StORMProtocol {
/// - Parameter str: create statement
/// - Parameter defaultTypes: by default it is true so MySQLStORM decides for the type conversion. To be able to provide your own, you need to override the `subscript(key: String) -> String`
open func setup(_ str: String = "", _ useDefaults: Bool? = true) throws {
LogFile.info("Running setup: \(table())", logFile: "./StORMlog.txt")
LogFile.info("Running setup: \(table())", logFile: StORMDebug.location)
var createStatement = str
if str.count == 0 {
var opt = [String]()
Expand Down Expand Up @@ -326,12 +326,12 @@ open class MySQLStORM: StORM, StORMProtocol {
let keyComponent = ", PRIMARY KEY (`\(keyName)`)"

createStatement = "CREATE TABLE IF NOT EXISTS \(table()) (\(opt.joined(separator: ", "))\(keyComponent));"
if StORMdebug { LogFile.info("createStatement: \(createStatement)", logFile: "./StORMlog.txt") }
if StORMDebug.active { LogFile.info("createStatement: \(createStatement)", logFile: StORMDebug.location) }
}
do {
try sql(createStatement, params: [])
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/SQL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension MySQLStORM {
try exec(statement, params: params)
} catch {
if !MySQLConnector.quiet {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
}
self.error = StORMError.error("\(error)")
throw error
Expand All @@ -34,7 +34,7 @@ extension MySQLStORM {
return try execRows(statement, params: params)
} catch {
if !MySQLConnector.quiet {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
}
self.error = StORMError.error("\(error)")
throw error
Expand Down
2 changes: 1 addition & 1 deletion Sources/Select.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ extension MySQLStORM {

//return results
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/Update.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension MySQLStORM {
do {
try exec(str, params: paramsString)
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -54,7 +54,7 @@ extension MySQLStORM {
do {
return try update(cols: keys, params: vals, idName: idName, idValue: idValue)
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Upsert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extension MySQLStORM {
do {
try exec(str, params: paramsString)
} catch {
LogFile.error("Error msg: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error msg: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand Down