lib: hide away logging internals

... no need to have struct zlog generally-exposed.

A few files get to include log_int.h because they use zlog/vzlog.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2016-02-23 13:01:47 +01:00 committed by David Lamparter
parent dd8376febd
commit deaa50db47
13 changed files with 78 additions and 41 deletions

View File

@ -249,7 +249,6 @@ struct update_subgroup
u_int32_t merge_checks_triggered;
uint64_t id;
struct zlog *log;
u_int16_t sflags;

View File

@ -29,6 +29,7 @@
#include "lib/memory.h"
#include "lib/routemap.h"
#include "lib/log.h"
#include "lib/log_int.h"
#include "lib/linklist.h"
#include "lib/command.h"

View File

@ -24,6 +24,7 @@
#include "log.h"
#include <lib/log.h>
#include <lib/log_int.h>
#include "mpls.h"
static const char * const procnames[] = {

View File

@ -58,7 +58,8 @@ pkginclude_HEADERS = \
# end
noinst_HEADERS = \
plist_int.h
plist_int.h \
log_int.h
noinst_PROGRAMS = grammar_sandbox

View File

@ -30,6 +30,7 @@
#include "memory.h"
#include "log.h"
#include "log_int.h"
#include <lib/version.h>
#include "thread.h"
#include "vector.h"

View File

@ -1697,9 +1697,7 @@ filter_show (struct vty *vty, const char *name, afi_t afi)
return 0;
/* Print the name of the protocol */
if (zlog_default)
vty_out (vty, "%s:%s",
zlog_default->protoname, VTY_NEWLINE);
vty_out(vty, "%s:%s", zlog_protoname(), VTY_NEWLINE);
for (access = master->num.head; access; access = access->next)
{

View File

@ -26,6 +26,7 @@
#include "zclient.h"
#include "log.h"
#include "log_int.h"
#include "memory.h"
#include "command.h"
#ifndef SUNOS_5
@ -752,6 +753,12 @@ closezlog (void)
zlog_default = NULL;
}
const char *
zlog_protoname (void)
{
return zlog_default ? zlog_default->protoname : "NONE";
}
/* Called from command.c. */
void
zlog_set_level (zlog_dest_t dest, int log_level)

View File

@ -55,23 +55,6 @@ typedef enum
} zlog_dest_t;
#define ZLOG_NUM_DESTS (ZLOG_DEST_FILE+1)
struct zlog
{
const char *ident; /* daemon name (first arg to openlog) */
const char *protoname;
u_short instance;
int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated
logging destination */
int default_lvl; /* maxlvl to use if none is specified */
FILE *fp;
char *filename;
int facility; /* as per syslog facility */
int record_priority; /* should messages logged through stdio include the
priority of the message? */
int syslog_options; /* 2nd arg to openlog */
int timestamp_precision; /* # of digits of subsecond precision */
};
/* Message structure. */
struct message
{
@ -79,9 +62,6 @@ struct message
const char *str;
};
/* Default logging strucutre. */
extern struct zlog *zlog_default;
/* Open zlog function */
extern void openzlog (const char *progname, const char *protoname,
u_short instance, int syslog_options, int syslog_facility);
@ -89,6 +69,8 @@ extern void openzlog (const char *progname, const char *protoname,
/* Close zlog function. */
extern void closezlog (void);
extern const char *zlog_protoname (void);
/* GCC have printf type attribute check. */
#ifdef __GNUC__
#define PRINTF_ATTRIBUTE(a,b) __attribute__ ((__format__ (__printf__, a, b)))
@ -96,12 +78,7 @@ extern void closezlog (void);
#define PRINTF_ATTRIBUTE(a,b)
#endif /* __GNUC__ */
/* Generic function for zlog. */
extern void zlog (int priority, const char *format, ...)
PRINTF_ATTRIBUTE(2, 3);
/* Handy zlog functions. */
extern void vzlog (int priority, const char *format, va_list args);
extern void zlog_err (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_warn (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_info (const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
@ -133,8 +110,6 @@ extern const char *mes_lookup (const struct message *meslist,
int max, int index,
const char *no_item, const char *mesname);
extern const char *zlog_priority[];
/* Safe version of strerror -- never returns NULL. */
extern const char *safe_strerror(int errnum);

57
lib/log_int.h Normal file
View File

@ -0,0 +1,57 @@
/*
* Zebra logging funcions.
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
*
* This file is part of GNU Zebra.
*
* GNU Zebra 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 2, or (at your option) any
* later version.
*
* GNU Zebra 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 GNU Zebra; see the file COPYING. If not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#ifndef _ZEBRA_LOG_PRIVATE_H
#define _ZEBRA_LOG_PRIVATE_H
#include "log.h"
struct zlog
{
const char *ident; /* daemon name (first arg to openlog) */
const char *protoname;
u_short instance;
int maxlvl[ZLOG_NUM_DESTS]; /* maximum priority to send to associated
logging destination */
int default_lvl; /* maxlvl to use if none is specified */
FILE *fp;
char *filename;
int facility; /* as per syslog facility */
int record_priority; /* should messages logged through stdio include the
priority of the message? */
int syslog_options; /* 2nd arg to openlog */
int timestamp_precision; /* # of digits of subsecond precision */
};
/* Default logging strucutre. */
extern struct zlog *zlog_default;
extern const char *zlog_priority[];
/* Generic function for zlog. */
extern void vzlog (int priority, const char *format, va_list args);
extern void zlog (int priority, const char *format, ...)
PRINTF_ATTRIBUTE(2, 3);
#endif /* _ZEBRA_LOG_PRIVATE_H */

View File

@ -1175,8 +1175,7 @@ vty_show_prefix_entry (struct vty *vty, afi_t afi, struct prefix_list *plist,
struct prefix_list_entry *pentry;
/* Print the name of the protocol */
if (zlog_default)
vty_out (vty, "%s: ", zlog_default->protoname);
vty_out(vty, "%s: ", zlog_protoname());
if (dtype == normal_display)
{

View File

@ -28,6 +28,7 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#include "routemap.h"
#include "command.h"
#include "log.h"
#include "log_int.h"
#include "hash.h"
DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP, "Route map")
@ -991,7 +992,7 @@ vty_show_route_map_entry (struct vty *vty, struct route_map *map)
/* Print the name of the protocol */
if (zlog_default)
{
vty_out (vty, "%s", zlog_default->protoname);
vty_out (vty, "%s", zlog_protoname());
if (zlog_default->instance)
vty_out (vty, " %d", zlog_default->instance);
}
@ -1051,8 +1052,7 @@ vty_show_route_map (struct vty *vty, const char *name)
}
else
{
if (zlog_default)
vty_out (vty, "%s", zlog_default->protoname);
vty_out (vty, "%s", zlog_protoname());
if (zlog_default && zlog_default->instance)
vty_out (vty, " %d", zlog_default->instance);
vty_out (vty, ": 'route-map %s' not found%s", name, VTY_NEWLINE);

View File

@ -457,10 +457,7 @@ vty_command (struct vty *vty, char *buf)
ret = cmd_execute_command (vline, vty, NULL, 0);
/* Get the name of the protocol if any */
if (zlog_default)
protocolname = zlog_default->protoname;
else
protocolname = "NONE";
protocolname = zlog_protoname();
#ifdef CONSUMED_TIME_CHECK
GETRUSAGE(&after);

View File

@ -28,6 +28,7 @@
#include "zebra_memory.h"
#include "command.h"
#include "log.h"
#include "log_int.h"
#include "sockunion.h"
#include "linklist.h"
#include "thread.h"