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

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

BROKEN!

I'm in the middle of implementing a logging callback in the server.

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
36
37#ifdef NDG_PYTHON_EMBED
38
39void bbftpd_openlog(const char *ident, int option, int facility) {
40  return;
41}
42
43void bbftpd_closelog(void) {
44  return;
45}
46
47void bbftpd_log(int priority, const char *format, ...) {
48  va_list ap;
49
50  va_start(ap, format);
51  ndg_log(priority, format, ap);
52  va_end(ap);
53}
54
55#else // NDG_PYTHON_EMBED
56
57static const char *log_ident;
58static FILE *logfh = NULL;
59
60#define LOGFILE "bbftpd.log"
61
62
63/**
64 * Ignore option and facility arguments.
65 */
66void bbftpd_openlog(const char *ident, int option, int facility) {
67  log_ident = ident;
68
69  if (logfh != NULL) {
70    fclose(logfh);
71  }
72
73  if ((logfh = fopen(LOGFILE, "a")) == NULL) {
74    logfh = stderr;
75    bbftpd_log(LOG_ERR, "Failed to open logfile %s, %s.  Using stderr", LOGFILE, strerror(errno));
76  }
77
78  return;
79}
80
81void bbftpd_closelog(void) {
82
83  if (logfh != NULL) {
84    fclose(logfh);
85    logfh = NULL;
86  }
87
88  return;
89}
90
91/**
92 * Ignore priority for now.
93 */
94void bbftpd_log(int priority, const char *format, ...) {
95  va_list ap;
96
97  va_start(ap, format);
98
99  if (logfh != NULL) {
100    fprintf(logfh, "%s: ", log_ident);
101    vfprintf(logfh, format, ap);
102    fprintf(logfh, "\n");
103  }
104  fflush(logfh);
105
106  va_end(ap);
107}
108
109#endif // NDG_PYTHON_EMBED
Note: See TracBrowser for help on using the repository browser.