Thread: [srvx-commits] CVS: services/src log.c,1.52,1.53
Brought to you by:
entrope
|
From: Zoot <zo...@us...> - 2003-07-08 05:15:41
|
Update of /cvsroot/srvx/services/src
In directory sc8-pr-cvs1:/tmp/cvs-serv5105/src
Modified Files:
log.c
Log Message:
Support a new "std:" log destination; examples of valid target strings are "std:out", "std:err", and "std:N" where N is a valid file descriptor.
Index: log.c
===================================================================
RCS file: /cvsroot/srvx/services/src/log.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -r1.52 -r1.53
*** log.c 8 Jul 2003 01:24:01 -0000 1.52
--- log.c 8 Jul 2003 05:15:39 -0000 1.53
***************
*** 318,322 ****
--- 318,324 ----
unsigned int ii;
+
close_logs();
+
rd = conf_get_node("logs");
if (rd && (rd->type == RECDB_OBJECT)) {
***************
*** 730,733 ****
--- 732,747 ----
}
+ /* shared stub log operations act as a noop */
+
+ static void
+ ldNop_reopen(struct logDestination *self_) {
+ (void)self_; /* no operation necessary */
+ }
+
+ static void
+ ldNop_replay(struct logDestination *self_, struct log_type *type, int is_write, const char *line) {
+ (void)self_; (void)type; (void)is_write; (void)line; /* no operation necessary */
+ }
+
/* file: log type */
***************
*** 809,812 ****
--- 823,882 ----
};
+ /* std: log type */
+
+ static struct logDest_vtable ldStd_vtbl;
+
+ static struct logDestination *
+ ldStd_open(const char *args) {
+ struct logDest_file *ld;
+ ld = calloc(1, sizeof(*ld));
+ ld->base.vtbl = &ldStd_vtbl;
+ ld->fname = strdup(args);
+
+ /* Print to stderr if given "err" and default to stdout otherwise. */
+ if (atoi(args)) {
+ ld->output = fdopen(atoi(args), "a");
+ } else if (!strcasecmp(args, "err")) {
+ ld->output = stdout;
+ } else {
+ ld->output = stderr;
+ }
+
+ return &ld->base;
+ }
+
+ static void
+ ldStd_close(struct logDestination *self_) {
+ struct logDest_file *self = (struct logDest_file*)self_;
+ free(self->fname);
+ free(self);
+ }
+
+ static void
+ ldStd_replay(struct logDestination *self_, struct log_type *type, int is_write, const char *line) {
+ struct logDest_file *self = (struct logDest_file*)self_;
+ (void)type;
+
+ fprintf(self->output, "%s%s\n", is_write ? "W: " : " ", line);
+ }
+
+ static void
+ ldStd_module(struct logDestination *self_, struct log_type *type, enum log_severity sev, const char *message) {
+ struct logDest_file *self = (struct logDest_file*)self_;
+ (void)type;
+
+ fprintf(self->output, "%s: %s\n", log_severity_names[sev], message);
+ }
+
+ static struct logDest_vtable ldStd_vtbl = {
+ "std",
+ ldStd_open,
+ ldNop_reopen,
+ ldStd_close,
+ ldFile_audit,
+ ldStd_replay,
+ ldStd_module
+ };
+
/* irc: log type */
***************
*** 827,835 ****
static void
- ldIrc_reopen(struct logDestination *self_) {
- (void)self_; /* no operation necessary */
- }
-
- static void
ldIrc_close(struct logDestination *self_) {
struct logDest_irc *self = (struct logDest_irc*)self_;
--- 897,900 ----
***************
*** 851,860 ****
static void
- ldIrc_replay(struct logDestination *self_, struct log_type *type, int is_write, const char *line) {
- (void)self_; (void)type; (void)is_write; (void)line;
- /* totally ignore this - it would be a recipe for disaster */
- }
-
- static void
ldIrc_module(struct logDestination *self_, struct log_type *type, enum log_severity sev, const char *message) {
struct logDest_irc *self = (struct logDest_irc*)self_;
--- 916,919 ----
***************
*** 868,875 ****
"irc",
ldIrc_open,
! ldIrc_reopen,
ldIrc_close,
ldIrc_audit,
! ldIrc_replay,
ldIrc_module
};
--- 927,934 ----
"irc",
ldIrc_open,
! ldNop_reopen,
ldIrc_close,
ldIrc_audit,
! ldNop_replay, /* totally ignore this - it would be a recipe for disaster */
ldIrc_module
};
***************
*** 880,889 ****
log_dests = dict_new();
dict_set_free_keys(log_dests, free);
- log_dest_types = dict_new();
log_types = dict_new();
dict_set_free_keys(log_types, free);
dict_set_free_data(log_types, log_type_free);
/* register log types */
dict_insert(log_dest_types, ldFile_vtbl.type_name, &ldFile_vtbl);
dict_insert(log_dest_types, ldIrc_vtbl.type_name, &ldIrc_vtbl);
conf_register_reload(log_conf_read);
--- 939,949 ----
log_dests = dict_new();
dict_set_free_keys(log_dests, free);
log_types = dict_new();
dict_set_free_keys(log_types, free);
dict_set_free_data(log_types, log_type_free);
+ log_dest_types = dict_new();
/* register log types */
dict_insert(log_dest_types, ldFile_vtbl.type_name, &ldFile_vtbl);
+ dict_insert(log_dest_types, ldStd_vtbl.type_name, &ldStd_vtbl);
dict_insert(log_dest_types, ldIrc_vtbl.type_name, &ldIrc_vtbl);
conf_register_reload(log_conf_read);
|