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

Contents of /lbbs/src/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Thu Oct 21 17:28:46 2004 UTC (21 years, 5 months ago) by sysadm
Branch: MAIN
Changes since 1.4: +18 -0 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 "common.h"
19
20 FILE *fp_log_std;
21 FILE *fp_log_err;
22
23 int
24 log_begin (char *file_log_std, char *file_log_err)
25 {
26 fp_log_std = fopen (file_log_std, "a");
27 if (fp_log_std == NULL)
28 {
29 perror ("log_begin failed\n");
30 return -1;
31 }
32
33 fp_log_err = fopen (file_log_err, "a");
34 if (fp_log_err == NULL)
35 {
36 perror ("log_begin failed\n");
37 return -2;
38 }
39
40 return 0;
41 }
42
43 int
44 log_end ()
45 {
46 fclose (fp_log_std);
47 fclose (fp_log_err);
48 }
49
50 int
51 log_head (char *buf)
52 {
53 time_t t;
54 char s_time[256];
55 t = time(0);
56
57 strftime(s_time,256,"%Y-%m-%d %H:%M:%S", localtime (&t));
58 sprintf(buf,"[%s] [%d] ", s_time, getpid());
59
60 return 0;
61 }
62
63 int
64 log_std (char *msg)
65 {
66 char buf[1024];
67
68 if (fp_log_std == NULL)
69 {
70 perror ("log_std failed\n");
71 return -1;
72 }
73
74 log_head(buf);
75
76 strcat(buf,msg);
77
78 if (fprintf (fp_log_std, buf)<0)
79 {
80 perror ("log_std failed\n");
81 return -2;
82 }
83
84 fflush(fp_log_std);
85
86 return 0;
87 }
88
89 int
90 log_error (char *error_msg)
91 {
92 char buf[1024];
93
94 if (fp_log_err == NULL)
95 {
96 perror ("log_error failed\n");
97 return -1;
98 }
99
100 log_head(buf);
101
102 strcat(buf,error_msg);
103
104 if (fprintf (fp_log_err, buf)<0)
105 {
106 perror ("log_error failed\n");
107 return -2;
108 }
109
110 fflush(fp_log_err);
111
112 return 0;
113 }
114
115 int
116 log_std_redirect(int fd)
117 {
118 int ret;
119 close (fileno(fp_log_std));
120 ret = dup2(fd, fileno(fp_log_std));
121 return ret;
122 }
123
124 int
125 log_err_redirect(int fd)
126 {
127 int ret;
128 close (fileno(fp_log_err));
129 ret = dup2(fd, fileno(fp_log_err));
130 return ret;
131 }

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