source: TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_log.c @ 1369

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI05-delivery/trunk/src/bbftp-server-3.2.0/bbftpd/bbftpd_private_log.c@1369
Revision 1369, 1.8 KB checked in by spascoe, 13 years ago (diff)

Corrections to bbftp.h.in required rerunning autoconf.

Line 
1/*
2 * bbftpd/bbftpd_log.c
3 * Copyright (C) 2006, CCLRC
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 */
19
20/**
21 * A drop in replacement for syslog.
22 *
23 * @author Stephen Pascoe
24 */
25
26#include <bbftpd.h>
27
28#include <bbftpd_private_log.h>
29
30#include <stdlib.h>
31#include <stdio.h>
32#include <stdarg.h>
33#include <string.h>
34#include <errno.h>
35
36static const char *log_ident;
37static FILE *logfh = NULL;
38
39#define LOGFILE "bbftpd.log"
40
41/**
42 * Ignore option and facility arguments.
43 */
44void bbftpd_openlog(const char *ident, int option, int facility) {
45  log_ident = ident;
46
47  if (logfh != NULL) {
48    fclose(logfh);
49  }
50
51  if ((logfh = fopen(LOGFILE, "a")) == NULL) {
52    logfh = stderr;
53    bbftpd_log(LOG_ERR, "Failed to open logfile %s, %s.  Using stderr", LOGFILE, strerror(errno));
54  }
55
56  return;
57}
58
59void bbftpd_closelog(void) {
60
61  if (logfh != NULL) {
62    fclose(logfh);
63    logfh = NULL;
64  }
65
66  return;
67}
68
69/**
70 * Ignore priority for now.
71 */
72void bbftpd_log(int priority, const char *format, ...) {
73  va_list ap;
74
75  va_start(ap, format);
76
77  if (logfh != NULL) {
78    fprintf(logfh, "%s: ", log_ident);
79    vfprintf(logfh, format, ap);
80    fprintf(logfh, "\n");
81  }
82  fflush(logfh);
83
84  va_end(ap);
85}
86
Note: See TracBrowser for help on using the repository browser.