summaryrefslogtreecommitdiff
path: root/src/plugins/logger/logger-config.c
blob: 3569337c42f1d53e7822e629c63fa1883e678b51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * Copyright (c) 2003-2008 by FlashCode <flashcode@flashtux.org>
 * See README for License detail, AUTHORS for developers list.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/* logger-config.c: logger configuration options */


#include <stdlib.h>
#include <limits.h>

#include "../weechat-plugin.h"
#include "logger.h"
#include "logger-config.h"


struct t_config_file *logger_config_file = NULL;

/* logger config, look section */

struct t_config_option *logger_config_look_backlog;

/* logger config, file section */

struct t_config_option *logger_config_file_auto_log;
struct t_config_option *logger_config_file_name_lower_case;
struct t_config_option *logger_config_file_path;
struct t_config_option *logger_config_file_info_lines;
struct t_config_option *logger_config_file_time_format;


/*
 * logger_config_init: init logger configuration file
 *                     return: 1 if ok, 0 if error
 */

int
logger_config_init ()
{
    struct t_config_section *ptr_section;
    
    logger_config_file = weechat_config_new (LOGGER_CONFIG_NAME,
                                             NULL, NULL);
    if (!logger_config_file)
        return 0;
    
    /* look */
    ptr_section = weechat_config_new_section (logger_config_file, "look",
                                              0, 0,
                                              NULL, NULL, NULL, NULL,
                                              NULL, NULL, NULL, NULL);
    if (!ptr_section)
    {
        weechat_config_free (logger_config_file);
        return 0;
    }
    
    logger_config_look_backlog = weechat_config_new_option (
        logger_config_file, ptr_section,
        "backlog", "integer",
        N_("maximum number of lines to display from log file when creating "
           "new buffer (0 = no backlog)"),
        NULL, 0, INT_MAX, "20", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    
    /* file */
    ptr_section = weechat_config_new_section (logger_config_file, "file",
                                              0, 0,
                                              NULL, NULL, NULL, NULL,
                                              NULL, NULL, NULL, NULL);
    if (!ptr_section)
    {
        weechat_config_free (logger_config_file);
        return 0;
    }
    
    logger_config_file_auto_log = weechat_config_new_option (
        logger_config_file, ptr_section,
        "auto_log", "boolean",
        N_("automatically save content of buffers to files (unless a buffer "
           "disables log)"),
        NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    logger_config_file_name_lower_case = weechat_config_new_option (
        logger_config_file, ptr_section,
        "name_lower_case", "boolean",
        N_("use only lower case for log filenames"),
        NULL, 0, 0, "on", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    logger_config_file_path = weechat_config_new_option (
        logger_config_file, ptr_section,
        "path", "string",
        N_("path for WeeChat log files ('%h' will be replaced by WeeChat "
           "home, ~/.weechat by default)"),
        NULL, 0, 0, "%h/logs/", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    logger_config_file_info_lines = weechat_config_new_option (
        logger_config_file, ptr_section,
        "info_lines", "boolean",
        N_("write information line in log file when log starts or ends for a "
           "buffer"),
        NULL, 0, 0, "off", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    logger_config_file_time_format = weechat_config_new_option (
        logger_config_file, ptr_section,
        "time_format", "string",
        N_("timestamp used in log files (see man strftime for date/time "
           "specifiers)"),
        NULL, 0, 0, "%Y-%m-%d %H:%M:%S", NULL, NULL, NULL, NULL, NULL, NULL, NULL);
    
    return 1;
}

/*
 * logger_config_read: read logger configuration file
 */

int
logger_config_read ()
{
    return weechat_config_read (logger_config_file);
}

/*
 * logger_config_write: write logger configuration file
 */

int
logger_config_write ()
{
    return weechat_config_write (logger_config_file);
}

/*
 * logger_config_free: free logger configuration
 */

void
logger_config_free ()
{
    weechat_config_free (logger_config_file);
}