LCOV - code coverage report
Current view: top level - src - Logger.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 19 30 63.3 %
Date: 2010-12-13 Functions: 5 9 55.6 %
Branches: 8 28 28.6 %

           Branch data     Line data    Source code
       1                 :            : // $Id: Logger.cc 6916 2009-09-24 20:48:36Z vern $
       2                 :            : //
       3                 :            : // See the file "COPYING" in the main distribution directory for copyright.
       4                 :            : 
       5                 :            : #include <stdlib.h>
       6                 :            : #include <math.h>
       7                 :            : #include <ctype.h>
       8                 :            : #include <syslog.h>
       9                 :            : 
      10                 :            : #include "config.h"
      11                 :            : #include "File.h"
      12                 :            : #include "Logger.h"
      13                 :            : 
      14                 :            : #ifdef SYSLOG_INT
      15                 :            : extern "C" {
      16                 :            : int openlog(const char* ident, int logopt, int facility);
      17                 :            : int syslog(int priority, const char* message_fmt, ...);
      18                 :            : int closelog();
      19                 :            : }
      20                 :            : #endif
      21                 :            : 
      22                 :          1 : Logger::Logger(const char* name, BroFile* arg_f)
      23                 :            :         {
      24                 :          1 :         openlog(name, 0, LOG_LOCAL5);
      25                 :          1 :         f = arg_f;
      26                 :          1 :         enabled = 1;
      27                 :          1 :         }
      28                 :            : 
      29                 :          1 : Logger::~Logger()
      30                 :            :         {
      31                 :          1 :         closelog();
      32                 :          1 :         Unref(f);
      33 [ +  - ][ #  # ]:          1 :         }
                 [ #  # ]
      34                 :            : 
      35                 :       1379 : void Logger::Log(const char* msg)
      36                 :            :         {
      37                 :            :         int has_timestamp =
      38                 :            :                 (fabs(atof(msg) - network_time) <= 30.0) ||
      39 [ +  - ][ -  + ]:       1379 :                 (msg[0] == 't' && msg[1] == '=' && isdigit(msg[2]));
         [ #  # ][ #  # ]
      40                 :            : 
      41         [ -  + ]:       1379 :         if ( enabled )
      42                 :            :                 {
      43                 :          0 :                 const char* sub_msg = msg;
      44         [ #  # ]:          0 :                 if ( has_timestamp )
      45                 :            :                         {
      46                 :            :                         // Don't include the timestamp in the logging,
      47                 :            :                         // as it gets tacked on by syslog anyway.
      48                 :          0 :                         sub_msg = strchr(sub_msg, ' ');
      49         [ #  # ]:          0 :                         if ( sub_msg )
      50                 :          0 :                                 ++sub_msg;      // skip over ' '
      51                 :            :                         else
      52                 :          0 :                                 sub_msg = msg;
      53                 :            :                         }
      54                 :            : 
      55                 :          0 :                 syslog(LOG_NOTICE, "%s", sub_msg);
      56                 :            :                 }
      57                 :            : 
      58         [ +  - ]:       1379 :         if ( f )
      59                 :            :                 {
      60         [ -  + ]:       1379 :                 if ( has_timestamp )
      61                 :          0 :                         f->Write(fmt("%s\n", msg));
      62                 :            :                 else
      63                 :       1379 :                         f->Write(fmt("%.6f %s\n", network_time, msg));
      64                 :            : 
      65                 :       1379 :                 f->Flush();
      66                 :            :                 }
      67                 :       1379 :         }
      68                 :            : 
      69                 :          0 : void Logger::Describe(ODesc* d) const
      70                 :            :         {
      71                 :          0 :         d->AddSP("logger");
      72                 :          0 :         f->Describe(d);
      73 [ +  - ][ +  - ]:          6 :         }

Generated by: LCOV version 1.8