MCPcopy Create free account
hub / github.com/MariaDB/server / write_log

Function write_log

plugin/server_audit/server_audit.cc:1105–1158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1103*/
1104
1105static int write_log(const char *message, size_t len, time_t ts)
1106{
1107#if defined _WIN32 || !defined SUX_LOCK_GENERIC
1108 DBUG_ASSERT(lock_operations.is_locked_or_waiting());
1109#endif
1110 int result= 0;
1111
1112 if (output_type == OUTPUT_FILE)
1113 {
1114 if (logfile)
1115 {
1116 MYSQL_TIME ltime;
1117 thd_gmt_sec_to_TIME(NULL, &ltime, ts);
1118
1119 size_t ts_len= 0;
1120 char *ts_start= (char *) message - TIMESTAMP_OUTPUT_LENGTH;
1121
1122 /*
1123 Format the timestamp into the start of the gap. We use
1124 TIMESTAMP_OUTPUT_LENGTH - 1 as the limit to ensure there is always at
1125 least one byte available at the end of the gap for the trailing comma,
1126 even if the formatted timestamp takes up the maximum allowed space
1127 (including its null terminator).
1128 */
1129 thd_TIME_to_str(NULL, &ltime, timestamp_format_buffer,
1130 ts_start, TIMESTAMP_OUTPUT_LENGTH - 1);
1131 ts_len= strlen(ts_start);
1132
1133 /* Append a comma as the CSV field separator. */
1134 ts_start[ts_len++]= ',';
1135 ts_start[ts_len]= 0;
1136
1137 if (ts_len > 0 && ts_len < TIMESTAMP_OUTPUT_LENGTH)
1138 memmove((char *) message - ts_len, ts_start, ts_len);
1139
1140 char *final_message= (char *) message - ts_len;
1141 size_t final_len= len + ts_len;
1142
1143 if (!(is_active= (logger_write(logfile, final_message, final_len) == (int) final_len)))
1144 {
1145 ++log_write_failures;
1146 result= 1;
1147 }
1148 }
1149 }
1150 else if (output_type == OUTPUT_SYSLOG)
1151 {
1152 syslog(syslog_facility_codes[syslog_facility] |
1153 syslog_priority_codes[syslog_priority],
1154 "%s %.*s", syslog_info, (int) len, message);
1155 }
1156
1157 return result;
1158}
1159
1160/**
1161 Write to the log, acquiring the lock.

Callers 2

write_log_and_lockFunction · 0.85
write_log_maybe_lockFunction · 0.85

Calls 4

thd_gmt_sec_to_TIMEFunction · 0.85
thd_TIME_to_strFunction · 0.85
logger_writeFunction · 0.85
is_locked_or_waitingMethod · 0.45

Tested by

no test coverage detected