mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Moved function to get log dir to log.c
This commit is contained in:
parent
0b4c464919
commit
c58aca5640
@ -32,10 +32,10 @@
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "preferences.h"
|
#include "common.h"
|
||||||
|
|
||||||
#include "files.h"
|
#include "files.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
#include "preferences.h"
|
||||||
#include "tools/autocomplete.h"
|
#include "tools/autocomplete.h"
|
||||||
|
|
||||||
static gchar *prefs_loc;
|
static gchar *prefs_loc;
|
||||||
@ -45,6 +45,7 @@ gint log_maxsize = 0;
|
|||||||
static Autocomplete boolean_choice_ac;
|
static Autocomplete boolean_choice_ac;
|
||||||
|
|
||||||
static void _save_prefs(void);
|
static void _save_prefs(void);
|
||||||
|
static gchar * _get_preferences_file(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
prefs_load(void)
|
prefs_load(void)
|
||||||
@ -52,7 +53,7 @@ prefs_load(void)
|
|||||||
GError *err;
|
GError *err;
|
||||||
|
|
||||||
log_info("Loading preferences");
|
log_info("Loading preferences");
|
||||||
prefs_loc = files_get_preferences_file();
|
prefs_loc = _get_preferences_file();
|
||||||
|
|
||||||
prefs = g_key_file_new();
|
prefs = g_key_file_new();
|
||||||
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS,
|
g_key_file_load_from_file(prefs, prefs_loc, G_KEY_FILE_KEEP_COMMENTS,
|
||||||
@ -453,3 +454,16 @@ _save_prefs(void)
|
|||||||
char *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
|
char *g_prefs_data = g_key_file_to_data(prefs, &g_data_size, NULL);
|
||||||
g_file_set_contents(prefs_loc, g_prefs_data, g_data_size, NULL);
|
g_file_set_contents(prefs_loc, g_prefs_data, g_data_size, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
_get_preferences_file(void)
|
||||||
|
{
|
||||||
|
gchar *xdg_config = xdg_get_config_home();
|
||||||
|
GString *prefs_file = g_string_new(xdg_config);
|
||||||
|
g_string_append(prefs_file, "/profanity/profrc");
|
||||||
|
gchar *result = strdup(prefs_file->str);
|
||||||
|
g_free(xdg_config);
|
||||||
|
g_string_free(prefs_file, TRUE);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
26
src/files.c
26
src/files.c
@ -45,32 +45,6 @@ files_create_directories(void)
|
|||||||
_files_create_themes_directory();
|
_files_create_themes_directory();
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar *
|
|
||||||
files_get_preferences_file(void)
|
|
||||||
{
|
|
||||||
gchar *xdg_config = xdg_get_config_home();
|
|
||||||
GString *prefs_file = g_string_new(xdg_config);
|
|
||||||
g_string_append(prefs_file, "/profanity/profrc");
|
|
||||||
gchar *result = strdup(prefs_file->str);
|
|
||||||
g_free(xdg_config);
|
|
||||||
g_string_free(prefs_file, TRUE);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
gchar *
|
|
||||||
files_get_log_file(void)
|
|
||||||
{
|
|
||||||
gchar *xdg_data = xdg_get_data_home();
|
|
||||||
GString *logfile = g_string_new(xdg_data);
|
|
||||||
g_string_append(logfile, "/profanity/logs/profanity.log");
|
|
||||||
gchar *result = strdup(logfile->str);
|
|
||||||
g_free(xdg_data);
|
|
||||||
g_string_free(logfile, TRUE);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
gchar *
|
gchar *
|
||||||
files_get_accounts_file(void)
|
files_get_accounts_file(void)
|
||||||
{
|
{
|
||||||
|
@ -24,8 +24,6 @@
|
|||||||
#define FILES_H
|
#define FILES_H
|
||||||
|
|
||||||
void files_create_directories(void);
|
void files_create_directories(void);
|
||||||
gchar* files_get_preferences_file(void);
|
|
||||||
gchar* files_get_log_file(void);
|
|
||||||
gchar* files_get_themes_dir(void);
|
gchar* files_get_themes_dir(void);
|
||||||
gchar* files_get_accounts_file(void);
|
gchar* files_get_accounts_file(void);
|
||||||
|
|
||||||
|
20
src/log.c
20
src/log.c
@ -63,7 +63,7 @@ static gboolean _key_equals(void *key1, void *key2);
|
|||||||
static char * _get_log_filename(const char * const other, const char * const login,
|
static char * _get_log_filename(const char * const other, const char * const login,
|
||||||
GDateTime *dt, gboolean create);
|
GDateTime *dt, gboolean create);
|
||||||
static gchar * _get_chatlog_dir(void);
|
static gchar * _get_chatlog_dir(void);
|
||||||
|
static gchar * _get_log_file(void);
|
||||||
static void _rotate_log_file(void);
|
static void _rotate_log_file(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -119,7 +119,7 @@ log_init(log_level_t filter)
|
|||||||
{
|
{
|
||||||
level_filter = filter;
|
level_filter = filter;
|
||||||
tz = g_time_zone_new_local();
|
tz = g_time_zone_new_local();
|
||||||
gchar *log_file = files_get_log_file();
|
gchar *log_file = _get_log_file();
|
||||||
logp = fopen(log_file, "a");
|
logp = fopen(log_file, "a");
|
||||||
g_free(log_file);
|
g_free(log_file);
|
||||||
}
|
}
|
||||||
@ -143,7 +143,7 @@ log_msg(log_level_t level, const char * const area, const char * const msg)
|
|||||||
if (level >= level_filter) {
|
if (level >= level_filter) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int result;
|
int result;
|
||||||
gchar *log_file = files_get_log_file();
|
gchar *log_file = _get_log_file();
|
||||||
dt = g_date_time_new_now(tz);
|
dt = g_date_time_new_now(tz);
|
||||||
|
|
||||||
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");
|
||||||
@ -165,7 +165,7 @@ log_msg(log_level_t level, const char * const area, const char * const msg)
|
|||||||
static void
|
static void
|
||||||
_rotate_log_file(void)
|
_rotate_log_file(void)
|
||||||
{
|
{
|
||||||
gchar *log_file = files_get_log_file();
|
gchar *log_file = _get_log_file();
|
||||||
size_t len = strlen(log_file);
|
size_t len = strlen(log_file);
|
||||||
char *log_file_new = malloc(len + 3);
|
char *log_file_new = malloc(len + 3);
|
||||||
|
|
||||||
@ -399,3 +399,15 @@ _get_chatlog_dir(void)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gchar *
|
||||||
|
_get_log_file(void)
|
||||||
|
{
|
||||||
|
gchar *xdg_data = xdg_get_data_home();
|
||||||
|
GString *logfile = g_string_new(xdg_data);
|
||||||
|
g_string_append(logfile, "/profanity/logs/profanity.log");
|
||||||
|
gchar *result = strdup(logfile->str);
|
||||||
|
g_free(xdg_data);
|
||||||
|
g_string_free(logfile, TRUE);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user