Changeset 5ebff60 for log.c


Ignore:
Timestamp:
2015-02-20T22:50:54Z (8 years ago)
Author:
dequis <dx@…>
Branches:
master
Children:
0b9daac, 3d45471, 7733b8c
Parents:
af359b4
git-author:
Indent <please@…> (19-02-15 05:47:20)
git-committer:
dequis <dx@…> (20-02-15 22:50:54)
Message:

Reindent everything to K&R style with tabs

Used uncrustify, with the configuration file in ./doc/uncrustify.cfg

Commit author set to "Indent <please@…>" so that it's easier to
skip while doing git blame.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • log.c

    raf359b4 r5ebff60  
    1   /********************************************************************\
     1/********************************************************************\
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
     
    55  \********************************************************************/
    66
    7 /* Logging services for the bee                         */
     7/* Logging services for the bee                         */
    88
    99/*
     
    3535static void log_console(int level, const char *logmessage);
    3636
    37 void log_init(void) {
    38         openlog("bitlbee", LOG_PID, LOG_DAEMON);       
     37void log_init(void)
     38{
     39        openlog("bitlbee", LOG_PID, LOG_DAEMON);
    3940
    4041        logoutput.informational = &log_null;
     
    4849}
    4950
    50 void log_link(int level, int output) {
     51void log_link(int level, int output)
     52{
    5153        /* I know it's ugly, but it works and I didn't feel like messing with pointer to function pointers */
    5254
    53         if(level == LOGLVL_INFO) {
    54                 if(output == LOGOUTPUT_NULL)
    55                         logoutput.informational = &log_null;   
    56                 else if(output == LOGOUTPUT_IRC)
    57                         logoutput.informational = &log_irc;     
    58                 else if(output == LOGOUTPUT_SYSLOG)
    59                         logoutput.informational = &log_syslog; 
    60                 else if(output == LOGOUTPUT_CONSOLE)
    61                         logoutput.informational = &log_console; 
    62         }
    63         else if(level == LOGLVL_WARNING) {
    64                 if(output == LOGOUTPUT_NULL)
     55        if (level == LOGLVL_INFO) {
     56                if (output == LOGOUTPUT_NULL) {
     57                        logoutput.informational = &log_null;
     58                } else if (output == LOGOUTPUT_IRC) {
     59                        logoutput.informational = &log_irc;
     60                } else if (output == LOGOUTPUT_SYSLOG) {
     61                        logoutput.informational = &log_syslog;
     62                } else if (output == LOGOUTPUT_CONSOLE) {
     63                        logoutput.informational = &log_console;
     64                }
     65        } else if (level == LOGLVL_WARNING) {
     66                if (output == LOGOUTPUT_NULL) {
    6567                        logoutput.warning = &log_null;
    66                 else if(output == LOGOUTPUT_IRC)
     68                } else if (output == LOGOUTPUT_IRC) {
    6769                        logoutput.warning = &log_irc;
    68                 else if(output == LOGOUTPUT_SYSLOG)
     70                } else if (output == LOGOUTPUT_SYSLOG) {
    6971                        logoutput.warning = &log_syslog;
    70                 else if(output == LOGOUTPUT_CONSOLE)
     72                } else if (output == LOGOUTPUT_CONSOLE) {
    7173                        logoutput.warning = &log_console;
    72         }
    73         else if(level == LOGLVL_ERROR) {
    74                 if(output == LOGOUTPUT_NULL)
     74                }
     75        } else if (level == LOGLVL_ERROR) {
     76                if (output == LOGOUTPUT_NULL) {
    7577                        logoutput.error = &log_null;
    76                 else if(output == LOGOUTPUT_IRC)
     78                } else if (output == LOGOUTPUT_IRC) {
    7779                        logoutput.error = &log_irc;
    78                 else if(output == LOGOUTPUT_SYSLOG)
     80                } else if (output == LOGOUTPUT_SYSLOG) {
    7981                        logoutput.error = &log_syslog;
    80                 else if(output == LOGOUTPUT_CONSOLE)
     82                } else if (output == LOGOUTPUT_CONSOLE) {
    8183                        logoutput.error = &log_console;
    82         }
    83 #ifdef DEBUG
    84         else if(level == LOGLVL_DEBUG) {
    85                 if(output == LOGOUTPUT_NULL)
     84                }
     85        }
     86#ifdef DEBUG
     87        else if (level == LOGLVL_DEBUG) {
     88                if (output == LOGOUTPUT_NULL) {
    8689                        logoutput.debug = &log_null;
    87                 else if(output == LOGOUTPUT_IRC)
     90                } else if (output == LOGOUTPUT_IRC) {
    8891                        logoutput.debug = &log_irc;
    89                 else if(output == LOGOUTPUT_SYSLOG)
     92                } else if (output == LOGOUTPUT_SYSLOG) {
    9093                        logoutput.debug = &log_syslog;
    91                 else if(output == LOGOUTPUT_CONSOLE)
     94                } else if (output == LOGOUTPUT_CONSOLE) {
    9295                        logoutput.debug = &log_console;
    93         }
    94 #endif
    95         return;
    96 
    97 }
    98 
    99 void log_message(int level, const char *message, ... ) {
     96                }
     97        }
     98#endif
     99        return;
     100
     101}
     102
     103void log_message(int level, const char *message, ...)
     104{
    100105
    101106        va_list ap;
     
    106111        va_end(ap);
    107112
    108         if(level == LOGLVL_INFO)
     113        if (level == LOGLVL_INFO) {
    109114                (*(logoutput.informational))(level, msgstring);
    110         if(level == LOGLVL_WARNING)
     115        }
     116        if (level == LOGLVL_WARNING) {
    111117                (*(logoutput.warning))(level, msgstring);
    112         if(level == LOGLVL_ERROR)
     118        }
     119        if (level == LOGLVL_ERROR) {
    113120                (*(logoutput.error))(level, msgstring);
    114 #ifdef DEBUG
    115         if(level == LOGLVL_DEBUG)
     121        }
     122#ifdef DEBUG
     123        if (level == LOGLVL_DEBUG) {
    116124                (*(logoutput.debug))(level, msgstring);
     125        }
    117126#endif
    118127
    119128        g_free(msgstring);
    120        
    121         return;
    122 }
    123 
    124 void log_error(const char *functionname) {
     129
     130        return;
     131}
     132
     133void log_error(const char *functionname)
     134{
    125135        log_message(LOGLVL_ERROR, "%s: %s", functionname, strerror(errno));
    126        
    127         return;
    128 }
    129 
    130 static void log_null(int level, const char *message) {
    131         return;
    132 }
    133 
    134 static void log_irc(int level, const char *message) {
    135         if(level == LOGLVL_ERROR)
     136
     137        return;
     138}
     139
     140static void log_null(int level, const char *message)
     141{
     142        return;
     143}
     144
     145static void log_irc(int level, const char *message)
     146{
     147        if (level == LOGLVL_ERROR) {
    136148                irc_write_all(1, "ERROR :Error: %s", message);
    137         if(level == LOGLVL_WARNING)
     149        }
     150        if (level == LOGLVL_WARNING) {
    138151                irc_write_all(0, "ERROR :Warning: %s", message);
    139         if(level == LOGLVL_INFO)
    140                 irc_write_all(0, "ERROR :Informational: %s", message); 
    141 #ifdef DEBUG
    142         if(level == LOGLVL_DEBUG)
    143                 irc_write_all(0, "ERROR :Debug: %s", message); 
    144 #endif 
    145 
    146         return;
    147 }
    148 
    149 static void log_syslog(int level, const char *message) {
    150         if(level == LOGLVL_ERROR)
     152        }
     153        if (level == LOGLVL_INFO) {
     154                irc_write_all(0, "ERROR :Informational: %s", message);
     155        }
     156#ifdef DEBUG
     157        if (level == LOGLVL_DEBUG) {
     158                irc_write_all(0, "ERROR :Debug: %s", message);
     159        }
     160#endif
     161
     162        return;
     163}
     164
     165static void log_syslog(int level, const char *message)
     166{
     167        if (level == LOGLVL_ERROR) {
    151168                syslog(LOG_ERR, "%s", message);
    152         if(level == LOGLVL_WARNING)
     169        }
     170        if (level == LOGLVL_WARNING) {
    153171                syslog(LOG_WARNING, "%s", message);
    154         if(level == LOGLVL_INFO)
     172        }
     173        if (level == LOGLVL_INFO) {
    155174                syslog(LOG_INFO, "%s", message);
    156 #ifdef DEBUG
    157         if(level == LOGLVL_DEBUG)
     175        }
     176#ifdef DEBUG
     177        if (level == LOGLVL_DEBUG) {
    158178                syslog(LOG_DEBUG, "%s", message);
    159 #endif
    160         return;
    161 }
    162 
    163 static void log_console(int level, const char *message) {
    164         if(level == LOGLVL_ERROR)
     179        }
     180#endif
     181        return;
     182}
     183
     184static void log_console(int level, const char *message)
     185{
     186        if (level == LOGLVL_ERROR) {
    165187                fprintf(stderr, "Error: %s\n", message);
    166         if(level == LOGLVL_WARNING)
     188        }
     189        if (level == LOGLVL_WARNING) {
    167190                fprintf(stderr, "Warning: %s\n", message);
    168         if(level == LOGLVL_INFO)
     191        }
     192        if (level == LOGLVL_INFO) {
    169193                fprintf(stdout, "Informational: %s\n", message);
    170 #ifdef DEBUG
    171         if(level == LOGLVL_DEBUG)
     194        }
     195#ifdef DEBUG
     196        if (level == LOGLVL_DEBUG) {
    172197                fprintf(stdout, "Debug: %s\n", message);
     198        }
    173199#endif
    174200        /* Always log stuff in syslogs too. */
Note: See TracChangeset for help on using the changeset viewer.