예제 #1
0
static LogPipe *
date_parser_clone(LogPipe *s)
{
  DateParser *self = (DateParser *) s;
  LogParser *cloned;

  cloned = date_parser_new(log_pipe_get_config(&self->super.super));
  date_parser_set_format(cloned, self->date_format);
  date_parser_set_timezone(cloned, self->date_tz);
  date_parser_set_time_stamp(cloned, self->time_stamp);
  log_parser_set_template(cloned, log_template_ref(self->super.template));
예제 #2
0
static LogParser *
_construct_parser(gchar *timezone_, gchar *format, gint time_stamp)
{
  LogParser *parser;

  parser = date_parser_new (configuration);
  if (format != NULL)
    date_parser_set_format(parser, format);
  if (timezone_ != NULL)
    date_parser_set_timezone(parser, timezone_);
  date_parser_set_time_stamp(parser, time_stamp);

  log_pipe_init(&parser->super);
  return parser;
}
예제 #3
0
static void
testcase(gchar *msg, gchar *timezone, gchar *format, gchar *expected)
{
  LogTemplate *templ;
  LogMessage *logmsg;
  LogParser *parser;
  gboolean success;
  GString *res = g_string_sized_new(128);

  parser = date_parser_new (configuration);
  if (format != NULL) date_parser_set_format(parser, format);
  if (timezone != NULL) date_parser_set_timezone(parser, timezone);

  log_pipe_init(&parser->super);

  logmsg = log_msg_new_empty();
  logmsg->timestamps[LM_TS_RECVD].tv_sec = 1451473200; /* Dec  30 2015 */
  log_msg_set_value(logmsg, log_msg_get_value_handle("MESSAGE"), msg, -1);
  success = log_parser_process(parser, &logmsg, NULL, log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), -1);

  if (!success && expected)
    {
      fprintf(stderr, "unable to parse format=%s msg=%s\n", format, msg);
      exit(1);
    }
  else if (success && !expected)
    {
      fprintf(stderr, "successfully parsed but expected failure, format=%s msg=%s\n", format, msg);
      exit(1);
    }
  else if (expected)
    {
      /* Convert to ISODATE */
      templ = compile_template("${ISODATE}", FALSE);
      log_template_format(templ, logmsg, NULL, LTZ_LOCAL, -1, NULL, res);
      assert_nstring(res->str, res->len, expected, strlen(expected),
                     "incorrect date parsed msg=%s format=%s",
                     msg, format);
      log_template_unref(templ);
    }

  g_string_free(res, TRUE);
  log_pipe_unref(&parser->super);
  log_msg_unref(logmsg);
  return;
}
예제 #4
0
static void
testcase(gchar *msg, goffset offset, gchar *timezone, gchar *format, gchar *expected)
{
  LogTemplate *templ;
  LogMessage *logmsg;
  NVTable *nvtable;
  GlobalConfig *cfg = cfg_new (0x302);
  LogParser *parser = date_parser_new (cfg);
  gboolean success;
  const gchar *context_id = "test-context-id";
  GString *res = g_string_sized_new(128);

  date_parser_set_offset(parser, offset);
  if (format != NULL) date_parser_set_format(parser, format);
  if (timezone != NULL) date_parser_set_timezone(parser, timezone);

  parse_options.flags = 0;
  logmsg = log_msg_new_empty();
  logmsg->timestamps[LM_TS_RECVD].tv_sec = 1438793384; /* Wed Aug  5 2015 */
  log_msg_set_value(logmsg, log_msg_get_value_handle("MESSAGE"), msg, -1);
  nvtable = nv_table_ref(logmsg->payload);
  success = log_parser_process(parser, &logmsg, NULL, log_msg_get_value(logmsg, LM_V_MESSAGE, NULL), -1);
  nv_table_unref(nvtable);

  if (!success)
    {
      fprintf(stderr, "unable to parse offset=%d format=%s msg=%s\n", offset, format, msg);
      exit(1);
    }

  /* Convert to ISODATE */
  templ = compile_template("${ISODATE}", FALSE);
  log_template_format(templ, logmsg, NULL, LTZ_LOCAL, 999, context_id, res);
  assert_nstring(res->str, res->len, expected, strlen(expected),
                 "incorrect date parsed msg=%s offset=%d format=%s",
                 msg, offset, format);
  log_template_unref(templ);
  g_string_free(res, TRUE);

  log_pipe_unref(&parser->super);
  log_msg_unref(logmsg);
  return;
}