1 /*
2 +----------------------------------------------------------------------+
3 | Zend OPcache |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 1998-2016 The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@zend.com> |
16 | Zeev Suraski <zeev@zend.com> |
17 | Stanislav Malyshev <stas@zend.com> |
18 | Dmitry Stogov <dmitry@zend.com> |
19 +----------------------------------------------------------------------+
20 */
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <stdarg.h>
25 #include <time.h>
26 #ifdef ZEND_WIN32
27 # include <process.h>
28 #endif
29 #include "ZendAccelerator.h"
30
31 void zend_accel_error(int type, const char *format, ...)
32 {
33 va_list args;
34 time_t timestamp;
35 char *time_string;
36 FILE * fLog = NULL;
37
38 if (type > ZCG(accel_directives).log_verbosity_level) {
39 return;
40 }
41
42 timestamp = time(NULL);
43 time_string = asctime(localtime(×tamp));
44 time_string[24] = 0;
45
46 if (!ZCG(accel_directives).error_log ||
47 !*ZCG(accel_directives).error_log ||
48 strcmp(ZCG(accel_directives).error_log, "stderr") == 0) {
49
50 fLog = stderr;
51 } else {
52 fLog = fopen(ZCG(accel_directives).error_log, "a+");
53 if (!fLog) {
54 fLog = stderr;
55 }
56 }
57
58 #ifdef ZTS
59 fprintf(fLog, "%s (" ZEND_ULONG_FMT "): ", time_string, (zend_ulong)tsrm_thread_id());
60 #else
61 fprintf(fLog, "%s (%d): ", time_string, getpid());
62 #endif
63
64 switch (type) {
65 case ACCEL_LOG_FATAL:
66 fprintf(fLog, "Fatal Error ");
67 break;
68 case ACCEL_LOG_ERROR:
69 fprintf(fLog, "Error ");
70 break;
71 case ACCEL_LOG_WARNING:
72 fprintf(fLog, "Warning ");
73 break;
74 case ACCEL_LOG_INFO:
75 fprintf(fLog, "Message ");
76 break;
77 case ACCEL_LOG_DEBUG:
78 fprintf(fLog, "Debug ");
79 break;
80 }
81
82 va_start(args, format);
83 vfprintf(fLog, format, args);
84 va_end(args);
85 fprintf(fLog, "\n");
86 switch (type) {
87 case ACCEL_LOG_ERROR:
88 zend_bailout();
89 break;
90 case ACCEL_LOG_FATAL:
91 exit(-2);
92 break;
93 }
94 fflush(fLog);
95 if (fLog != stderr) {
96 fclose(fLog);
97 }
98 }