/[LeafOK_CVS]/lbbs/src/log.c
ViewVC logotype

Contents of /lbbs/src/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (show annotations)
Fri Oct 22 15:20:32 2004 UTC (21 years, 4 months ago) by sysadm
Branch: MAIN
Changes since 1.5: +21 -32 lines
Content type: text/x-csrc
*** empty log message ***

1 /***************************************************************************
2 log.c - description
3 -------------------
4 begin : Mon Oct 18 2004
5 copyright : (C) 2004 by leaf
6 email : leaflet@leafok.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "io.h"
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <time.h>
22
23 FILE *fp_log_std;
24 FILE *fp_log_err;
25
26 int
27 log_begin (char *file_log_std, char *file_log_err)
28 {
29 fp_log_std = fopen (file_log_std, "a");
30 if (fp_log_std == NULL)
31 {
32 perror ("log_begin failed\n");
33 return -1;
34 }
35
36 fp_log_err = fopen (file_log_err, "a");
37 if (fp_log_err == NULL)
38 {
39 perror ("log_begin failed\n");
40 return -2;
41 }
42
43 return 0;
44 }
45
46 int
47 log_end ()
48 {
49 fclose (fp_log_std);
50 fclose (fp_log_err);
51 }
52
53 int
54 log_head (char *buf)
55 {
56 time_t t;
57 char s_time[256];
58 t = time(0);
59
60 strftime(s_time,256,"%Y-%m-%d %H:%M:%S", localtime (&t));
61 sprintf(buf,"[%s] [%d] ", s_time, getpid());
62
63 return 0;
64 }
65
66 int
67 log_std(const char * format, ...)
68 {
69 va_list args;
70 int retval;
71 char buf[1024];
72
73 log_head(buf);
74 strcat(buf, format);
75
76 va_start (args, format);
77 retval = vfprintf (fp_log_std, format, args);
78 va_end (args);
79
80 fflush(fp_log_std);
81
82 return retval;
83 }
84
85 int
86 log_error (const char * format, ...)
87 {
88 va_list args;
89 int retval;
90 char buf[1024];
91
92 log_head(buf);
93 strcat(buf, format);
94
95 va_start (args, format);
96 retval = vfprintf (fp_log_err, format, args);
97 va_end (args);
98
99 fflush(fp_log_err);
100
101 return retval;
102 }
103
104 int
105 log_std_redirect(int fd)
106 {
107 int ret;
108 close (fileno(fp_log_std));
109 ret = dup2(fd, fileno(fp_log_std));
110 return ret;
111 }
112
113 int
114 log_err_redirect(int fd)
115 {
116 int ret;
117 close (fileno(fp_log_err));
118 ret = dup2(fd, fileno(fp_log_err));
119 return ret;
120 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1