NeoMutt  2021-10-22-8-g9cb437
Teaching an old dog new tricks
mutt_logging.h File Reference

NeoMutt Logging. More...

#include <stdbool.h>
#include <stdint.h>
#include <time.h>
#include "mutt/lib.h"
+ Include dependency graph for mutt_logging.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.


int log_disp_curses (time_t stamp, const char *file, int line, const char *function, enum LogLevel level,...)
 Display a log line in the message line - Implements log_dispatcher_t -. More...
void mutt_log_prep (void)
 Prepare to log. More...
int mutt_log_start (void)
 Enable file logging. More...
void mutt_log_stop (void)
 Close the log file. More...
int mutt_log_set_level (enum LogLevel level, bool verbose)
 Change the logging level. More...
int mutt_log_set_file (const char *file)
 Change the logging file. More...
int main_log_observer (struct NotifyCallback *nc)
 Notification that a Config Variable has changed - Implements observer_t -. More...
int level_validator (const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err)
 Validate the "debug_level" config variable - Implements ConfigDef::validator() -. More...
void mutt_clear_error (void)
 Clear the message line (bottom line of screen) More...

Detailed Description

NeoMutt Logging.

  • Richard Russon

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

Definition in file mutt_logging.h.

Function Documentation

◆ mutt_log_prep()

void mutt_log_prep ( void  )

Prepare to log.

Definition at line 212 of file mutt_logging.c.

213 {
214  char ver[64];
215  snprintf(ver, sizeof(ver), "-%s%s", PACKAGE_VERSION, GitVer);
217 }
void log_file_set_version(const char *version)
Set the program's version number.
Definition: logging.c:221
const char * GitVer
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_log_start()

int mutt_log_start ( void  )

Enable file logging.

Return values
0Success, or already running
-1Failed to start

This also handles file rotation.

Definition at line 284 of file mutt_logging.c.

285 {
286  const short c_debug_level = cs_subset_number(NeoMutt->sub, "debug_level");
287  if (c_debug_level < 1)
288  return 0;
290  if (log_file_running())
291  return 0;
293  const char *const c_debug_file = cs_subset_path(NeoMutt->sub, "debug_file");
294  mutt_log_set_file(c_debug_file);
296  /* This will trigger the file creation */
297  if (log_file_set_level(c_debug_level, true) < 0)
298  return -1;
300  return 0;
301 }
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
int log_file_set_level(enum LogLevel level, bool verbose)
Set the logging level.
Definition: logging.c:175
bool log_file_running(void)
Is the log file running?
Definition: logging.c:230
int mutt_log_set_file(const char *file)
Change the logging file.
Definition: mutt_logging.c:236
Container for Accounts, Notifications.
Definition: neomutt.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_log_stop()

void mutt_log_stop ( void  )

Close the log file.

Definition at line 222 of file mutt_logging.c.

223 {
224  log_file_close(false);
225  FREE(&CurrentFile);
226 }
void log_file_close(bool verbose)
Close the log file.
Definition: logging.c:98
#define FREE(x)
Definition: memory.h:40
char * CurrentFile
The previous log file name.
Definition: mutt_logging.c:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_log_set_level()

int mutt_log_set_level ( enum LogLevel  level,
bool  verbose 

Change the logging level.

levelLogging level
verboseIf true, then log the event
Return values
-1Error, level is out of range

Definition at line 262 of file mutt_logging.c.

263 {
264  if (!CurrentFile)
265  {
266  const char *const c_debug_file = cs_subset_path(NeoMutt->sub, "debug_file");
267  mutt_log_set_file(c_debug_file);
268  }
270  if (log_file_set_level(level, verbose) != 0)
271  return -1;
273  cs_subset_str_native_set(NeoMutt->sub, "debug_level", level, NULL);
274  return 0;
275 }
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition: subset.c:305
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_log_set_file()

int mutt_log_set_file ( const char *  file)

Change the logging file.

fileName to use
Return values
0Success, file opened
-1Error, see errno

Close the old log, rotate the new logs and open the new log.

Definition at line 236 of file mutt_logging.c.

237 {
238  const char *const c_debug_file = cs_subset_path(NeoMutt->sub, "debug_file");
239  if (!mutt_str_equal(CurrentFile, c_debug_file))
240  {
241  const char *name = rotate_logs(c_debug_file, NumOfLogs);
242  if (!name)
243  return -1;
245  log_file_set_filename(name, false);
246  FREE(&name);
247  mutt_str_replace(&CurrentFile, c_debug_file);
248  }
250  cs_subset_str_string_set(NeoMutt->sub, "debug_file", file, NULL);
252  return 0;
253 }
int log_file_set_filename(const char *file, bool verbose)
Set the filename for the log.
Definition: logging.c:149
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
const int NumOfLogs
How many log files to rotate.
Definition: mutt_logging.c:50
static const char * rotate_logs(const char *file, int count)
Rotate a set of numbered files.
Definition: mutt_logging.c:84
int cs_subset_str_string_set(const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
Set a config item by string.
Definition: subset.c:408
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_clear_error()

void mutt_clear_error ( void  )

Clear the message line (bottom line of screen)

Definition at line 113 of file mutt_logging.c.

114 {
115  /* Make sure the error message has had time to be read */
116  if (OptMsgErr)
117  error_pause();
119  ErrorBufMessage = false;
120  if (!OptNoCurses)
122 }
void msgwin_clear_text(void)
Clear the text in the Message Window.
Definition: msgwin.c:240
bool ErrorBufMessage
true if the last message was an error
Definition: mutt_globals.h:48
static void error_pause(void)
Wait for an error message to be read.
Definition: mutt_logging.c:59
bool OptNoCurses
(pseudo) when sending in batch mode
Definition: options.h:53
bool OptMsgErr
(pseudo) used by mutt_error/mutt_message
Definition: options.h:46
+ Here is the call graph for this function: