mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Customisable logging levels
This commit is contained in:
parent
74a88ad566
commit
e698738745
@ -35,6 +35,7 @@
|
|||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
#include "prof_autocomplete.h"
|
#include "prof_autocomplete.h"
|
||||||
#include "tinyurl.h"
|
#include "tinyurl.h"
|
||||||
|
#include "log.h"
|
||||||
|
|
||||||
/* command structure
|
/* command structure
|
||||||
* cmd - The actual string of the command
|
* cmd - The actual string of the command
|
||||||
@ -329,6 +330,8 @@ static PAutocomplete commands_ac;
|
|||||||
gboolean
|
gboolean
|
||||||
process_input(char *inp)
|
process_input(char *inp)
|
||||||
{
|
{
|
||||||
|
log_msg(PROF_LEVEL_DEBUG, PROF, "Input recieved: %s", inp);
|
||||||
|
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
|
|
||||||
g_strstrip(inp);
|
g_strstrip(inp);
|
||||||
@ -495,12 +498,18 @@ _cmd_connect(const char * const inp, struct cmd_help_t help)
|
|||||||
inp_block();
|
inp_block();
|
||||||
inp_get_password(passwd);
|
inp_get_password(passwd);
|
||||||
inp_non_block();
|
inp_non_block();
|
||||||
|
|
||||||
|
log_msg(PROF_LEVEL_DEBUG, PROF, "Connecting as %s", lower);
|
||||||
|
|
||||||
conn_status = jabber_connect(lower, passwd);
|
conn_status = jabber_connect(lower, passwd);
|
||||||
if (conn_status == JABBER_CONNECTING)
|
if (conn_status == JABBER_CONNECTING) {
|
||||||
cons_show("Connecting...");
|
cons_show("Connecting...");
|
||||||
if (conn_status == JABBER_DISCONNECTED)
|
log_msg(PROF_LEVEL_DEBUG, PROF, "Connecting...");
|
||||||
|
}
|
||||||
|
if (conn_status == JABBER_DISCONNECTED) {
|
||||||
cons_bad_show("Connection to server failed.");
|
cons_bad_show("Connection to server failed.");
|
||||||
|
log_msg(PROF_LEVEL_DEBUG, PROF, "Connection using %s failed", lower);
|
||||||
|
}
|
||||||
|
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
|
18
src/log.c
18
src/log.c
@ -35,13 +35,24 @@ static GDateTime *dt;
|
|||||||
static log_level_t prof_log_level;
|
static log_level_t prof_log_level;
|
||||||
|
|
||||||
void
|
void
|
||||||
log_msg(log_level_t level, const char * const area, const char * const msg)
|
log_msg(log_level_t level, const char * const area, const char * const msg, ...)
|
||||||
{
|
{
|
||||||
if (level >= prof_log_level) {
|
if (level >= prof_log_level) {
|
||||||
dt = g_date_time_new_now(tz);
|
dt = g_date_time_new_now(tz);
|
||||||
|
|
||||||
|
va_list arg;
|
||||||
|
va_start(arg, msg);
|
||||||
|
GString *msg_formatted = g_string_new(NULL);
|
||||||
|
g_string_vprintf(msg_formatted, msg, arg);
|
||||||
|
va_end(arg);
|
||||||
|
|
||||||
gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S");
|
gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S");
|
||||||
fprintf(logp, "%s: %s: %s\n", date_fmt, area, msg);
|
fprintf(logp, "%s: %s: %s\n", date_fmt, area, msg_formatted->str);
|
||||||
g_date_time_unref(dt);
|
g_date_time_unref(dt);
|
||||||
|
g_string_free(msg_formatted, TRUE);
|
||||||
|
|
||||||
|
fflush(logp);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +67,6 @@ log_init(log_level_t log_level)
|
|||||||
g_string_append(log_file, "/profanity.log");
|
g_string_append(log_file, "/profanity.log");
|
||||||
logp = fopen(log_file->str, "a");
|
logp = fopen(log_file->str, "a");
|
||||||
g_string_free(log_file, TRUE);
|
g_string_free(log_file, TRUE);
|
||||||
log_msg(PROF_LEVEL_INFO, PROF, "Starting Profanity...");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
log_level_t
|
log_level_t
|
||||||
|
@ -38,7 +38,8 @@ typedef enum {
|
|||||||
} log_level_t;
|
} log_level_t;
|
||||||
|
|
||||||
void log_init(log_level_t log_level);
|
void log_init(log_level_t log_level);
|
||||||
void log_msg(log_level_t level, const char * const area, const char * const msg);
|
void log_msg(log_level_t level, const char * const area,
|
||||||
|
const char * const msg, ...);
|
||||||
log_level_t log_get_level(void);
|
log_level_t log_get_level(void);
|
||||||
void log_close(void);
|
void log_close(void);
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
|
|
||||||
static gboolean disable_tls = FALSE;
|
static gboolean disable_tls = FALSE;
|
||||||
static gboolean version = FALSE;
|
static gboolean version = FALSE;
|
||||||
|
static char *log = "INFO";
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
@ -38,6 +39,7 @@ main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL },
|
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL },
|
||||||
{ "disable-tls", 'd', 0, G_OPTION_ARG_NONE, &disable_tls, "Disable TLS", NULL },
|
{ "disable-tls", 'd', 0, G_OPTION_ARG_NONE, &disable_tls, "Disable TLS", NULL },
|
||||||
|
{ "log",'l', 0, G_OPTION_ARG_STRING, &log, "Set logging levels, DEBUG, INFO (default), WARN, ERROR", "LEVEL" },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -46,7 +48,6 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
context = g_option_context_new(NULL);
|
context = g_option_context_new(NULL);
|
||||||
g_option_context_add_main_entries(context, entries, NULL);
|
g_option_context_add_main_entries(context, entries, NULL);
|
||||||
//g_option_context_add_group(context, gtk_get_option_group (TRUE));
|
|
||||||
if (!g_option_context_parse(context, &argc, &argv, &error)) {
|
if (!g_option_context_parse(context, &argc, &argv, &error)) {
|
||||||
g_print("%s\n", error->message);
|
g_print("%s\n", error->message);
|
||||||
return 1;
|
return 1;
|
||||||
@ -64,7 +65,7 @@ main(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
profanity_init(disable_tls);
|
profanity_init(disable_tls, log);
|
||||||
profanity_run();
|
profanity_run();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "contact_list.h"
|
#include "contact_list.h"
|
||||||
#include "tinyurl.h"
|
#include "tinyurl.h"
|
||||||
|
|
||||||
|
static log_level_t get_log_level(char *log_level);
|
||||||
static void _profanity_shutdown(void);
|
static void _profanity_shutdown(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -69,10 +70,12 @@ profanity_run(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
profanity_init(const int disable_tls)
|
profanity_init(const int disable_tls, char *log_level)
|
||||||
{
|
{
|
||||||
create_config_directory();
|
create_config_directory();
|
||||||
log_init(PROF_LEVEL_DEBUG);
|
log_level_t prof_log_level = get_log_level(log_level);
|
||||||
|
log_init(prof_log_level);
|
||||||
|
log_msg(PROF_LEVEL_INFO, PROF, "Starting Profanity...");
|
||||||
chat_log_init();
|
chat_log_init();
|
||||||
prefs_load();
|
prefs_load();
|
||||||
gui_init();
|
gui_init();
|
||||||
@ -85,9 +88,23 @@ profanity_init(const int disable_tls)
|
|||||||
void
|
void
|
||||||
_profanity_shutdown(void)
|
_profanity_shutdown(void)
|
||||||
{
|
{
|
||||||
|
log_msg(PROF_LEVEL_INFO, PROF, "Profanity is shutting down.");
|
||||||
jabber_disconnect();
|
jabber_disconnect();
|
||||||
gui_close();
|
gui_close();
|
||||||
log_close();
|
log_close();
|
||||||
chat_log_close();
|
chat_log_close();
|
||||||
prefs_close();
|
prefs_close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static log_level_t get_log_level(char *log_level)
|
||||||
|
{
|
||||||
|
if (strcmp(log_level, "DEBUG") == 0) {
|
||||||
|
return PROF_LEVEL_DEBUG;
|
||||||
|
} else if (strcmp(log_level, "INFO") == 0) {
|
||||||
|
return PROF_LEVEL_INFO;
|
||||||
|
} else if (strcmp(log_level, "WARN") == 0) {
|
||||||
|
return PROF_LEVEL_WARN;
|
||||||
|
} else {
|
||||||
|
return PROF_LEVEL_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#ifndef PROFANITY_H
|
#ifndef PROFANITY_H
|
||||||
#define PROFANITY_H
|
#define PROFANITY_H
|
||||||
|
|
||||||
void profanity_init(const int disable_tls);
|
void profanity_init(const int disable_tls, char *log_level);
|
||||||
void profanity_run(void);
|
void profanity_run(void);
|
||||||
void profanity_shutdown(void);
|
void profanity_shutdown(void);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user