Flowgrind
Advanced TCP traffic generator
fg_log.c File Reference
#include <syslog.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include "fg_log.h"
#include "fg_time.h"
#include "fg_error.h"

Go to the source code of this file.

Functions

void close_logging (void)
 Close logging stream. More...
 
void init_logging (enum log_streams stream)
 Open logging stream. More...
 
void logging (int priority, const char *fmt,...)
 
void vlogging (int priority, const char *fmt, va_list ap)
 

Variables

static enum log_streams log_stream = LOG_SYSLOG
 

Function Documentation

void close_logging ( void  )

Close logging stream.

Definition at line 57 of file fg_log.c.

58 {
59  switch (log_stream) {
60  case LOGGING_SYSLOG:
61  closelog();
62  break;
63  case LOGGING_STDERR:
64  case LOGGING_STDOUT:
65  break;
66  }
67 }
Log to stderr.
Definition: fg_log.h:41
Log to syslog.
Definition: fg_log.h:39
Log to stdout.
Definition: fg_log.h:43
static enum log_streams log_stream
Definition: fg_log.c:41
void init_logging ( enum log_streams  stream)

Open logging stream.

Parameters
[in]streamto which output stream we log

Definition at line 43 of file fg_log.c.

44 {
45  log_stream = stream;
46 
47  switch (log_stream) {
48  case LOGGING_SYSLOG:
49  openlog("flowgrindd", LOG_NDELAY | LOG_CONS | LOG_PID, LOG_DAEMON);
50  break;
51  case LOGGING_STDERR:
52  case LOGGING_STDOUT:
53  break;
54  }
55 }
Log to stderr.
Definition: fg_log.h:41
Log to syslog.
Definition: fg_log.h:39
Log to stdout.
Definition: fg_log.h:43
static enum log_streams log_stream
Definition: fg_log.c:41
void logging ( int  priority,
const char *  fmt,
  ... 
)

Definition at line 69 of file fg_log.c.

70 {
71  va_list ap;
72 
73  va_start(ap, fmt);
74  vlogging(priority, fmt, ap);
75  va_end(ap);
76 }
void vlogging(int priority, const char *fmt, va_list ap)
Definition: fg_log.c:78
void vlogging ( int  priority,
const char *  fmt,
va_list  ap 
)

Definition at line 78 of file fg_log.c.

79 {
80  char timestamp[30] = "";
81  ctimenow_r(timestamp, sizeof(timestamp), false);
82 
83  switch (log_stream) {
84  case LOGGING_SYSLOG:
85  vsyslog(priority, fmt, ap);
86  break;
87  case LOGGING_STDERR:
88  fprintf(stderr, "%s ", timestamp);
89  vfprintf(stderr, fmt, ap);
90  fprintf(stderr, "\n");
91  fflush(stderr);
92  break;
93  case LOGGING_STDOUT:
94  fprintf(stdout, "%s ", timestamp);
95  vfprintf(stdout, fmt, ap);
96  fprintf(stdout, "\n");
97  fflush(stdout);
98  break;
99  }
100 
101 }
Log to stderr.
Definition: fg_log.h:41
const char * ctimenow_r(char *buf, size_t size, bool ns)
Returns the current wall-clock time as null-terminated string.
Definition: fg_time.c:47
Log to syslog.
Definition: fg_log.h:39
Log to stdout.
Definition: fg_log.h:43
static enum log_streams log_stream
Definition: fg_log.c:41

Variable Documentation

enum log_streams log_stream = LOG_SYSLOG
static

Definition at line 41 of file fg_log.c.