Commit c20368a8 authored by Shawn Webb's avatar Shawn Webb
Browse files

Support logging errors and warnings



Also prepend the message with the type of message (ERROR, INFO,
WARNING).
Signed-off-by: Shawn Webb's avatarShawn Webb <shawn.webb@hardenedbsd.org>
parent 9fb2f352
...@@ -57,7 +57,11 @@ typedef struct _llconfig { ...@@ -57,7 +57,11 @@ typedef struct _llconfig {
typedef struct _lllog { typedef struct _lllog {
int ll_verbosity; int ll_verbosity;
char *ll_path; char *ll_path;
log_cb ll_log_err;
log_cb ll_log_info; log_cb ll_log_info;
log_cb ll_log_warn;
log_close ll_log_close; log_close ll_log_close;
} lattutil_log_t; } lattutil_log_t;
...@@ -156,8 +160,12 @@ void lattutil_log_free(lattutil_log_t **); ...@@ -156,8 +160,12 @@ void lattutil_log_free(lattutil_log_t **);
bool lattutil_log_syslog_init(lattutil_log_t *, int, int); bool lattutil_log_syslog_init(lattutil_log_t *, int, int);
#ifdef _lattutil_internal #ifdef _lattutil_internal
ssize_t lattutil_log_syslog_err(lattutil_log_t *, int,
const char *, ...);
ssize_t lattutil_log_syslog_info(lattutil_log_t *, int, ssize_t lattutil_log_syslog_info(lattutil_log_t *, int,
const char *, ...); const char *, ...);
ssize_t lattutil_log_syslog_warn(lattutil_log_t *, int,
const char *, ...);
void lattutil_log_syslog_close(lattutil_log_t *); void lattutil_log_syslog_close(lattutil_log_t *);
#endif /* _lattutil_internal */ #endif /* _lattutil_internal */
......
...@@ -82,8 +82,10 @@ lattutil_log_syslog_init(lattutil_log_t *logp, int logopt, int facility) ...@@ -82,8 +82,10 @@ lattutil_log_syslog_init(lattutil_log_t *logp, int logopt, int facility)
{ {
const char *name; const char *name;
logp->ll_log_info = lattutil_log_syslog_info;
logp->ll_log_close = lattutil_log_syslog_close; logp->ll_log_close = lattutil_log_syslog_close;
logp->ll_log_err = lattutil_log_syslog_err;
logp->ll_log_info = lattutil_log_syslog_info;
logp->ll_log_warn = lattutil_log_syslog_warn;
name = logp->ll_path; name = logp->ll_path;
if (name == NULL) { if (name == NULL) {
...@@ -93,7 +95,6 @@ lattutil_log_syslog_init(lattutil_log_t *logp, int logopt, int facility) ...@@ -93,7 +95,6 @@ lattutil_log_syslog_init(lattutil_log_t *logp, int logopt, int facility)
} }
} }
printf("Opening log %s\n", name);
openlog(name, logopt, facility); openlog(name, logopt, facility);
return (true); return (true);
......
...@@ -31,6 +31,31 @@ ...@@ -31,6 +31,31 @@
#include "liblattutil.h" #include "liblattutil.h"
ssize_t
lattutil_log_syslog_err(lattutil_log_t *logp, int verbose,
const char *fmt, ...)
{
va_list args;
size_t len;
char *msg;
va_start(args, fmt);
if (verbose == -1 || verbose >= logp->ll_verbosity) {
msg = NULL;
vasprintf(&msg, fmt, args);
if (msg == NULL) {
len = -1;
goto end;
}
len = strlen(msg);
syslog(LOG_ERR, "ERROR: %s", msg);
}
va_end(args);
end:
return (len);
}
ssize_t ssize_t
lattutil_log_syslog_info(lattutil_log_t *logp, int verbose, lattutil_log_syslog_info(lattutil_log_t *logp, int verbose,
const char *fmt, ...) const char *fmt, ...)
...@@ -40,17 +65,40 @@ lattutil_log_syslog_info(lattutil_log_t *logp, int verbose, ...@@ -40,17 +65,40 @@ lattutil_log_syslog_info(lattutil_log_t *logp, int verbose,
char *msg; char *msg;
va_start(args, fmt); va_start(args, fmt);
printf("Hey there!\n");
if (verbose == -1 || verbose >= logp->ll_verbosity) { if (verbose == -1 || verbose >= logp->ll_verbosity) {
msg = NULL; msg = NULL;
vasprintf(&msg, fmt, args); vasprintf(&msg, fmt, args);
printf("Attempting to log: %s\n", msg);
if (msg == NULL) { if (msg == NULL) {
len = -1; len = -1;
goto end; goto end;
} }
len = strlen(msg); len = strlen(msg);
syslog(LOG_INFO, "%s", msg); syslog(LOG_INFO, "INFO: %s", msg);
}
va_end(args);
end:
return (len);
}
ssize_t
lattutil_log_syslog_warn(lattutil_log_t *logp, int verbose,
const char *fmt, ...)
{
va_list args;
size_t len;
char *msg;
va_start(args, fmt);
if (verbose == -1 || verbose >= logp->ll_verbosity) {
msg = NULL;
vasprintf(&msg, fmt, args);
if (msg == NULL) {
len = -1;
goto end;
}
len = strlen(msg);
syslog(LOG_WARNING, "WARNING: %s", msg);
} }
va_end(args); va_end(args);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment