31 "CREATE TABLE log_entries (seq INTEGER PRIMARY KEY, app_id TEXT, " 32 "timestamp TIMESTAMP, log_stream TEXT, log_level TEXT, filename TEXT, " 33 "line INTEGER, class_name TEXT, object_name TEXT, function_name TEXT, message TEXT)";
35 "INSERT INTO log_entries (app_id, timestamp, log_stream, log_level, " 36 "filename, line, class_name, object_name, function_name, message) " 37 "VALUES (:app_id, :timestamp, :log_stream, :log_level, :filename, " 38 ":line, :class_name, :object_name, :function_name, :message)";
41 : m_db_filename(db_filename),
61 sqlite3_stmt *query_sql = NULL;
67 std::cerr <<
"SQLite log output: Could not open SQLite database " 72 res = sqlite3_prepare_v2(
m_db,
73 "SELECT sql FROM sqlite_master WHERE type='table' AND name='log_entries'",
74 -1, &query_sql, NULL);
77 std::cerr <<
"SQLite log output: Could not check if the log table exists in " 82 res = sqlite3_step(query_sql);
83 if (res == SQLITE_DONE)
85 if (sqlite3_exec(
m_db,
m_create_sql.c_str(), NULL, NULL, &error) != SQLITE_OK)
87 std::cerr <<
"SQLite log output: Could not create the log table: " << error <<
std::endl;
89 sqlite3_finalize(query_sql);
94 sqlite3_finalize(query_sql);
101 std::cerr <<
"SQLite log output: Could not prepare the insert statement: " 108 res = sqlite3_exec(
m_db,
"PRAGMA synchronous=OFF", NULL, NULL, &error);
109 if (res != SQLITE_OK)
111 std::cerr <<
"SQLite log output: Could not set PRAGMA synchronous=OFF: " << error <<
std::endl;
115 res = sqlite3_exec(
m_db,
"PRAGMA temp_store=MEMORY", NULL, NULL, &error);
116 if (res != SQLITE_OK)
118 std::cerr <<
"SQLite log output: Could not set PRAGMA temp_store=MEMORY: " << error <<
std::endl;
143 const char *log_level,
const char *filename,
144 size_t line,
const char *class_name,
const char *object_name,
145 const char *function_name,
const char *message_text)
169 res = sqlite3_bind_text(
m_insert_stmt, 1, app_id, -1, SQLITE_TRANSIENT);
170 if (res != SQLITE_OK)
172 std::cerr <<
"SQLite log output: Could not bind column 'app_id': " 175 res = sqlite3_bind_text(
m_insert_stmt, 2, timestamp, -1, SQLITE_TRANSIENT);
176 if (res != SQLITE_OK)
178 std::cerr <<
"SQLite log output: Could not bind column 'timestamp': " 181 res = sqlite3_bind_text(
m_insert_stmt, 3, log_stream, -1, SQLITE_TRANSIENT);
182 if (res != SQLITE_OK)
184 std::cerr <<
"SQLite log output: Could not bind column 'log_stream': " 187 res = sqlite3_bind_text(
m_insert_stmt, 4, log_level, -1, SQLITE_TRANSIENT);
188 if (res != SQLITE_OK)
190 std::cerr <<
"SQLite log output: Could not bind column 'log_level': " 193 res = sqlite3_bind_text(
m_insert_stmt, 5, filename, -1, SQLITE_TRANSIENT);
194 if (res != SQLITE_OK)
196 std::cerr <<
"SQLite log output: Could not bind column 'filename': " 200 if (res != SQLITE_OK)
202 std::cerr <<
"SQLite log output: Could not bind column 'lin': " 205 res = sqlite3_bind_text(
m_insert_stmt, 7, class_name, -1, SQLITE_TRANSIENT);
206 if (res != SQLITE_OK)
208 std::cerr <<
"SQLite log output: Could not bind column 'class_name': " 211 res = sqlite3_bind_text(
m_insert_stmt, 8, object_name, -1, SQLITE_TRANSIENT);
212 if (res != SQLITE_OK)
214 std::cerr <<
"SQLite log output: Could not bind column 'object_name': " 217 res = sqlite3_bind_text(
m_insert_stmt, 9, function_name, -1, SQLITE_TRANSIENT);
218 if (res != SQLITE_OK)
220 std::cerr <<
"SQLite log output: Could not bind column 'function_name': " 223 res = sqlite3_bind_text(
m_insert_stmt, 10, message_text, -1, SQLITE_TRANSIENT);
224 if (res != SQLITE_OK)
226 std::cerr <<
"SQLite log output: Could not bind column 'message': " 232 if (res != SQLITE_DONE)
234 std::cerr <<
"SQLite log output: Could not insert log line: " static icl_core::String m_create_sql
Represents absolute times.
int64_t days() const
Use this function if you want to express the time in days.
static icl_core::String m_insert_sql
sqlite3_stmt * m_insert_stmt
icl_core::String m_db_filename
SQLiteLogDb(const icl_core::String &db_filename, bool rotate)
void writeLogLine(const char *app_id, const char *timestamp, const char *log_stream, const char *log_level, const char *filename, size_t line, const char *class_name, const char *object_name, const char *function_name, const char *message_text)
ThreadStream & endl(ThreadStream &stream)
int rename(const char *old_filename, const char *new_filename)
void strfTime(char *dest, size_t max_len, const char *format) const
Contains icl_logging::SQLiteLogDb.