Ticket #6729: log_count_repeats_24221.patch

File log_count_repeats_24221.patch, 2.6 KB (added by kevin.wells@…, 2 years ago)

Count repeated log messages instead of logging them individually

  • mythtv/libs/libmythtv/avformatdecoder.cpp

     
    109109    if (VERBOSE_LEVEL_NONE) 
    110110        return; 
    111111 
     112    static QString prev_line(""); 
     113    static int count = 0; 
    112114    static QString full_line(""); 
    113115    static const int msg_len = 255; 
    114116    static QMutex string_lock; 
     
    157159    full_line += QString(str); 
    158160    if (full_line.endsWith("\n")) 
    159161    { 
    160         full_line.truncate(full_line.length() - 1); 
    161         VERBOSE(verbose_level, full_line); 
     162        if (full_line == prev_line) 
     163            ++count; 
     164        else 
     165        { 
     166            if (count > 0) 
     167            { 
     168                // Assume level same for repeated messages 
     169                snprintf(str, msg_len, 
     170                        "    Last message repeated %d times", count); 
     171                VERBOSE(verbose_level, str); 
     172                count = 0; 
     173            } 
     174 
     175            prev_line = full_line; 
     176 
     177            full_line.truncate(full_line.length() - 1); 
     178            VERBOSE(verbose_level, full_line); 
     179        } 
     180 
    162181        full_line.truncate(0); 
    163182    } 
    164183    string_lock.unlock(); 
  • mythtv/programs/mythtranscode/mpeg2fix.cpp

     
    5858 
    5959void my_av_print(void *ptr, int level, const char* fmt, va_list vl) 
    6060{ 
     61    static QString prev_line(""); 
     62    static int count = 0; 
    6163    (void) ptr; 
    6264 
    6365    static QString full_line(""); 
    64     char str[256]; 
     66    static const int msg_len = 255; 
     67    char str[msg_len + 1]; 
    6568 
    6669    if (level > AV_LOG_INFO) 
    6770        return; 
     
    7073    full_line += QString(str); 
    7174    if (full_line.endsWith("\n")) 
    7275    { 
    73         full_line.truncate(full_line.length() - 1); 
    74         VERBOSE(MPF_IMPORTANT, full_line); 
    75         full_line = QString(""); 
     76        if (full_line == prev_line) 
     77            ++count; 
     78        else 
     79        { 
     80            if (count > 0) 
     81            { 
     82                // Assume level same for repeated messages 
     83                snprintf(str, msg_len, 
     84                        "    Last message repeated %d times", count); 
     85                VERBOSE(MPF_IMPORTANT, str); 
     86                count = 0; 
     87            } 
     88 
     89            prev_line = full_line; 
     90 
     91            full_line.truncate(full_line.length() - 1); 
     92            VERBOSE(MPF_IMPORTANT, full_line); 
     93        } 
     94 
     95        full_line.truncate(0); 
    7696    } 
    7797} 
    7898