mirror of https://github.com/yandex/odyssey.git
odissey: distinct error messages
This commit is contained in:
parent
041057b34a
commit
d277fcfdd6
2
src/od.c
2
src/od.c
|
@ -72,10 +72,10 @@ int od_main(od_t *od, int argc, char **argv)
|
|||
if (rc == -1)
|
||||
return 1;
|
||||
}
|
||||
od_log(&od->log, "");
|
||||
rc = od_schemevalidate(&od->scheme, &od->log);
|
||||
if (rc == -1)
|
||||
return 1;
|
||||
od_log(&od->log, "");
|
||||
od_log(&od->log, "ready.");
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -72,28 +72,28 @@ od_configopen(odconfig_t *config, char *file)
|
|||
struct stat st;
|
||||
int rc = lstat(file, &st);
|
||||
if (rc == -1) {
|
||||
od_log(config->log, "error: failed to open config file '%s'",
|
||||
file);
|
||||
od_error(config->log, "failed to open config file '%s'",
|
||||
file);
|
||||
return -1;
|
||||
}
|
||||
char *config_buf = malloc(st.st_size);
|
||||
if (config_buf == NULL) {
|
||||
od_log(config->log, "error: memory allocation error");
|
||||
od_error(config->log, "memory allocation error");
|
||||
return -1;
|
||||
}
|
||||
FILE *f = fopen(file, "r");
|
||||
if (f == NULL) {
|
||||
free(config_buf);
|
||||
od_log(config->log, "error: failed to open config file '%s'",
|
||||
file);
|
||||
od_error(config->log, "failed to open config file '%s'",
|
||||
file);
|
||||
return -1;
|
||||
}
|
||||
rc = fread(config_buf, st.st_size, 1, f);
|
||||
fclose(f);
|
||||
if (rc != 1) {
|
||||
free(config_buf);
|
||||
od_log(config->log, "error: failed to open config file '%s'",
|
||||
file);
|
||||
od_error(config->log, "failed to open config file '%s'",
|
||||
file);
|
||||
return -1;
|
||||
}
|
||||
od_lexopen(&config->lex, od_config_keywords, config_buf,
|
||||
|
@ -119,8 +119,8 @@ od_configerror(odconfig_t *config, odtoken_t *tk, char *fmt, ...)
|
|||
int line = config->lex.line;
|
||||
if (tk)
|
||||
line = tk->line;
|
||||
od_log(config->log, "%s:%d %s\n", config->scheme->config_file,
|
||||
line, msg);
|
||||
od_error(config->log, "%s:%d %s", config->scheme->config_file,
|
||||
line, msg);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
26
src/od_log.c
26
src/od_log.c
|
@ -45,13 +45,12 @@ int od_logclose(odlog_t *l)
|
|||
return rc;
|
||||
}
|
||||
|
||||
int od_log(odlog_t *l, char *fmt, ...)
|
||||
static int
|
||||
od_logv(odlog_t *l, char *prefix, char *fmt, va_list args)
|
||||
{
|
||||
char buffer[512];
|
||||
/* pid */
|
||||
int len = snprintf(buffer, sizeof(buffer), "%d ", l->pid);
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
/* time */
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
|
@ -59,6 +58,9 @@ int od_log(odlog_t *l, char *fmt, ...)
|
|||
localtime(&tv.tv_sec));
|
||||
len += snprintf(buffer + len, sizeof(buffer) - len, "%03d ",
|
||||
(int)tv.tv_usec / 1000);
|
||||
/* message prefix */
|
||||
if (prefix)
|
||||
len += snprintf(buffer + len, sizeof(buffer) - len, "%s", prefix);
|
||||
/* message */
|
||||
len += vsnprintf(buffer + len, sizeof(buffer) - len, fmt, args);
|
||||
va_end(args);
|
||||
|
@ -67,3 +69,21 @@ int od_log(odlog_t *l, char *fmt, ...)
|
|||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int od_log(odlog_t *l, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(l, NULL, fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int od_error(odlog_t *l, char *fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
int rc = od_logv(l, "error: ", fmt, args);
|
||||
va_end(args);
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -17,5 +17,6 @@ int od_loginit(odlog_t*);
|
|||
int od_logopen(odlog_t*, char*);
|
||||
int od_logclose(odlog_t*);
|
||||
int od_log(odlog_t*, char*, ...);
|
||||
int od_error(odlog_t*, char*, ...);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -91,7 +91,7 @@ int od_schemevalidate(odscheme_t *scheme, odlog_t *log)
|
|||
{
|
||||
/* pooling mode */
|
||||
if (scheme->pooling == NULL) {
|
||||
od_log(log, "pooling mode is not set");
|
||||
od_error(log, "pooling mode is not set");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(scheme->pooling, "session") == 0)
|
||||
|
@ -104,13 +104,13 @@ int od_schemevalidate(odscheme_t *scheme, odlog_t *log)
|
|||
scheme->pooling_mode = OD_PTRANSACTION;
|
||||
|
||||
if (scheme->pooling_mode == OD_PUNDEF) {
|
||||
od_log(log, "unknown pooling mode");
|
||||
od_error(log, "unknown pooling mode");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* routing mode */
|
||||
if (scheme->routing == NULL) {
|
||||
od_log(log, "routing mode is not set");
|
||||
od_error(log, "routing mode is not set");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp(scheme->routing, "forward") == 0)
|
||||
|
@ -120,7 +120,7 @@ int od_schemevalidate(odscheme_t *scheme, odlog_t *log)
|
|||
scheme->routing_mode = OD_RROUND_ROBIN;
|
||||
|
||||
if (scheme->routing_mode == OD_RUNDEF) {
|
||||
od_log(log, "unknown routing mode");
|
||||
od_error(log, "unknown routing mode");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -130,7 +130,7 @@ int od_schemevalidate(odscheme_t *scheme, odlog_t *log)
|
|||
|
||||
/* servers */
|
||||
if (od_listempty(&scheme->servers)) {
|
||||
od_log(log, "no servers are defined");
|
||||
od_error(log, "no servers are defined");
|
||||
return -1;
|
||||
}
|
||||
odlist_t *i;
|
||||
|
@ -138,8 +138,8 @@ int od_schemevalidate(odscheme_t *scheme, odlog_t *log)
|
|||
odscheme_server_t *server;
|
||||
server = od_container_of(i, odscheme_server_t, link);
|
||||
if (server->host == NULL) {
|
||||
od_log(log, "server '%s': no host is specified",
|
||||
server->name);
|
||||
od_error(log, "server '%s': no host is specified",
|
||||
server->name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -149,14 +149,14 @@ int od_schemevalidate(odscheme_t *scheme, odlog_t *log)
|
|||
odscheme_route_t *route;
|
||||
route = od_container_of(i, odscheme_route_t, link);
|
||||
if (route->route == NULL) {
|
||||
od_log(log, "route '%s': no route server is specified",
|
||||
route->database);
|
||||
od_error(log, "route '%s': no route server is specified",
|
||||
route->database);
|
||||
return -1;
|
||||
}
|
||||
route->server = od_schemeserver_match(scheme, route->route);
|
||||
if (route->server == NULL) {
|
||||
od_log(log, "route '%s': no route server '%s' found",
|
||||
route->route);
|
||||
od_error(log, "route '%s': no route server '%s' found",
|
||||
route->route);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue