mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-21 09:51:50 +00:00
Refactor and move logArgv() to log_util.c
This commit is contained in:
parent
fd8195fa4f
commit
6a330977f3
23
log.c
23
log.c
@ -659,29 +659,6 @@ void logFlush()
|
||||
_log_flush(&it);
|
||||
}
|
||||
|
||||
void logArgv(int level, struct __sourceloc whence, const char *label, int argc, const char *const *argv)
|
||||
{
|
||||
if (level != LOG_LEVEL_SILENT) {
|
||||
struct strbuf b;
|
||||
strbuf_init(&b, NULL, 0);
|
||||
strbuf_append_argv(&b, argc, argv);
|
||||
size_t len = strbuf_count(&b);
|
||||
strbuf_init(&b, alloca(len + 1), len + 1);
|
||||
strbuf_append_argv(&b, argc, argv);
|
||||
_log_iterator it;
|
||||
_log_iterator_start(&it);
|
||||
_rotate_log_file(&it);
|
||||
while (_log_iterator_next(&it, level)) {
|
||||
_log_prefix_whence(&it, whence);
|
||||
if (label) {
|
||||
xputs(label, it.xpf);
|
||||
xputc(' ', it.xpf);
|
||||
}
|
||||
xputs(strbuf_str(&b), it.xpf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void logString(int level, struct __sourceloc whence, const char *str)
|
||||
{
|
||||
if (level != LOG_LEVEL_SILENT) {
|
||||
|
18
log_util.c
18
log_util.c
@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
#include "log.h"
|
||||
#include "strbuf.h"
|
||||
#include "strbuf_helpers.h"
|
||||
|
||||
int logDump(int level, struct __sourceloc whence, char *name, const unsigned char *addr, size_t len)
|
||||
{
|
||||
@ -44,6 +45,23 @@ int logDump(int level, struct __sourceloc whence, char *name, const unsigned cha
|
||||
return 0;
|
||||
}
|
||||
|
||||
void logArgv(int level, struct __sourceloc whence, const char *label, int argc, const char *const *argv)
|
||||
{
|
||||
if (level != LOG_LEVEL_SILENT) {
|
||||
struct strbuf b;
|
||||
strbuf_init(&b, NULL, 0);
|
||||
strbuf_append_argv(&b, argc, argv);
|
||||
size_t len = strbuf_count(&b);
|
||||
strbuf_init(&b, alloca(len + 1), len + 1);
|
||||
strbuf_append_argv(&b, argc, argv);
|
||||
|
||||
if (label)
|
||||
logMessage(level, whence, "%s %s", label, strbuf_str(&b));
|
||||
else
|
||||
logMessage(level, whence, "%s", strbuf_str(&b));
|
||||
}
|
||||
}
|
||||
|
||||
const char *log_level_as_string(int level)
|
||||
{
|
||||
switch (level) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user