OSDN Git Service

* updated copyright.
[modchxj/mod_chxj.git] / src / qs_log.c
1 /*
2  * Copyright (C) 2005-2011 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
27 void
28 qs_log(Doc *doc, int log_level,const char *f, int l, char *msg) 
29 {
30   switch(log_level) {
31   case QX_LOG_DEBUG:
32 #ifdef USE_LOG
33 #ifdef DEBUG
34     do {
35       FILE* fp = fopen("/tmp/debug.log", "a");
36       fprintf(fp, "DBG:[%20.20s][%10d]: - <%s>\n", f,l,msg);
37       fclose(fp);
38     }
39     while(0);
40 #endif
41 #endif
42     break;
43   case QX_LOG_INFO:
44 #ifdef USE_LOG
45     do {
46       FILE* fp = fopen("/tmp/debug.log", "a");
47       fprintf(fp, "INF:[%20.20s][%10d]: - <%s>\n", f,l,msg);
48       fclose(fp);
49     }
50     while(0);
51 #endif
52     break;
53   case QX_LOG_WARN:
54 #ifdef USE_LOG
55     do {
56       FILE* fp = fopen("/tmp/debug.log", "a");
57       fprintf(fp, "WRN:[%20.20s][%10d]: - <%s>\n", f,l,msg);
58       fclose(fp);
59     }
60     while(0);
61 #endif
62     break;
63   case QX_LOG_ERROR:
64 #ifdef USE_LOG
65     do {
66       FILE* fp = fopen("/tmp/debug.log", "a");
67       fprintf(fp, "ERR:[%20.20s][%10d]: - <%s>\n", f,l,msg);
68       fclose(fp);
69     }
70     while(0);
71 #endif
72     break;
73   case QX_LOG_FATAL:
74 #ifdef USE_LOG
75     do {
76       FILE* fp = fopen("/tmp/debug.log", "a");
77       fprintf(fp, "FTL:[%20.20s][%10d]: - <%s>\n", f,l,msg);
78       fclose(fp);
79     }
80     while(0);
81 #endif
82     if (doc && doc->r) {
83       chxj_log_rerror(f,l, APLOG_CRIT, 0, doc->r, msg);
84     }
85     else {
86       fprintf(stderr, "%s\n", msg);
87     }
88   }
89 }
90
91 void
92 qs_log_int(Doc *UNUSED(doc), int UNUSED(log_level),const char *UNUSED(f), int UNUSED(l), char *UNUSED(msg), int UNUSED(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
103   case QX_LOG_INFO:
104     fprintf(stderr, "INF:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
105     break;
106
107   case QX_LOG_WARN:
108     fprintf(stderr, "WRN:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
109     break;
110
111   case QX_LOG_ERROR:
112     fprintf(stderr, "ERR:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
113     break;
114
115   case QX_LOG_FATAL:
116     fprintf(stderr, "FTL:[%20.20s][%10d]: - <%s:%d>\n", f,l,msg,val);
117     _exit(0);
118     break;
119   }
120 #endif
121 #endif
122 }