Skip to content

Add Ability to change log file location #8

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

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 PostgresStORM {
do {
try exec(deleteSQL(self.table(), idName: idname.lowercased()), params: [String(describing: idval)])
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -32,7 +32,7 @@ extension PostgresStORM {
do {
try exec(deleteSQL(self.table(), idName: idname.lowercased()), params: [String(describing: id)])
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -44,7 +44,7 @@ extension PostgresStORM {
do {
try select(whereclause: "\"\(idname.lowercased())\" = $1", params: [id], orderby: [])
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw error
}
}
Expand All @@ -55,7 +55,7 @@ extension PostgresStORM {
do {
try select(whereclause: "\"\(idname.lowercased())\" = $1", params: ["\(idval)"], orderby: [])
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw error
}
}
Expand All @@ -76,7 +76,7 @@ extension PostgresStORM {
do {
try select(whereclause: set.joined(separator: " AND "), params: paramsString, orderby: [idname], cursor: cursor)
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw error
}

Expand All @@ -101,7 +101,7 @@ extension PostgresStORM {
do {
try select(whereclause: set.joined(separator: " AND "), params: paramsString, orderby: [idname], cursor: cursor)
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
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 PostgresStORM {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [String(id)])
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -36,7 +36,7 @@ extension PostgresStORM {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [id])
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand All @@ -49,7 +49,7 @@ extension PostgresStORM {
do {
try exec(deleteSQL(self.table(), idName: idName), params: [id.string])
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/Insert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension PostgresStORM {
do {
return try insert(cols: keys, params: vals)
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -43,7 +43,7 @@ extension PostgresStORM {
do {
return try insert(cols: keys, params: vals)
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -55,7 +55,7 @@ extension PostgresStORM {
do {
return try insert(cols: cols, params: params, idcolumn: idname)
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -80,7 +80,7 @@ extension PostgresStORM {
let response = try exec(str, params: paramString)
return parseRows(response)[0].data[idcolumn.lowercased()]!
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
self.error = StORMError.error("\(error)")
throw error
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/PostgresConnect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ open class PostgresConnect: StORMConnect {
// Connection String
private func connectionString() -> String {
let conn = "postgresql://\(credentials.username.stringByEncodingURL):\(credentials.password.stringByEncodingURL)@\(credentials.host.stringByEncodingURL):\(credentials.port)/\(database.stringByEncodingURL)"
if StORMdebug { LogFile.info("Postgres conn: \(conn)", logFile: "./StORMlog.txt") }
if StORMDebug.active { LogFile.info("Postgres conn: \(conn)", logFile: StORMDebug.location) }
return conn
}

/// Opens the connection
/// If StORMdebug is true, the connection state will be output to console and to ./StORMlog.txt
/// If StORMDebug.active is true, the connection state will be output to console and to StORMDebug.location
public func open() {
let status = server.connectdb(self.connectionString())
if status != .ok {
state = .bad
resultCode = .error("\(server.errorMessage())")
if StORMdebug { LogFile.error("Postgres conn error: \(server.errorMessage())", logFile: "./StORMlog.txt") }
if StORMDebug.active { LogFile.error("Postgres conn error: \(server.errorMessage())", logFile: StORMDebug.location) }
} else {
if StORMdebug { LogFile.info("Postgres conn state: ok", logFile: "./StORMlog.txt") }
if StORMDebug.active { LogFile.info("Postgres conn state: ok", logFile: StORMDebug.location) }
resultCode = .noError
}
}
Expand Down
18 changes: 9 additions & 9 deletions Sources/PostgresStORM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ open class PostgresStORM: 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 All @@ -74,7 +74,7 @@ open class PostgresStORM: StORM, StORMProtocol {

// set exec message
errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines)
if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") }
if StORMDebug.active { LogFile.info("Error msg: \(errorMsg)", logFile: StORMDebug.location) }
if isError() {
thisConnection.server.close()
throw StORMError.error(errorMsg)
Expand Down Expand Up @@ -107,7 +107,7 @@ open class PostgresStORM: StORM, StORMProtocol {

// set exec message
errorMsg = thisConnection.server.errorMessage().trimmingCharacters(in: .whitespacesAndNewlines)
if StORMdebug { LogFile.info("Error msg: \(errorMsg)", logFile: "./StORMlog.txt") }
if StORMDebug.active { LogFile.info("Error msg: \(errorMsg)", logFile: StORMDebug.location) }
if isError() {
thisConnection.server.close()
throw StORMError.error(errorMsg)
Expand Down Expand Up @@ -163,7 +163,7 @@ open class PostgresStORM: StORM, StORMProtocol {
try update(data: asData(1), idName: idname, idValue: idval)
}
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -184,7 +184,7 @@ open class PostgresStORM: StORM, StORMProtocol {
try update(data: asData(1), idName: idname, idValue: idval)
}
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -195,7 +195,7 @@ open class PostgresStORM: StORM, StORMProtocol {
do {
try insert(asData())
} catch {
LogFile.error("Error: \(error)", logFile: "./StORMlog.txt")
LogFile.error("Error: \(error)", logFile: StORMDebug.location)
throw StORMError.error("\(error)")
}
}
Expand All @@ -211,7 +211,7 @@ open class PostgresStORM: StORM, StORMProtocol {
/// Requires the connection to be configured, as well as a valid "table" property to have been set in the class

open func setup(_ str: String = "") 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 @@ -251,13 +251,13 @@ open class PostgresStORM: StORM, StORMProtocol {
let keyComponent = ", CONSTRAINT \(table())_key PRIMARY KEY (\(keyName)) NOT DEFERRABLE INITIALLY IMMEDIATE"

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 @@ -21,7 +21,7 @@ extension PostgresStORM {
return try exec(statement, params: params)
} catch {
if !PostgresConnector.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 @@ -36,7 +36,7 @@ extension PostgresStORM {
return try execRows(statement, params: params)
} catch {
if !PostgresConnector.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 @@ -145,7 +145,7 @@ extension PostgresStORM {

//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 PostgresStORM {
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 PostgresStORM {
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 @@ -33,7 +33,7 @@ extension PostgresStORM {
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