| 96 | } |
| 97 | |
| 98 | void logMessage(LogMsgSide side, LogMsgType type, |
| 99 | const PathName& database, |
| 100 | const string& message) |
| 101 | { |
| 102 | const time_t now = time(NULL); |
| 103 | |
| 104 | const auto file = os_utils::fopen(m_filename.c_str(), "a"); |
| 105 | if (file) |
| 106 | { |
| 107 | if (!lock(file)) |
| 108 | { |
| 109 | fclose(file); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | if (m_error) |
| 114 | m_error = false; |
| 115 | |
| 116 | string dbname, text; |
| 117 | |
| 118 | if (database.hasData()) |
| 119 | dbname.printf("Database: %s\n\t", database.c_str()); |
| 120 | |
| 121 | text.printf("\n%s (%s) %s\t%s%s: %s\n", |
| 122 | m_hostname.c_str(), LOG_MSG_SIDES[side], ctime(&now), |
| 123 | dbname.c_str(), LOG_MSG_TYPES[type], message.c_str()); |
| 124 | |
| 125 | fseek(file, 0, SEEK_END); |
| 126 | fputs(text.c_str(), file); |
| 127 | fclose(file); |
| 128 | unlock(); |
| 129 | } |
| 130 | else if (!m_error && !m_error.exchange(true)) |
| 131 | { |
| 132 | gds__log("Failed to open log file \'%s\', errno %d", |
| 133 | m_filename.c_str(), errno); |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | private: |
| 138 | bool lock(FILE* file) |