Add logString() function

This commit is contained in:
Andrew Bettison 2012-08-01 17:52:38 +09:30
parent 2bd7c38483
commit 560e0c6699
2 changed files with 20 additions and 0 deletions

19
log.c
View File

@ -216,6 +216,25 @@ void logArgv(int level, const char *file, unsigned int line, const char *functio
} }
} }
void logString(int level, const char *file, unsigned int line, const char *function, const char *str)
{
const char *s = str;
const char *p;
for (p = str; *p; ++p) {
if (*p == '\n') {
if (_log_prepare(level, file, line, function)) {
strbuf_ncat(&logbuf, str, p - s);
_log_finish(level);
}
s = p + 1;
}
}
if (p > s && _log_prepare(level, file, line, function)) {
strbuf_ncat(&logbuf, str, p - s);
_log_finish(level);
}
}
void logMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, ...) void logMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, ...)
{ {
va_list ap; va_list ap;

1
log.h
View File

@ -63,6 +63,7 @@ void set_logging(FILE *f);
FILE *open_logging(); FILE *open_logging();
void close_logging(); void close_logging();
void logArgv(int level, const char *file, unsigned int line, const char *function, const char *label, int argc, const char *const *argv); void logArgv(int level, const char *file, unsigned int line, const char *function, const char *label, int argc, const char *const *argv);
void logString(int level, const char *file, unsigned int line, const char *function, const char *str);
void logMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, ...); void logMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, ...);
void vlogMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, va_list); void vlogMessage(int level, const char *file, unsigned int line, const char *function, const char *fmt, va_list);
unsigned int debugFlagMask(const char *flagname); unsigned int debugFlagMask(const char *flagname);