Refactor and move logArgv() to log_util.c

This commit is contained in:
Jeremy Lakeman 2014-04-14 12:30:33 +09:30
parent fd8195fa4f
commit 6a330977f3
2 changed files with 18 additions and 23 deletions

23
log.c
View File

@ -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) {

View File

@ -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) {