LTP GCOV extension - code coverage report
Current view: directory - src/utils/logger - min_system_logger.c
Test: min.info
Date: 2009-06-18 Instrumented lines: 47
Code covered: 89.4 % Executed lines: 42

       1                 : /*
       2                 :  * This file is part of MIN Test Framework. Copyright © 2008 Nokia Corporation
       3                 :  * and/or its subsidiary(-ies).
       4                 :  * Contact: Sampo Saaristo
       5                 :  * Contact e-mail: DG.MIN-Support@nokia.com
       6                 :  * 
       7                 :  * This program is free software: you can redistribute it and/or modify it 
       8                 :  * under the terms of the GNU General Public License as published by the Free 
       9                 :  * Software Foundation, version 2 of the License. 
      10                 :  * 
      11                 :  * This program is distributed in the hope that it will be useful, but WITHOUT 
      12                 :  * ANY WARRANTY; without even the implied warranty of  MERCHANTABILITY or 
      13                 :  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General  Public License for
      14                 :  * more details. You should have received a copy of the GNU General Public 
      15                 :  * License along with this program. If not,  see 
      16                 :  * <http://www.gnu.org/licenses/>.
      17                 :  */
      18                 : 
      19                 : 
      20                 : /**
      21                 :  *  @file       min_system_logger.c
      22                 :  *  @version    0.1
      23                 :  *  @brief      This file contains implementation of MIN System logger API
      24                 :  */
      25                 : 
      26                 : 
      27                 : /* ------------------------------------------------------------------------- */
      28                 : /* INCLUDE FILES */
      29                 : 
      30                 : #include <stdio.h>
      31                 : #include <stdlib.h>
      32                 : #include <stdarg.h>
      33                 : #include <syslog.h>
      34                 : 
      35                 : #include <min_common.h>
      36                 : #include <min_logger.h>
      37                 : #include <min_system_logger.h>
      38                 : 
      39                 : /* ------------------------------------------------------------------------- */
      40                 : /* EXTERNAL DATA STRUCTURES */
      41                 : /* None */
      42                 : 
      43                 : /* ------------------------------------------------------------------------- */
      44                 : /* EXTERNAL FUNCTION PROTOTYPES */
      45                 : /* None */
      46                 : 
      47                 : /* ------------------------------------------------------------------------- */
      48                 : /* CONSTANTS */
      49                 : /* None */
      50                 : 
      51                 : /* ------------------------------------------------------------------------- */
      52                 : /* MACROS */
      53                 : /* None */
      54                 : 
      55                 : /* ------------------------------------------------------------------------- */
      56                 : /* LOCAL CONSTANTS AND MACROS */
      57                 : /** maximum size for format string in debug messages */
      58                 : #define FMT_MAX_SIZE 255
      59                 : 
      60                 : /* ------------------------------------------------------------------------- */
      61                 : /* MODULE DATA STRUCTURES */
      62                 : MinLogger *__logger__ = INITPTR;
      63                 : Text *__component_name__ = INITPTR;
      64                 : 
      65                 : /* ------------------------------------------------------------------------- */
      66                 : /* LOCAL FUNCTION PROTOTYPES */
      67                 : 
      68                 : /** Writes min log by calling vsyslog() system function
      69                 :  * @return 1 if priority is invalid, 0 on ok.
      70                 :  * @param priority min message priority LOG_DEBUG .. 
      71                 :  * @param format message formatting string as in e.g. printf (3)e
      72                 :  * @param ap var args strucuture (/usr/include/stdarg.h)
      73                 :  */
      74                 : LOCAL int       min_log (int priority, const char *format, va_list ap);
      75                 : 
      76                 : /* ------------------------------------------------------------------------- */
      77                 : /* FORWARD DECLARATIONS */
      78                 : /* None */
      79                 : 
      80                 : /* ==================== LOCAL FUNCTIONS ==================================== */
      81                 : /* None */
      82                 : 
      83                 : LOCAL int min_log (int priority, const char *format, va_list ap)
      84              24 : {
      85                 : 
      86              24 :         if (priority < LOG_EMERG || priority > LOG_DEBUG)
      87               0 :                 return 1;
      88                 : 
      89              24 :         vsyslog (priority, format, ap);
      90                 : 
      91              24 :         return 0;
      92                 : }
      93                 : 
      94                 : 
      95                 : /* ======================== FUNCTIONS ====================================== */
      96                 : 
      97                 : /* ------------------------------------------------------------------------- */
      98                 : 
      99                 : int min_log_open (const char *identifier, unsigned int debug_level)
     100             343 : {
     101             343 :         if (__component_name__==INITPTR) {
     102             228 :                 __component_name__=tx_create(identifier);
     103                 :         } else {
     104             115 :                 tx_c_copy(__component_name__,identifier);
     105                 :         }
     106                 : 
     107             343 :         if (__logger__!=INITPTR) { mnl_destroy(&__logger__); }
     108                 : 
     109             343 :         __logger__ = mnl_create("/tmp","minlog.txt",
     110                 :                                 MinLoggerDefaultValues);
     111             343 :         return 0;
     112                 : }
     113                 : 
     114                 : /* ------------------------------------------------------------------------- */
     115                 : 
     116                 : int min_log_close ()
     117             114 : {
     118             114 :         if (__component_name__!=INITPTR) {
     119             111 :                 tx_destroy(&__component_name__);
     120             111 :                 __component_name__ = INITPTR;
     121                 :         }
     122             114 :         if (__logger__!=INITPTR) {
     123             111 :                 mnl_destroy(&__logger__);
     124             111 :                 __logger__ = INITPTR;
     125                 :         }
     126                 : 
     127             114 :         return 0;
     128                 : }
     129                 : 
     130                 : /* ------------------------------------------------------------------------- */
     131                 : 
     132                 : int min_emerg (const char *format, ...)
     133               0 : {
     134                 :         va_list         ap;
     135                 : 
     136               0 :         va_start (ap, format);
     137                 : #if 0
     138                 :         vmnl_log(sys_logger,ESFatal,format,ap); 
     139                 : 
     140                 :         min_log (LOG_EMERG, format, ap);
     141                 : #endif
     142               0 :         va_end (ap);
     143                 : 
     144               0 :         return 0;
     145                 : }
     146                 : 
     147                 : /* ------------------------------------------------------------------------- */
     148                 : 
     149                 : int min_err (const char *format, ...)
     150               2 : {
     151                 :         va_list         ap;
     152                 : 
     153               2 :         va_start (ap, format);
     154               2 :         min_log (LOG_ERR, format, ap);
     155               2 :         va_end (ap);
     156                 : 
     157               2 :         return 0;
     158                 : }
     159                 : 
     160                 : /* ------------------------------------------------------------------------- */
     161                 : 
     162                 : int min_warn (const char *format, ...)
     163               1 : {
     164                 :         va_list         ap;
     165                 : 
     166               1 :         va_start (ap, format);
     167               1 :         min_log (LOG_WARNING, format, ap);
     168               1 :         va_end (ap);
     169                 : 
     170               1 :         return 0;
     171                 : }
     172                 : 
     173                 : /* ------------------------------------------------------------------------- */
     174                 : 
     175                 : int min_info (const char *format, ...)
     176               4 : {
     177                 :         va_list         ap;
     178                 : 
     179               4 :         va_start (ap, format);
     180               4 :         min_log (LOG_INFO, format, ap);
     181               4 :         va_end (ap);
     182                 : 
     183               4 :         return 0;
     184                 : }
     185                 : 
     186                 : /* ------------------------------------------------------------------------- */
     187                 : 
     188                 : int min_debug (const char *func, unsigned int lineno, const char *file_name,
     189                 :                 const char *format, ...)
     190              17 : {
     191                 :         char            fmt[FMT_MAX_SIZE];
     192                 :         va_list         ap, ap2;
     193                 : 
     194              17 :         sprintf (fmt, "%s:%d:%s():%s", file_name, lineno, func, format);
     195              17 :         va_start (ap, format);
     196              17 :         va_copy (ap2, ap);
     197              17 :         min_log (LOG_INFO, fmt, ap2);
     198              17 :         va_end (ap);
     199              17 :         va_end (ap2);
     200                 : 
     201              17 :         return 0;
     202                 : }
     203                 : 
     204                 : /* ================= TESTS FOR LOCAL FUNCTIONS ============================= */
     205                 : #if 0                           /* def MIN_UNIT_TEST (None) */
     206                 : #include "check.h"
     207                 : 
     208                 : /* ------------------------------------------------------------------------- */
     209                 : 
     210                 : int template_tests ()
     211                 : {
     212                 :         int             number_failed;
     213                 : 
     214                 :         number_failed = 0;
     215                 : 
     216                 :         return number_failed;
     217                 : }
     218                 : 
     219                 : /* ------------------------------------------------------------------------- */
     220                 : 
     221                 : #endif  /* 0 */                        /* MIN_UNIT_TEST */
     222                 : 
     223                 : /* End of file */

Generated by: LTP GCOV extension version 1.6