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 {
typedef struct _lllog {
int ll_verbosity;
char *ll_path;
log_cb ll_log_err;
log_cb ll_log_info;
log_cb ll_log_warn;
log_close ll_log_close;
} lattutil_log_t;
......@@ -156,8 +160,12 @@ void lattutil_log_free(lattutil_log_t **);
bool lattutil_log_syslog_init(lattutil_log_t *, int, int);
#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,
const char *, ...);
ssize_t lattutil_log_syslog_warn(lattutil_log_t *, int,
const char *, ...);
void lattutil_log_syslog_close(lattutil_log_t *);
#endif /* _lattutil_internal */
......
......@@ -82,8 +82,10 @@ lattutil_log_syslog_init(lattutil_log_t *logp, int logopt, int facility)
{
const char *name;
logp->ll_log_info = lattutil_log_syslog_info;
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;
if (name == NULL) {
......@@ -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);
return (true);
......
......@@ -31,6 +31,31 @@
#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
lattutil_log_syslog_info(lattutil_log_t *logp, int verbose,
const char *fmt, ...)
......@@ -40,17 +65,40 @@ lattutil_log_syslog_info(lattutil_log_t *logp, int verbose,
char *msg;
va_start(args, fmt);
printf("Hey there!\n");
if (verbose == -1 || verbose >= logp->ll_verbosity) {
msg = NULL;
vasprintf(&msg, fmt, args);
printf("Attempting to log: %s\n", msg);
if (msg == NULL) {
len = -1;
goto end;
}
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);
......
Markdown is supported
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