LCOV - code coverage report
Current view: top level - lib - logger.c (source / functions) Hit Total Coverage
Test: smtpd.info Lines: 19 29 65.5 %
Date: 2015-11-25 19:06:20 Functions: 1 2 50.0 %

          Line data    Source code
       1             : /* This file is part of the cmail project (http://cmail.rocks/)
       2             :  * (c) 2015 Fabian "cbdev" Stumpf
       3             :  * License: Simplified BSD (2-Clause)
       4             :  * For further information, consult LICENSE.txt
       5             :  */
       6             : 
       7        4571 : void logprintf(LOGGER log, unsigned level, char* fmt, ...){
       8             :         va_list args;
       9             :         va_list copy;
      10             :         char timestring[LOGGER_TIMESTRING_LEN];
      11             : 
      12        4571 :         va_start(args, fmt);
      13             : 
      14        4571 :         if(log.print_timestamp){
      15        4571 :                 if(common_tprintf("%a, %d %b %Y %T %z", time(NULL), timestring, sizeof(timestring) - 1) < 0){
      16           0 :                         snprintf(timestring, sizeof(timestring)-1, "Time failed");
      17             :                 }
      18             :         }
      19             : 
      20        4571 :         if(log.log_secondary){
      21          53 :                 if(log.verbosity >= level){
      22          53 :                         va_copy(copy, args);
      23          53 :                         if(log.print_timestamp){
      24          53 :                                 fprintf(stderr, "%s ", timestring);
      25             :                         }
      26          53 :                         vfprintf(stderr, fmt, copy);
      27          53 :                         fflush(stderr);
      28          53 :                         va_end(copy);
      29             :                 }
      30             :         }
      31             : 
      32        4571 :         if(log.verbosity >= level){
      33        4571 :                 if(log.print_timestamp){
      34        4571 :                         fprintf(log.stream, "%s ", timestring);
      35             :                 }
      36        4571 :                 vfprintf(log.stream, fmt, args);
      37        4571 :                 fflush(log.stream);
      38             :         }
      39        4571 :         va_end(args);
      40        4571 : }
      41             : 
      42           0 : void log_dump_buffer(LOGGER log, unsigned level, void* buffer, size_t bytes){
      43           0 :         uint8_t* data = (uint8_t*)buffer;
      44             :         size_t i;
      45             : 
      46           0 :         logprintf(log, level, "Buffer dump (%d bytes)\n", bytes);
      47             : 
      48           0 :         for(i = 0; i < bytes; i++){
      49           0 :                 logprintf(log, level, "(%d, %c, %02x)", i, isprint(data[i]) ? data[i]:'.', data[i]);
      50           0 :                 if(i && i % 8 == 0){
      51           0 :                         logprintf(log, level, "\n");
      52             :                 }
      53             :         }
      54             : 
      55           0 :         logprintf(log, level, "\n");
      56           0 : }

Generated by: LCOV version 1.11