| 194 | | void log_write_rec(LOG_REC *log, const char *str, int level) |
| 195 | | { |
| 196 | | char *colorstr; |
| 197 | | struct tm *tm; |
| 198 | | time_t now; |
| 199 | | int hour, day; |
| 200 | | |
| 201 | | g_return_if_fail(log != NULL);
|
| 202 | | g_return_if_fail(str != NULL);
|
| 203 | | |
| 204 | | if (log->handle == -1) |
| 205 | | return; |
| 206 | | |
| 207 | | now = time(NULL);
|
| 208 | | tm = localtime(&now); |
| 209 | | hour = tm->tm_hour; |
| 210 | | day = tm->tm_mday; |
| 211 | | |
| 212 | | tm = localtime(&log->last); |
| 213 | | day -= tm->tm_mday; |
| 214 | | if (tm->tm_hour != hour) { |
| 215 | | |
| 216 | | log_rotate_check(log); |
| 217 | | } |
| 218 | | |
| 219 | | if (day != 0) { |
| 220 | | |
| 221 | | log_write_timestamp(log->handle, |
| 222 | | settings_get_str("log_day_changed"), |
| 223 | | "\n", now); |
| 224 | | } |
| 225 | | |
| 226 | | log->last = now; |
| 227 | | |
| 228 | | if (log->colorizer == NULL)
|
| 229 | | colorstr = NULL;
|
| 230 | | else |
| 231 | | str = colorstr = log->colorizer(str); |
| 232 | | |
| 233 | | if ((level & MSGLEVEL_LASTLOG) == 0) |
| 234 | | log_write_timestamp(log->handle, log_timestamp, str, now); |
| 235 | | else |
| 236 | | write_buffer(log->handle, str, strlen(str)); |
| 237 | | write_buffer(log->handle, "\n", 1); |
| 238 | | |
| 239 | | signal_emit("log written", 2, log, str); |
| 240 | | |
| 241 | | g_free_not_null(colorstr);
|
| 242 | | } |