Low level logging. To use only for very big messages, otherwise * serverLog() is to prefer. */
| 1126 | /* Low level logging. To use only for very big messages, otherwise |
| 1127 | * serverLog() is to prefer. */ |
| 1128 | void serverLogRaw(int level, const char *msg) { |
| 1129 | const int syslogLevelMap[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE, LOG_WARNING }; |
| 1130 | const char *c = ".-*#"; |
| 1131 | FILE *fp; |
| 1132 | char buf[64]; |
| 1133 | int rawmode = (level & LL_RAW); |
| 1134 | int log_to_stdout = server.logfile[0] == '\0'; |
| 1135 | |
| 1136 | level &= 0xff; /* clear flags */ |
| 1137 | if (level < server.verbosity) return; |
| 1138 | |
| 1139 | fp = log_to_stdout ? stdout : fopen(server.logfile,"a"); |
| 1140 | if (!fp) return; |
| 1141 | |
| 1142 | if (rawmode) { |
| 1143 | fprintf(fp,"%s",msg); |
| 1144 | } else { |
| 1145 | int off; |
| 1146 | struct timeval tv; |
| 1147 | int role_char; |
| 1148 | pid_t pid = getpid(); |
| 1149 | |
| 1150 | gettimeofday(&tv,NULL); |
| 1151 | struct tm tm; |
| 1152 | nolocks_localtime(&tm,tv.tv_sec,server.timezone,server.daylight_active); |
| 1153 | off = strftime(buf,sizeof(buf),"%d %b %Y %H:%M:%S.",&tm); |
| 1154 | snprintf(buf+off,sizeof(buf)-off,"%03d",(int)tv.tv_usec/1000); |
| 1155 | if (server.sentinel_mode) { |
| 1156 | role_char = 'X'; /* Sentinel. */ |
| 1157 | } else if (pid != server.pid) { |
| 1158 | role_char = 'C'; /* RDB / AOF writing child. */ |
| 1159 | } else { |
| 1160 | role_char = (server.masterhost ? 'S':'M'); /* Slave or Master. */ |
| 1161 | } |
| 1162 | fprintf(fp,"%d:%c %s %c %s\n", |
| 1163 | (int)getpid(),role_char, buf,c[level],msg); |
| 1164 | } |
| 1165 | fflush(fp); |
| 1166 | |
| 1167 | if (!log_to_stdout) fclose(fp); |
| 1168 | if (server.syslog_enabled) syslog(syslogLevelMap[level], "%s", msg); |
| 1169 | } |
| 1170 | |
| 1171 | /* Like serverLogRaw() but with printf-alike support. This is the function that |
| 1172 | * is used across the code. The raw version is only used in order to dump |
no test coverage detected