File: err.c

package info (click to toggle)
skksearch 0.0-25
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 228 kB
  • sloc: ansic: 1,079; makefile: 23; sh: 18
file content (68 lines) | stat: -rw-r--r-- 1,427 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 1999 Hideki Sakurada
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <stdio.h>
#include <stdarg.h>
#include "err.h"

#define DEFAULT_LOGLEVEL 4;

/* -1(disabled), 0(the lowest) - 7(the highest) */
int loglevel  = DEFAULT_LOGLEVEL;
int use_syslog;
char *logfile;

static FILE *errout;


void openerr() {
  if (logfile != NULL)
    {
      errout = fopen(logfile, "a");
    }
#ifdef SYSLOG
  else
    if (use_syslog) {
      openlog(SYSLOG_IDENT, LOG_PID, SYSLOG_FACILITY);
    }
#endif /* SYSLOG */
  return;
}


void closeerr() {
  if (errout != NULL)
    fclose(errout);
#ifdef SYSLOG
  else if (use_syslog)
    closelog();
#endif /* SYSLOG */
}


void err(int priority, char *message, ...) {
  va_list argp;

  va_start(argp, message);

  if (errout != NULL) {
    if (loglevel >= priority)
      vfprintf(errout, message, argp);
  }
#ifdef SYSLOG
  else
    if (use_syslog) vsyslog(priority, message, argp);
#endif /* SYSLOG */
  va_end(argp);
}