OSDN Git Service

* Merge branch 'branch_0.11.0'
[modchxj/mod_chxj.git] / src / qs_log.c
1 /*
2  * Copyright (C) 2005-2008 Atsushi Konno All rights reserved.
3  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <stdio.h>
18 #include <unistd.h>
19 #include "qs_log.h"
20 #include "qs_malloc.h"
21 #include "chxj_apache.h"
22
23
24
25
26 void
27 qs_log(Doc *doc, int log_level,const char *f, int l, char *msg) 
28 {
29   switch(log_level) {
30   case QX_LOG_DEBUG:
31 #ifdef USE_LOG
32 #ifdef DEBUG
33     do {
34       FILE *fp = fopen("/tmp/debug.log", "a");
35       fprintf(fp, "DBG:[%20.20s][%10d]: - <%s>\n", f,l,msg);
36       fclose(fp);
37     }
38     while(0);
39 #endif
40 #endif
41     break;
42   case QX_LOG_INFO:
43 #ifdef USE_LOG
44     do {
45       FILE* fp = fopen("/tmp/debug.log", "a");
46       fprintf(fp, "INF:[%20.20s][%10d]: - <%s>\n", f,l,msg);
47       fclose(fp);
48     }
49     while(0);
50 #endif
51     break;
52   case QX_LOG_WARN:
53 #ifdef USE_LOG
54     do {
55       FILE *fp = fopen("/tmp/debug.log", "a");
56       fprintf(fp, "WRN:[%20.20s][%10d]: - <%s>\n", f,l,msg);
57       fclose(fp);
58     }
59     while(0);
60 #endif
61     break;
62   case QX_LOG_ERROR:
63 #ifdef USE_LOG
64     do {
65       FILE *fp = fopen("/tmp/debug.log", "a");
66       fprintf(fp, "ERR:[%20.20s][%10d]: - <%s>\n", f,l,msg);
67       fclose(fp);
68     }
69     while(0);
70 #endif
71     break;
72   case QX_LOG_FATAL:
73 #ifdef USE_LOG
74     do {
75       FILE *fp = fopen("/tmp/debug.log", "a");
76       fprintf(fp, "FTL:[%20.20s][%10d]: - <%s>\n", f,l,msg);
77       fclose(fp);
78     }
79     while(0);
80 #endif
81     if (doc->r) {
82       chxj_log_rerror(f,l, APLOG_CRIT, 0, doc->r, msg);
83     }
84     qs_all_free(doc, QX_LOGMARK);
85     _exit(0);
86   }
87 }
88
89 void
90 qs_log_int(Doc *UNUSED(doc), int UNUSED(log_level),const char *UNUSED(f), int UNUSED(l), char *UNUSED(msg), int UNUSED(val)) 
91 {
92 #if 0
93 #ifdef USE_LOG
94   switch(log_level) {
95   case QX_LOG_DEBUG:
96 #ifdef DEBUG
97     fprintf(stderr, "DBG:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg, val);
98 #endif
99     break;
100
101   case QX_LOG_INFO:
102     fprintf(stderr, "INF:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
103     break;
104
105   case QX_LOG_WARN:
106     fprintf(stderr, "WRN:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
107     break;
108
109   case QX_LOG_ERROR:
110     fprintf(stderr, "ERR:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
111     break;
112
113   case QX_LOG_FATAL:
114     fprintf(stderr, "FTL:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
115     _exit(0);
116     break;
117   }
118 #endif
119 #endif
120 }