log_message_storage: use sblist
This commit is contained in:
parent
54ae2d2a19
commit
06c96761d5
27
src/log.c
27
src/log.c
@ -27,7 +27,7 @@
|
|||||||
#include "heap.h"
|
#include "heap.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "vector.h"
|
#include "sblist.h"
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ static int log_level = LOG_INFO;
|
|||||||
* The key is the actual messages (already filled in full), and the value
|
* The key is the actual messages (already filled in full), and the value
|
||||||
* is the log level.
|
* is the log level.
|
||||||
*/
|
*/
|
||||||
static vector_t log_message_storage;
|
static sblist *log_message_storage;
|
||||||
|
|
||||||
static unsigned int logging_initialized = FALSE; /* boolean */
|
static unsigned int logging_initialized = FALSE; /* boolean */
|
||||||
|
|
||||||
@ -142,7 +142,7 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
char *entry_buffer;
|
char *entry_buffer;
|
||||||
|
|
||||||
if (!log_message_storage) {
|
if (!log_message_storage) {
|
||||||
log_message_storage = vector_create ();
|
log_message_storage = sblist_new (sizeof(char*), 64);
|
||||||
if (!log_message_storage)
|
if (!log_message_storage)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -154,10 +154,8 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
sprintf (entry_buffer, "%d %s", level, str);
|
sprintf (entry_buffer, "%d %s", level, str);
|
||||||
vector_append (log_message_storage, entry_buffer,
|
if(!sblist_add (log_message_storage, &entry_buffer))
|
||||||
strlen (entry_buffer) + 1);
|
safefree (entry_buffer);
|
||||||
|
|
||||||
safefree (entry_buffer);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -227,7 +225,7 @@ out:
|
|||||||
*/
|
*/
|
||||||
static void send_stored_logs (void)
|
static void send_stored_logs (void)
|
||||||
{
|
{
|
||||||
char *string;
|
char **string;
|
||||||
char *ptr;
|
char *ptr;
|
||||||
int level;
|
int level;
|
||||||
size_t i;
|
size_t i;
|
||||||
@ -237,12 +235,12 @@ static void send_stored_logs (void)
|
|||||||
|
|
||||||
log_message(LOG_DEBUG, "sending stored logs");
|
log_message(LOG_DEBUG, "sending stored logs");
|
||||||
|
|
||||||
for (i = 0; (ssize_t) i != vector_length (log_message_storage); ++i) {
|
for (i = 0; i < sblist_getsize (log_message_storage); ++i) {
|
||||||
string =
|
string = sblist_get (log_message_storage, i);
|
||||||
(char *) vector_getentry (log_message_storage, i, NULL);
|
if (!string || !*string) continue;
|
||||||
|
|
||||||
ptr = strchr (string, ' ') + 1;
|
ptr = strchr (*string, ' ') + 1;
|
||||||
level = atoi (string);
|
level = atoi (*string);
|
||||||
|
|
||||||
#ifdef NDEBUG
|
#ifdef NDEBUG
|
||||||
if (log_level == LOG_CONN && level == LOG_INFO)
|
if (log_level == LOG_CONN && level == LOG_INFO)
|
||||||
@ -255,9 +253,10 @@ static void send_stored_logs (void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
log_message (level, "%s", ptr);
|
log_message (level, "%s", ptr);
|
||||||
|
safefree(*string);
|
||||||
}
|
}
|
||||||
|
|
||||||
vector_delete (log_message_storage);
|
sblist_free (log_message_storage);
|
||||||
log_message_storage = NULL;
|
log_message_storage = NULL;
|
||||||
|
|
||||||
log_message(LOG_DEBUG, "done sending stored logs");
|
log_message(LOG_DEBUG, "done sending stored logs");
|
||||||
|
Loading…
Reference in New Issue
Block a user