Cleanup logging.

Signed-off-by: Jan Vidar Krey <janvidar@extatic.org>
This commit is contained in:
Jan Vidar Krey 2009-03-20 17:40:50 +01:00
parent 998c6c36ce
commit b1f84b5b4a
5 changed files with 38 additions and 22 deletions

View File

@ -491,7 +491,7 @@ struct hub_info* hub_start_service(struct hub_config* config)
return 0;
}
hub_log(log_info, "Starting server, listening on %s:%d...", address_buf, config->server_port);
hub_log(log_info, "Starting " PRODUCT "/" VERSION ", listening on %s:%d...", address_buf, config->server_port);
server_tcp = net_socket_create(af, SOCK_STREAM, IPPROTO_TCP);
if (server_tcp == -1)

View File

@ -19,12 +19,36 @@
#include "uhub.h"
static void log_user_login(struct user* u)
{
const char* credentials_string[] = { "", "link", "guest", "user", "operator", "super", "admin" };
const char* addr = ip_convert_to_string(&u->ipaddr);
hub_log(log_user, "LoginOK %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, credentials_string[u->credentials], u->user_agent);
}
static void log_user_login_error(struct user* u, enum status_message msg)
{
const char* addr = ip_convert_to_string(&u->ipaddr);
const char* message = hub_get_status_message(u->hub, msg);
hub_log(log_user, "LoginError %s/%s %s \"%s\" (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message, u->user_agent);
}
static void log_user_logout(struct user* u, const char* message)
{
const char* addr = ip_convert_to_string(&u->ipaddr);
hub_log(log_user, "Logout %s/%s %s \"%s\" (%s)", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, message);
}
static void log_user_nick_change(struct user* u, const char* nick)
{
const char* addr = ip_convert_to_string(&u->ipaddr);
hub_log(log_user, "NickChange %s/%s %s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, addr, u->id.nick, nick);
}
/* Send MOTD, do logging etc */
void on_login_success(struct user* u)
{
/* Logging - FIXME: Move this to a plugin */
const char* addr = ip_convert_to_string(&u->ipaddr);
const char* credentials_string[] = { "!none!", "link", "guest", "user", "operator", "super", "admin" };
struct timeval timeout = { TIMEOUT_IDLE, 0 };
/* Send user list of all existing users */
@ -36,7 +60,7 @@ void on_login_success(struct user* u)
user_manager_add(u);
/* Print log message */
hub_log(log_user, "Login OK %s/%s \"%s\" [%s] (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, u->id.nick, addr, credentials_string[u->credentials], u->user_agent);
log_user_login(u);
/* Announce new user to all connected users */
if (user_is_logged_in(u))
@ -51,31 +75,24 @@ void on_login_success(struct user* u)
event_add(u->ev_read, &timeout);
}
void on_login_failure(struct user* u, enum status_message msg)
{
const char* addr = ip_convert_to_string(&u->ipaddr);
const char* message = hub_get_status_message(u->hub, msg);
hub_log(log_user, "Login FAIL %s/%s \"%s\" [%s] (%s) \"%s\"", sid_to_string(u->id.sid), u->id.cid, u->id.nick, addr, message, u->user_agent);
log_user_login_error(u, msg);
hub_send_status(u, msg, status_level_fatal);
user_disconnect(u, quit_logon_error);
}
void on_nick_change(struct user* u, const char* nick)
{
if (user_is_logged_in(u))
{
hub_log(log_user, "Nick change %s/%s \"%s\" -> \"%s\"", sid_to_string(u->id.sid), u->id.cid, u->id.nick, nick);
log_user_nick_change(u, nick);
}
}
void on_logout_user(struct user* user)
{
const char* reason = "";
const char* addr;
/* These are used for logging purposes */
switch (user->quit_reason)
@ -90,6 +107,7 @@ void on_logout_user(struct user* user)
case quit_protocol_error: reason = "protocol error"; break;
case quit_logon_error: reason = "login error"; break;
case quit_hub_disabled: reason = "hub disabled"; break;
case quit_ghost_timeout: reason = "ghost"; break;
default:
if (user->hub->status == hub_status_shutdown)
reason = "hub shutdown";
@ -98,10 +116,7 @@ void on_logout_user(struct user* user)
break;
}
addr = ip_convert_to_string(&user->ipaddr);
hub_log(log_user, "Logout %s/%s \"%s\" [%s] (%s)", sid_to_string(user->id.sid), user->id.cid, user->id.nick, addr, reason);
log_user_logout(user, reason);
user->quit_reason = 0;
}

View File

@ -332,7 +332,7 @@ static int check_logged_in(struct user* user, struct adc_message* cmd)
if (lookup1 == lookup2)
{
hub_log(log_debug, "check_logged_in: exact same user is logged in: %s", user->id.nick);
user_disconnect(lookup1, quit_timeout);
user_disconnect(lookup1, quit_ghost_timeout);
return 0;
}
else

View File

@ -177,8 +177,8 @@ void hub_log(int log_verbosity, const char *format, ...)
if (log_verbosity < verbosity)
{
t = time(NULL);
tmp = gmtime(&t);
strftime(timestamp, 32, "%a, %d %b %Y %H:%M:%S +0000", tmp);
tmp = localtime(&t);
strftime(timestamp, 32, "%Y-%m-%d %H:%M:%S %z", tmp);
va_start(args, format);
vsnprintf(logmsg, 1024, format, args);
va_end(args);

View File

@ -68,6 +68,7 @@ enum user_quit_reason
quit_protocol_error = 8, /** Fatal protocol error */
quit_logon_error = 9, /** Unable to login (wrong password, CID/PID, etc) */
quit_hub_disabled = 10, /** Hub is disabled. No new connections allowed */
quit_ghost_timeout = 11, /** The user is a ghost, and trying to login from another connection */
};