Commit 68fe9aa7 authored by Daniel Salzman's avatar Daniel Salzman

log: add format flags

parent 41799683
...@@ -77,7 +77,9 @@ src/contrib/sockaddr.c ...@@ -77,7 +77,9 @@ src/contrib/sockaddr.c
src/contrib/sockaddr.h src/contrib/sockaddr.h
src/contrib/string.c src/contrib/string.c
src/contrib/string.h src/contrib/string.h
src/contrib/time.h
src/contrib/tolower.h src/contrib/tolower.h
src/contrib/trim.h
src/contrib/ucw/array-sort.h src/contrib/ucw/array-sort.h
src/contrib/ucw/binsearch.h src/contrib/ucw/binsearch.h
src/contrib/ucw/heap.c src/contrib/ucw/heap.c
...@@ -241,8 +243,6 @@ src/knot/common/process.c ...@@ -241,8 +243,6 @@ src/knot/common/process.c
src/knot/common/process.h src/knot/common/process.h
src/knot/common/ref.c src/knot/common/ref.c
src/knot/common/ref.h src/knot/common/ref.h
src/knot/common/time.h
src/knot/common/trim.h
src/knot/conf/base.c src/knot/conf/base.c
src/knot/conf/base.h src/knot/conf/base.h
src/knot/conf/conf.c src/knot/conf/conf.c
...@@ -255,6 +255,8 @@ src/knot/conf/scheme.c ...@@ -255,6 +255,8 @@ src/knot/conf/scheme.c
src/knot/conf/scheme.h src/knot/conf/scheme.h
src/knot/conf/tools.c src/knot/conf/tools.c
src/knot/conf/tools.h src/knot/conf/tools.h
src/knot/ctl/commands.c
src/knot/ctl/commands.h
src/knot/ctl/remote.c src/knot/ctl/remote.c
src/knot/ctl/remote.h src/knot/ctl/remote.h
src/knot/dnssec/context.c src/knot/dnssec/context.c
......
...@@ -239,6 +239,8 @@ libknotd_la_SOURCES = \ ...@@ -239,6 +239,8 @@ libknotd_la_SOURCES = \
knot/conf/scheme.h \ knot/conf/scheme.h \
knot/conf/tools.c \ knot/conf/tools.c \
knot/conf/tools.h \ knot/conf/tools.h \
knot/ctl/commands.c \
knot/ctl/commands.h \
knot/ctl/remote.c \ knot/ctl/remote.c \
knot/ctl/remote.h \ knot/ctl/remote.h \
knot/dnssec/context.c \ knot/dnssec/context.c \
......
...@@ -45,8 +45,9 @@ struct log_sink ...@@ -45,8 +45,9 @@ struct log_sink
{ {
uint8_t *facility; /* Log sinks. */ uint8_t *facility; /* Log sinks. */
size_t facility_count; /* Sink count. */ size_t facility_count; /* Sink count. */
FILE** file; /* Open files. */ FILE **file; /* Open files. */
ssize_t file_count; /* Nr of open files. */ ssize_t file_count; /* Nr of open files. */
logflag_t flags; /* Formatting flags. */
}; };
/*! Log sink singleton. */ /*! Log sink singleton. */
...@@ -208,6 +209,11 @@ bool log_isopen() ...@@ -208,6 +209,11 @@ bool log_isopen()
return s_log != NULL; return s_log != NULL;
} }
void log_flag_set(logflag_t flag)
{
s_log->flags |= flag;
}
/*! \brief Open file as a logging facility. */ /*! \brief Open file as a logging facility. */
static int log_open_file(struct log_sink *log, const char* filename) static int log_open_file(struct log_sink *log, const char* filename)
{ {
...@@ -278,13 +284,15 @@ static int emit_log_msg(int level, const char *zone, size_t zone_len, const char ...@@ -278,13 +284,15 @@ static int emit_log_msg(int level, const char *zone, size_t zone_len, const char
level = LOG_MASK(level); level = LOG_MASK(level);
/* Prefix date and time. */ /* Prefix date and time. */
char tstr[LOG_BUFLEN] = {0}; char tstr[LOG_BUFLEN] = { 0 };
struct tm lt; if (!log_isopen() || !(s_log->flags & LOG_FNO_TIMESTAMP)) {
struct timeval tv; struct tm lt;
gettimeofday(&tv, NULL); struct timeval tv;
time_t sec = tv.tv_sec; gettimeofday(&tv, NULL);
if (localtime_r(&sec, &lt) != NULL) { time_t sec = tv.tv_sec;
strftime(tstr, sizeof(tstr), KNOT_LOG_TIME_FORMAT " ", &lt); if (localtime_r(&sec, &lt) != NULL) {
strftime(tstr, sizeof(tstr), KNOT_LOG_TIME_FORMAT " ", &lt);
}
} }
// Log streams // Log streams
...@@ -364,10 +372,12 @@ static int log_msg_text(int level, const char *zone, const char *fmt, va_list ar ...@@ -364,10 +372,12 @@ static int log_msg_text(int level, const char *zone, const char *fmt, va_list ar
size_t capacity = sizeof(sbuf) - 1; size_t capacity = sizeof(sbuf) - 1;
/* Prefix error level. */ /* Prefix error level. */
const char *prefix = level_prefix(level); if (level != LOG_INFO || !log_isopen() || !(s_log->flags & LOG_FNO_INFO)) {
ret = log_msg_add(&write, &capacity, "%s: ", prefix); const char *prefix = level_prefix(level);
if (ret != KNOT_EOK) { ret = log_msg_add(&write, &capacity, "%s: ", prefix);
return ret; if (ret != KNOT_EOK) {
return ret;
}
} }
/* Prefix zone name. */ /* Prefix zone name. */
......
...@@ -60,6 +60,12 @@ typedef enum { ...@@ -60,6 +60,12 @@ typedef enum {
LOG_ANY = 7 /*!< Any module. */ LOG_ANY = 7 /*!< Any module. */
} logsrc_t; } logsrc_t;
/*! \brief Logging format flags. */
typedef enum {
LOG_FNO_TIMESTAMP = 1 << 0, /*!< Don't print timestamp prefix. */
LOG_FNO_INFO = 1 << 1 /*!< Don't print info level prefix. */
} logflag_t;
/*! \brief Format for timestamps in log files. */ /*! \brief Format for timestamps in log files. */
#define KNOT_LOG_TIME_FORMAT "%Y-%m-%dT%H:%M:%S" #define KNOT_LOG_TIME_FORMAT "%Y-%m-%dT%H:%M:%S"
...@@ -83,6 +89,11 @@ void log_close(); ...@@ -83,6 +89,11 @@ void log_close();
*/ */
bool log_isopen(); bool log_isopen();
/*!
* \brief Set logging format flag.
*/
void log_flag_set(logflag_t flag);
/*! /*!
* \brief Return log levels for a given facility. * \brief Return log levels for a given facility.
* *
......
This diff is collapsed.
/* Copyright (C) 2015 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "libknot/libknot.h"
#include "knot/server/server.h"
#define CMDARGS_ALLOC_BLOCK KNOT_WIRE_MAX_PKTSIZE
#define KNOT_CTL_STATUS "status"
#define KNOT_CTL_STOP "stop"
#define KNOT_CTL_RELOAD "reload"
#define KNOT_CTL_ZONE_STATUS "zone-status"
#define KNOT_CTL_ZONE_RELOAD "zone-reload"
#define KNOT_CTL_ZONE_REFRESH "zone-refresh"
#define KNOT_CTL_ZONE_RETRANSFER "zone-retransfer"
#define KNOT_CTL_ZONE_FLUSH "zone-flush"
#define KNOT_CTL_ZONE_SIGN "zone-sign"
#define KNOT_CTL_CONF_LIST "conf-list"
#define KNOT_CTL_CONF_READ "conf-read"
#define KNOT_CTL_CONF_BEGIN "conf-begin"
#define KNOT_CTL_CONF_COMMIT "conf-commit"
#define KNOT_CTL_CONF_ABORT "conf-abort"
#define KNOT_CTL_CONF_DIFF "conf-diff"
#define KNOT_CTL_CONF_GET "conf-get"
#define KNOT_CTL_CONF_SET "conf-set"
#define KNOT_CTL_CONF_UNSET "conf-unset"
/*! \brief Remote command structure. */
typedef struct {
const knot_rrset_t *arg;
unsigned argc;
knot_rcode_t rc;
char *response;
size_t response_size;
size_t response_max;
} remote_cmdargs_t;
/*! \brief Callback prototype for remote commands. */
typedef int (*remote_cmdf_t)(server_t *, remote_cmdargs_t *);
/*! \brief Remote command table item. */
typedef struct {
const char *name;
remote_cmdf_t f;
} remote_cmd_t;
/*! \brief Table of remote commands. */
extern const remote_cmd_t remote_cmd_tbl[];
This diff is collapsed.
...@@ -212,7 +212,7 @@ static void event_loop(server_t *server) ...@@ -212,7 +212,7 @@ static void event_loop(server_t *server)
/* Events. */ /* Events. */
if (ret > 0) { if (ret > 0) {
ret = remote_process(server, sock, buf, buflen); ret = remote_process(server, sock, buf, buflen);
if (ret == KNOT_CTL_STOP) { if (ret == KNOT_CTL_ESTOP) {
break; break;
} }
} }
......
...@@ -89,9 +89,9 @@ enum knot_error { ...@@ -89,9 +89,9 @@ enum knot_error {
KNOT_EFILE, KNOT_EFILE,
/* Control states. */ /* Control states. */
KNOT_CTL_STOP, KNOT_CTL_ESTOP,
KNOT_CTL_ACCEPTED, KNOT_CTL_EACCEPTED,
KNOT_CTL_ARG_REQ, KNOT_CTL_EARG_REQ,
/* Network errors. */ /* Network errors. */
KNOT_NET_EADDR, KNOT_NET_EADDR,
......
...@@ -88,9 +88,9 @@ static const struct error errors[] = { ...@@ -88,9 +88,9 @@ static const struct error errors[] = {
{ KNOT_EFILE, "file error" }, { KNOT_EFILE, "file error" },
/* Control states. */ /* Control states. */
{ KNOT_CTL_STOP, "stopping server" }, { KNOT_CTL_ESTOP, "stopping server" },
{ KNOT_CTL_ACCEPTED, "command accepted" }, { KNOT_CTL_EACCEPTED, "command accepted" },
{ KNOT_CTL_ARG_REQ, "argument required" }, { KNOT_CTL_EARG_REQ, "argument required" },
/* Network errors. */ /* Network errors. */
{ KNOT_NET_EADDR, "bad address or host name" }, { KNOT_NET_EADDR, "bad address or host name" },
......
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