mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-06 03:50:08 +02:00
Allow variable arguments for logging.
This commit is contained in:
parent
aa15f92f86
commit
1f7551178d
4 changed files with 32 additions and 33 deletions
|
@ -365,9 +365,7 @@ static void fetch_from_all_folders(mrimap_t* ths, mrimapthreadval_t* threadval)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char* p = sqlite3_mprintf("Folder \"%s\" ignored.", name_utf8);
|
mr_log_info("Folder \"%s\" ignored.", name_utf8);
|
||||||
mr_log_info(p);
|
|
||||||
sqlite3_free(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(name_utf8);
|
free(name_utf8);
|
||||||
|
|
46
src/mrlog.c
46
src/mrlog.c
|
@ -28,50 +28,56 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include "mrmailbox.h"
|
#include "mrmailbox.h"
|
||||||
#include "mrlog.h"
|
#include "mrlog.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void mr_log(char type, const char* msg)
|
static void mr_log(char type, const char* msg_format_str, va_list argp)
|
||||||
{
|
{
|
||||||
if( msg == NULL ) {
|
const char *type_str;
|
||||||
return; /* this may happen if eg. sqlite3_mprintf() cannot allocate memory - normally, not. */
|
char* msg_full_str, *log_entry_str;
|
||||||
}
|
|
||||||
|
|
||||||
const char* type_str;
|
|
||||||
switch( type ) {
|
switch( type ) {
|
||||||
case 'i': type_str = "Information"; break;
|
case 'i': type_str = "Information"; break;
|
||||||
case 'w': type_str = "Warning"; break;
|
case 'w': type_str = "Warning"; break;
|
||||||
default: type_str = "ERROR"; break;
|
default: type_str = "ERROR"; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* p = sqlite3_mprintf("[%s] %s", type_str, msg);
|
msg_full_str = sqlite3_vmprintf(msg_format_str, argp); if( msg_full_str == NULL ) { exit(18); }
|
||||||
if( p ) {
|
log_entry_str = sqlite3_mprintf("[%s] %s", type_str, msg_full_str); if( log_entry_str == NULL ) { exit(19); }
|
||||||
printf("%s\n", p);
|
printf("%s\n", log_entry_str);
|
||||||
sqlite3_free(p);
|
sqlite3_free(log_entry_str);
|
||||||
}
|
sqlite3_free(msg_full_str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void mr_log_info(const char* msg)
|
void mr_log_info(const char* msg, ...)
|
||||||
{
|
{
|
||||||
mr_log('i', msg);
|
va_list va;
|
||||||
|
va_start(va, msg); /* va_start() expects the last non-variable argument as the second parameter */
|
||||||
|
mr_log('i', msg, va);
|
||||||
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void mr_log_warning(const char* msg)
|
void mr_log_warning(const char* msg, ...)
|
||||||
{
|
{
|
||||||
mr_log('w', msg);
|
va_list va;
|
||||||
|
va_start(va, msg);
|
||||||
|
mr_log('w', msg, va);
|
||||||
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void mr_log_error(const char* msg)
|
void mr_log_error(const char* msg, ...)
|
||||||
{
|
{
|
||||||
mr_log('e', msg);
|
va_list va;
|
||||||
|
va_start(va, msg);
|
||||||
|
mr_log('e', msg, va);
|
||||||
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,9 @@ extern "C" {
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
|
|
||||||
void mr_log_error (const char* msg);
|
void mr_log_error (const char* msg, ...);
|
||||||
void mr_log_warning(const char* msg);
|
void mr_log_warning(const char* msg, ...);
|
||||||
void mr_log_info (const char* msg);
|
void mr_log_info (const char* msg, ...);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -248,6 +248,7 @@ int mrmailbox_import_spec(mrmailbox_t* ths, const char* spec) /* spec is a file,
|
||||||
name = dir_entry->d_name; /* name without path; may also be `.` or `..` */
|
name = dir_entry->d_name; /* name without path; may also be `.` or `..` */
|
||||||
if( strlen(name)>=4 && strcmp(&name[strlen(name)-4], ".eml")==0 ) {
|
if( strlen(name)>=4 && strcmp(&name[strlen(name)-4], ".eml")==0 ) {
|
||||||
char* path_plus_name = sqlite3_mprintf("%s/%s", spec, name);
|
char* path_plus_name = sqlite3_mprintf("%s/%s", spec, name);
|
||||||
|
mr_log_info("Import: %s", path_plus_name);
|
||||||
if( path_plus_name ) {
|
if( path_plus_name ) {
|
||||||
if( mrmailbox_import_file(ths, path_plus_name) ) { /* no abort on single errors errors are logged in any case */
|
if( mrmailbox_import_file(ths, path_plus_name) ) { /* no abort on single errors errors are logged in any case */
|
||||||
read_cnt++;
|
read_cnt++;
|
||||||
|
@ -258,13 +259,7 @@ int mrmailbox_import_spec(mrmailbox_t* ths, const char* spec) /* spec is a file,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
mr_log_info("Import: %i mails read from %s.", read_cnt, spec);
|
||||||
char* p = sqlite3_mprintf("%i mails read from %s.", read_cnt, spec);
|
|
||||||
if( p ) {
|
|
||||||
mr_log_info(p);
|
|
||||||
sqlite3_free(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* success */
|
/* success */
|
||||||
success = 1;
|
success = 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue