"Fossies" - the Fresh Open Source Software Archive

Member "mlmmj-1.3.0/contrib/receivestrip/mlmmj_src/log_error.c" (13 Mar 2012, 2121 Bytes) of package /linux/privat/mlmmj-1.3.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2004 Morten K. Poulsen <morten at afdelingp.dk>
    2  *
    3  * $Id$
    4  *
    5  * Permission is hereby granted, free of charge, to any person obtaining a copy
    6  * of this software and associated documentation files (the "Software"), to
    7  * deal in the Software without restriction, including without limitation the
    8  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    9  * sell copies of the Software, and to permit persons to whom the Software is
   10  * furnished to do so, subject to the following conditions:
   11  *
   12  * The above copyright notice and this permission notice shall be included in
   13  * all copies or substantial portions of the Software.
   14  *
   15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
   18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
   21  * IN THE SOFTWARE.
   22  */
   23 
   24 #include <stdio.h>
   25 #include <string.h>
   26 #include <stdlib.h>
   27 #include <stdarg.h>
   28 #include <sys/types.h>
   29 #include <unistd.h>
   30 
   31 #include "log_error.h"
   32 #include "config.h"
   33 #include "memory.h"
   34 
   35 #ifdef HAVE_SYSLOG_H
   36 #include <syslog.h>
   37 #endif
   38 
   39 char *log_name = NULL;
   40 
   41 void log_set_name(const char* name)
   42 {
   43     if (log_name) myfree(log_name);
   44     log_name = mystrdup(name);
   45 }
   46 
   47 void log_free_name()
   48 {
   49     myfree(log_name);
   50 }
   51 
   52 void log_error(const char *file, int line, const char *errstr,
   53     const char *fmt, ...)
   54 {
   55     static int syslog_is_open = 0;
   56     char buf[1024];
   57     va_list ap;
   58 
   59     va_start(ap, fmt);
   60     vsnprintf(buf, sizeof(buf), fmt, ap);
   61     va_end(ap);
   62 
   63     if (!log_name) log_name = "mlmmj-UNKNOWN";
   64 
   65 #ifdef HAVE_SYSLOG
   66     if(!syslog_is_open) {
   67         openlog(log_name, LOG_PID|LOG_CONS, LOG_MAIL);
   68         syslog_is_open = 1;
   69     }
   70     syslog(LOG_ERR, "%s:%d: %s: %s", file, line, buf, errstr);
   71 #else
   72     fprintf(stderr, "%s[%d]: %s:%d: %s: %s\n", log_name, (int)getpid(),
   73             file, line, buf, errstr);
   74 #endif
   75 }