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

Contents of /lbbs/src/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Tue Oct 19 02:08:35 2004 UTC (21 years, 5 months ago) by sysadm
Branch: MAIN
Changes since 1.1: +29 -2 lines
Content type: text/x-csrc
Improve log function

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 -1;
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 strcat(buf,msg);
76
77 if (fprintf (fp_log_std, buf)<0)
78 {
79 perror ("log_std failed\n");
80 return -2;
81 }
82
83 fflush(fp_log_std);
84
85 return 0;
86 }
87
88 int
89 log_error (char *error_msg)
90 {
91 char buf[1024];
92
93 if (fp_log_err == NULL)
94 {
95 perror ("log_error failed\n");
96 return -1;
97 }
98
99 log_head(buf);
100 strcat(buf,error_msg);
101
102 if (fprintf (fp_log_err, buf)<0)
103 {
104 perror ("log_error failed\n");
105 return -2;
106 }
107
108 fflush(fp_log_err);
109
110 return 0;
111 }

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