Error Logging and SQL statements Tracing

@denisenkom Please review