Navigation


Changeset 961:d95cd3ca9e8d in freeDiameter for libfdproto/log.c


Ignore:
Timestamp:
Mar 7, 2013, 4:09:54 AM (11 years ago)
Author:
Thomas Klausner <tk@giga.or.at>
Branch:
default
Parents:
960:f39fa6cd86e0 (diff), 933:04f590da5821 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

merge latest 1.1 branch (one commit post 1.1.6)

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libfdproto/log.c

    r928 r961  
    4444int fd_g_debug_lvl = INFO;
    4545
     46static void fd_internal_logger( int, const char *, va_list );
     47
    4648/* These may be used to pass specific debug requests via the command-line parameters */
    4749char * fd_debug_one_function = NULL;
     
    5355
    5456/* Allow passing of the log and debug information from base stack to extensions */
    55 void (*fd_external_logger)( const char * format, va_list *args ) = NULL;
     57void (*fd_logger)( int loglevel, const char * format, va_list args ) = fd_internal_logger;
    5658
    57 /* Register an dexternal call back for tracing and debug */
    58 int fd_log_handler_register( void (*logger)(const char * format, va_list *args))
     59/* Register an external call back for tracing and debug */
     60int fd_log_handler_register( void (*logger)(int loglevel, const char * format, va_list args) )
    5961{
    6062        CHECK_PARAMS( logger );
    6163
    62         if ( fd_external_logger != NULL )
     64        if ( fd_logger != fd_internal_logger )
    6365        {
    6466               return EALREADY; /* only one registration allowed */
     
    6668        else
    6769        {
    68                fd_external_logger = logger;
     70               fd_logger = logger;
    6971        }
     72
    7073        return 0;
    7174}
     
    7477int fd_log_handler_unregister ( void )
    7578{
    76         fd_external_logger = NULL;
     79        fd_logger = fd_internal_logger;
    7780        return 0; /* Successfull in all cases. */
    7881}
     
    8386}
    8487
     88
     89static void fd_internal_logger( int loglevel, const char *format, va_list ap )
     90{
     91    char buf[25];
     92    FILE *fstr = fd_g_debug_fstr ?: stdout;
     93
     94    /* logging has been decided by macros outside already */
     95
     96    /* add timestamp */
     97    fprintf(fd_g_debug_fstr, "%s\t", fd_log_time(NULL, buf, sizeof(buf)));
     98    vfprintf(fd_g_debug_fstr, format, ap);
     99    if (format && (format[strlen(format)-1] != '\n')) {
     100        fprintf(fd_g_debug_fstr, "\n");
     101    }
     102    fflush(fd_g_debug_fstr);
     103}
     104
    85105/* Log a debug message */
    86 void fd_log_debug_fstr ( FILE * fstr, const char * format, ... )
     106void fd_log ( int loglevel, const char * format, ... )
    87107{
    88108        va_list ap;
     
    93113       
    94114        va_start(ap, format);
    95         if ( fd_external_logger != NULL )
    96         {
    97                fd_external_logger( format, &ap );
    98         }
    99         else
    100         {
    101                vfprintf( fstr ?: stdout, format, ap);
    102                fflush(fstr ?: stdout);
    103         }
     115        fd_logger(loglevel, format, ap);
    104116        va_end(ap);
    105117
     
    107119       
    108120        (void)pthread_mutex_unlock(&fd_log_lock);
     121}
     122
     123/* Log debug message to file. */
     124void fd_log_debug_fstr( FILE * fstr, const char * format, ... )
     125{
     126        va_list ap;
     127       
     128        va_start(ap, format);
     129        vfprintf(fstr, format, ap);
     130        va_end(ap);
    109131}
    110132
  • libfdproto/log.c

    r945 r961  
    33* Author: Sebastien Decugis <sdecugis@freediameter.net>                                                  *
    44*                                                                                                        *
    5 * Copyright (c) 2012, WIDE Project and NICT                                                              *
     5* Copyright (c) 2013, WIDE Project and NICT                                                              *
    66* All rights reserved.                                                                                   *
    77*                                                                                                        *
Note: See TracChangeset for help on using the changeset viewer.