~ubuntu-branches/ubuntu/trusty/syslog-ng/trusty-proposed

« back to all changes in this revision

Viewing changes to src/logwriter.c

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2010-03-28 19:47:36 UTC
  • mfrom: (1.3.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100328194736-1ob7kh1qr0fy8b9k
Tags: 3.1.0-1
* New upstream release.
* Fix path of syslog logfile (closes: #575722) and use tty10 instead of
  vc/10 to log on console.
* Provide syslog-ng in initscript (closes: #575723).

Show diffs side-by-side

added added

removed removed

Lines of Context:
325
325
  LogMessage *m;
326
326
  LogPathOptions path_options = LOG_PATH_OPTIONS_INIT;
327
327
  gchar hostname[256];
 
328
  gchar buf[1024];
 
329
  gssize len;
 
330
  const gchar *p;
328
331
 
329
332
  msg_debug("Suppress timer elapsed, emitting suppression summary", 
330
333
            NULL);
334
337
  m->timestamps[LM_TS_STAMP] = m->timestamps[LM_TS_RECVD];
335
338
  m->pri = self->last_msg->pri;
336
339
  m->flags = LF_INTERNAL | LF_LOCAL;
337
 
  log_msg_set_host(m, g_strndup(self->last_msg->host, self->last_msg->host_len), self->last_msg->host_len);
338
 
  log_msg_set_program(m, g_strndup(self->last_msg->program, self->last_msg->program_len), self->last_msg->program_len);
339
 
  log_msg_set_message(m, g_strdup_printf("Last message '%.20s' repeated %d times, supressed by syslog-ng on %s",
340
 
                                         self->last_msg->message,
341
 
                                         self->last_msg_count,
342
 
                                         hostname), -1);
343
 
                                         
344
 
                                         
 
340
 
 
341
  p = log_msg_get_value(self->last_msg, LM_V_HOST, &len);
 
342
  log_msg_set_value(m, LM_V_HOST, p, len);
 
343
  p = log_msg_get_value(self->last_msg, LM_V_PROGRAM, &len);
 
344
  log_msg_set_value(m, LM_V_PROGRAM, p, len);
 
345
 
 
346
  len = g_snprintf(buf, sizeof(buf), "Last message '%.20s' repeated %d times, supressed by syslog-ng on %s",
 
347
                   log_msg_get_value(self->last_msg, LM_V_MESSAGE, NULL),
 
348
                   self->last_msg_count,
 
349
                   hostname);
 
350
  log_msg_set_value(m, LM_V_MESSAGE, buf, len);
 
351
 
345
352
  path_options.flow_control = FALSE;
346
353
  log_queue_push_tail(self->queue, m, &path_options);
347
354
 
385
392
  if (self->last_msg)
386
393
    {
387
394
      if (self->last_msg->timestamps[LM_TS_RECVD].time.tv_sec >= lm->timestamps[LM_TS_RECVD].time.tv_sec - self->options->suppress &&
388
 
          strcmp(self->last_msg->message, lm->message) == 0 &&
389
 
          strcmp(self->last_msg->host, lm->host) == 0 &&
390
 
          strcmp(self->last_msg->program, lm->program) == 0 &&
391
 
          strcmp(self->last_msg->pid, lm->pid) == 0 &&
392
 
          strcmp(lm->message, "-- MARK --") != 0)
 
395
          strcmp(log_msg_get_value(self->last_msg, LM_V_MESSAGE, NULL), log_msg_get_value(lm, LM_V_MESSAGE, NULL)) == 0 &&
 
396
          strcmp(log_msg_get_value(self->last_msg, LM_V_HOST, NULL), log_msg_get_value(lm, LM_V_HOST, NULL)) == 0 &&
 
397
          strcmp(log_msg_get_value(self->last_msg, LM_V_PROGRAM, NULL), log_msg_get_value(lm, LM_V_PROGRAM, NULL)) == 0 &&
 
398
          strcmp(log_msg_get_value(self->last_msg, LM_V_PID, NULL), log_msg_get_value(lm, LM_V_PID, NULL)) == 0 &&
 
399
          strcmp(log_msg_get_value(lm, LM_V_MESSAGE, NULL), "-- MARK --") != 0)
393
400
        {
394
401
          stats_counter_inc(self->suppressed_messages);
395
402
          msg_debug("Suppressing duplicate message",
396
 
                    evt_tag_str("host", lm->host),
397
 
                    evt_tag_str("msg", lm->message),
 
403
                    evt_tag_str("host", log_msg_get_value(lm, LM_V_HOST, NULL)),
 
404
                    evt_tag_str("msg", log_msg_get_value(lm, LM_V_MESSAGE, NULL)),
398
405
                    NULL);
399
406
          self->last_msg_count++;
400
407
          
448
455
}
449
456
 
450
457
static void
451
 
log_writer_append_value(GString *result, const gchar *value, gint value_len, gboolean use_nil, gboolean append_space)
 
458
log_writer_append_value(GString *result, LogMessage *lm, NVHandle handle, gboolean use_nil, gboolean append_space)
452
459
{
 
460
  const gchar *value;
 
461
  gssize value_len;
 
462
 
 
463
  value = log_msg_get_value(lm, handle, &value_len);
453
464
  if (use_nil && value_len == 0)
454
465
    g_string_append_c(result, '-');
455
466
  else
473
484
  LogTemplate *template = NULL;
474
485
  LogStamp *stamp;
475
486
  guint32 seq_num;
476
 
  
 
487
  static NVHandle meta_seqid = 0;
 
488
 
 
489
  if (!meta_seqid)
 
490
    meta_seqid = log_msg_get_value_handle(".SDATA.meta.sequenceId");
 
491
 
477
492
  if (lm->flags & LF_LOCAL)
478
493
    {
479
494
      seq_num = self->seq_num;
480
495
    }
481
496
  else
482
497
    {
483
 
      const gchar *sequence_id;
484
 
      
485
 
      sequence_id = log_msg_lookup_sdata(lm, "meta.sequenceId", 15);
486
 
      if (sequence_id)
487
 
        seq_num = strtol(sequence_id, NULL, 10);
 
498
      const gchar *seqid;
 
499
      gssize seqid_length;
 
500
 
 
501
      seqid = log_msg_get_value(lm, meta_seqid, &seqid_length);
 
502
      seqid = APPEND_ZERO(seqid, seqid_length);
 
503
      if (seqid[0])
 
504
        seq_num = strtol(seqid, NULL, 10);
488
505
      else
489
506
        seq_num = 0;
490
507
    }
491
 
 
492
508
  
493
509
  /* no template was specified, use default */
494
510
  if (self->options->use_time_recvd)
508
524
                              self->options->frac_digits);
509
525
      g_string_append_c(result, ' ');
510
526
      
511
 
      log_writer_append_value(result, lm->host, lm->host_len, TRUE, TRUE);
512
 
      log_writer_append_value(result, lm->program, lm->program_len, TRUE, TRUE);
513
 
      log_writer_append_value(result, lm->pid, lm->pid_len, TRUE, TRUE);
514
 
      log_writer_append_value(result, lm->msgid, lm->msgid_len, TRUE, TRUE);
515
 
      
 
527
      log_writer_append_value(result, lm, LM_V_HOST, TRUE, TRUE);
 
528
      log_writer_append_value(result, lm, LM_V_PROGRAM, TRUE, TRUE);
 
529
      log_writer_append_value(result, lm, LM_V_PID, TRUE, TRUE);
 
530
      log_writer_append_value(result, lm, LM_V_MSGID, TRUE, TRUE);
 
531
 
 
532
#if 0
516
533
      if (lm->flags & LF_LOCAL)
517
534
        {
518
535
          gchar sequence_id[16];
520
537
          g_snprintf(sequence_id, sizeof(sequence_id), "%d", seq_num);
521
538
          log_msg_update_sdata(lm, "meta", "sequenceId", sequence_id);
522
539
        }
 
540
#endif
523
541
      len = result->len;
524
542
      log_msg_append_format_sdata(lm, result);
525
543
      if (len == result->len)
541
559
                                     seq_num,
542
560
                                     result);
543
561
        }
544
 
      else if (lm->message_len != 0)
 
562
      else
545
563
        {
 
564
          const gchar *p;
 
565
          gssize len;
 
566
 
 
567
          p = log_msg_get_value(lm, LM_V_MESSAGE, &len);
546
568
          g_string_append_c(result, ' ');
547
 
          if (lm->flags & LF_UTF8)
548
 
            g_string_append_len(result, "\xEF\xBB\xBF", 3);
549
 
          g_string_append_len(result, lm->message, lm->message_len);
 
569
          if (len != 0)
 
570
            {
 
571
              if (lm->flags & LF_UTF8)
 
572
                g_string_append_len(result, "\xEF\xBB\xBF", 3);
 
573
 
 
574
              g_string_append_len(result, p, len);
 
575
            }
550
576
        }
551
577
      g_string_append_c(result, '\n');
552
578
    }
579
605
        }
580
606
      else 
581
607
        {
582
 
     
 
608
          const gchar *p;
 
609
          gssize len;
 
610
 
583
611
          if (self->flags & LW_FORMAT_FILE)
584
612
            {
585
613
              log_stamp_format(stamp, result, self->options->ts_format,
597
625
            }
598
626
          g_string_append_c(result, ' ');
599
627
 
600
 
          g_string_append_len(result, lm->host, lm->host_len);
 
628
          p = log_msg_get_value(lm, LM_V_HOST, &len);
 
629
          g_string_append_len(result, p, len);
601
630
          g_string_append_c(result, ' ');
602
631
 
603
632
          if ((lm->flags & LF_LEGACY_MSGHDR))
604
633
            {
605
 
              gssize length;
606
 
              const gchar *msghdr;
607
 
 
608
 
              msghdr = log_msg_get_value(lm, "LEGACY_MSGHDR", &length);
609
 
              if (msghdr)
610
 
                {
611
 
                  g_string_append_len(result, msghdr, length);
612
 
                }
 
634
              p = log_msg_get_value(lm, LM_V_LEGACY_MSGHDR, &len);
 
635
              g_string_append_len(result, p, len);
613
636
            }
614
 
          else if (lm->program_len > 0)
 
637
          else
615
638
            {
616
 
              g_string_append_len(result, lm->program, lm->program_len);
617
 
              if (lm->pid_len > 0)
 
639
              p = log_msg_get_value(lm, LM_V_PROGRAM, &len);
 
640
              if (len > 0)
618
641
                {
619
 
                  g_string_append_c(result, '[');
620
 
                  g_string_append_len(result, lm->pid, lm->pid_len);
621
 
                  g_string_append_c(result, ']');
 
642
                  g_string_append_len(result, p, len);
 
643
                  p = log_msg_get_value(lm, LM_V_PID, &len);
 
644
                  if (len > 0)
 
645
                    {
 
646
                      g_string_append_c(result, '[');
 
647
                      g_string_append_len(result, p, len);
 
648
                      g_string_append_c(result, ']');
 
649
                    }
 
650
                  g_string_append_len(result, ": ", 2);
622
651
                }
623
 
              g_string_append_len(result, ": ", 2);
624
652
            }
625
 
          g_string_append_len(result, lm->message, lm->message_len);
 
653
          p = log_msg_get_value(lm, LM_V_MESSAGE, &len);
 
654
          g_string_append_len(result, p, len);
626
655
          g_string_append_c(result, '\n');
627
656
 
628
657
        }