OSDN Git Service

* Writing is changed.
[modchxj/mod_chxj.git] / src / qs_log.c
1 /*
2  * Copyright (C) 2005 QSDN,Inc. All rights reserved.
3  * Copyright (C) 2005 Atsushi Konno 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 "http_log.h"
22
23
24 extern apr_status_t chxj_init_module_kill(void *data);
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 != NULL)
82     {
83       ap_log_rerror(f,l, APLOG_CRIT, 0, doc->r, msg);
84       chxj_init_module_kill((void*)doc->r->server);
85     }
86     qs_all_free(doc, QX_LOGMARK);
87     _exit(0);
88   }
89 }
90
91 void
92 qs_log_int(Doc* doc, int log_level,const char* f, int l, char*msg, int val) 
93 {
94 #if 0
95 #ifdef USE_LOG
96   switch(log_level) {
97   case QX_LOG_DEBUG:
98 #ifdef DEBUG
99     fprintf(stderr, "DBG:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg, val);
100 #endif
101     break;
102   case QX_LOG_INFO:
103     fprintf(stderr, "INF:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
104     break;
105   case QX_LOG_WARN:
106     fprintf(stderr, "WRN:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
107     break;
108   case QX_LOG_ERROR:
109     fprintf(stderr, "ERR:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
110     break;
111   case QX_LOG_FATAL:
112     fprintf(stderr, "FTL:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
113     _exit(0);
114     break;
115   }
116 #endif
117 #endif
118 }