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

Contents of /lbbs/src/log.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations)
Sat May 7 12:08:28 2005 UTC (20 years, 10 months ago) by sysadm
Branch: MAIN
CVS Tags: lbbs_1-0-0-0_MIL
Changes since 1.9: +2 -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 "io.h"
19 #include <stdio.h>
20 #include <stdarg.h>
21 #include <sys/types.h>
22 #include <time.h>
23 #include <unistd.h>
24
25 FILE *fp_log_std;
26 FILE *fp_log_err;
27
28 int
29 log_begin (char *file_log_std, char *file_log_err)
30 {
31 fp_log_std = fopen (file_log_std, "a");
32 if (fp_log_std == NULL)
33 {
34 perror ("log_begin failed\n");
35 return -1;
36 }
37
38 fp_log_err = fopen (file_log_err, "a");
39 if (fp_log_err == NULL)
40 {
41 perror ("log_begin failed\n");
42 return -2;
43 }
44
45 return 0;
46 }
47
48 int
49 log_end ()
50 {
51 fclose (fp_log_std);
52 fclose (fp_log_err);
53 }
54
55 int
56 log_head (char *buf)
57 {
58 time_t t;
59 char s_time[256];
60 t = time (0);
61
62 strftime (s_time, 256, "%Y-%m-%d %H:%M:%S", localtime (&t));
63 sprintf (buf, "[%s] [%d] ", s_time, getpid ());
64
65 return 0;
66 }
67
68 int
69 log_std (const char *format, ...)
70 {
71 va_list args;
72 int retval;
73 char buf[1024];
74
75 log_head (buf);
76 strcat (buf, format);
77
78 va_start (args, format);
79 retval = vfprintf (fp_log_std, buf, args);
80 va_end (args);
81
82 fflush (fp_log_std);
83
84 return retval;
85 }
86
87 int
88 log_error (const char *format, ...)
89 {
90 va_list args;
91 int retval;
92 char buf[1024];
93
94 log_head (buf);
95 strcat (buf, format);
96
97 va_start (args, format);
98 retval = vfprintf (fp_log_err, buf, args);
99 va_end (args);
100
101 fflush (fp_log_err);
102
103 return retval;
104 }
105
106 int
107 log_std_redirect (int fd)
108 {
109 int ret;
110 close (fileno (fp_log_std));
111 ret = dup2 (fd, fileno (fp_log_std));
112 return ret;
113 }
114
115 int
116 log_err_redirect (int fd)
117 {
118 int ret;
119 close (fileno (fp_log_err));
120 ret = dup2 (fd, fileno (fp_log_err));
121 return ret;
122 }

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