* of the GNU Lesser General Public License.
*/
-#include "ucw/lib.h"
-#include "ucw/log.h"
-#include "ucw/log-internal.h"
-#include "ucw/conf.h"
-#include "ucw/simple-lists.h"
-#include "ucw/tbf.h"
-#include "ucw/threads.h"
+#include <ucw/lib.h>
+#include <ucw/log.h>
+#include <ucw/log-internal.h>
+#include <ucw/conf.h>
+#include <ucw/simple-lists.h>
+#include <ucw/tbf.h>
+#include <ucw/threads.h>
#include <stdio.h>
#include <string.h>
cnode n;
char *name;
char *file_name;
+ int file_desc;
char *syslog_facility;
u32 levels;
clist types; // simple_list of names
cnode n;
clist types; // simple_list of names
double rate;
- uns burst;
+ uint burst;
};
static char *
struct stream_config *c = ptr;
c->levels = ~0U;
+ c->file_desc = -1;
return NULL;
}
#define P(x) PTR_TO(struct limit_config, x)
CF_LIST("Types", P(types), &cf_string_list_config),
CF_DOUBLE("Rate", P(rate)),
- CF_UNS("Burst", P(burst)),
+ CF_UINT("Burst", P(burst)),
#undef P
CF_END
}
#define P(x) PTR_TO(struct stream_config, x)
CF_STRING("Name", P(name)),
CF_STRING("FileName", P(file_name)),
+ CF_INT("FileDesc", P(file_desc)),
CF_STRING("SyslogFacility", P(syslog_facility)),
CF_BITMAP_LOOKUP("Levels", P(levels), level_names),
CF_LIST("Types", P(types), &cf_string_list_config),
/*** Type sets ***/
-static uns
+static uint
log_type_mask(clist *l)
{
if (clist_empty(l))
return ~0U;
- uns types = 0;
+ uint types = 0;
CLIST_FOR_EACH(simp_node *, s, *l)
if (!strcmp(s->s, "all"))
return ~0U;
struct log_msg mm = *m;
mm.flags |= L_LOGGER_ERR;
mm.raw_msg = "(maximum logging rate exceeded, some messages will be suppressed)";
- log_pass_msg(0, ls, &mm);
+ log_pass_msg(ls, &mm);
}
return 1;
}
static void
log_apply_limits(struct log_stream *ls, struct limit_config *lim)
{
- uns mask = log_type_mask(&lim->types);
+ uint mask = log_type_mask(&lim->types);
if (!mask)
return;
tbf->burst = lim->burst;
tbf_init(tbf);
- for (uns i=0; i < LS_NUM_TYPES; i++)
+ for (uint i=0; i < LS_NUM_TYPES; i++)
if (mask & (1 << i))
limits[i] = tbf;
}
if (c->file_name)
ls = log_new_file(c->file_name, (c->stderr_follows ? FF_FD2_FOLLOWS : 0));
+ else if (c->file_desc >= 0)
+ ls = log_new_fd(c->file_desc, (c->stderr_follows ? FF_FD2_FOLLOWS : 0));
else if (c->syslog_facility)
ls = log_new_syslog(c->syslog_facility, (c->syslog_pids ? LOG_PID : 0));
else
void
log_configured(const char *name)
{
- struct log_stream *ls = log_new_configured(name);
- struct log_stream *def = log_stream_by_flags(0);
- log_rm_substream(def, NULL);
- log_add_substream(def, ls);
- log_close_stream(ls);
+ log_set_default_stream(log_new_configured(name));
}
#ifdef TEST
#include <unistd.h>
-#include "ucw/getopt.h"
+#include <ucw/getopt.h>
int main(int argc, char **argv)
{
int type = log_register_type("foo");
struct log_stream *ls = log_new_configured("combined");
- for (uns i=0; i<10; i++)
+ for (uint i=0; i<10; i++)
{
msg(L_INFO | ls->regnum | type, "Hello, universe!");
usleep(200000);