zend_accelerator_debug.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <stdarg.h>
  24. #include <time.h>
  25. #ifdef ZEND_WIN32
  26. # include <process.h>
  27. #endif
  28. #include "ZendAccelerator.h"
  29. void zend_accel_error(int type, const char *format, ...)
  30. {
  31. va_list args;
  32. time_t timestamp;
  33. char *time_string;
  34. FILE * fLog = NULL;
  35. TSRMLS_FETCH();
  36. if (type > ZCG(accel_directives).log_verbosity_level) {
  37. return;
  38. }
  39. timestamp = time(NULL);
  40. time_string = asctime(localtime(&timestamp));
  41. time_string[24] = 0;
  42. if (!ZCG(accel_directives).error_log ||
  43. !*ZCG(accel_directives).error_log ||
  44. strcmp(ZCG(accel_directives).error_log, "stderr") == 0) {
  45. fLog = stderr;
  46. } else {
  47. fLog = fopen(ZCG(accel_directives).error_log, "a+");
  48. if (!fLog) {
  49. fLog = stderr;
  50. }
  51. }
  52. #ifdef ZTS
  53. fprintf(fLog, "%s (%lu): ", time_string, (unsigned long)tsrm_thread_id());
  54. #else
  55. fprintf(fLog, "%s (%d): ", time_string, getpid());
  56. #endif
  57. switch (type) {
  58. case ACCEL_LOG_FATAL:
  59. fprintf(fLog, "Fatal Error ");
  60. break;
  61. case ACCEL_LOG_ERROR:
  62. fprintf(fLog, "Error ");
  63. break;
  64. case ACCEL_LOG_WARNING:
  65. fprintf(fLog, "Warning ");
  66. break;
  67. case ACCEL_LOG_INFO:
  68. fprintf(fLog, "Message ");
  69. break;
  70. case ACCEL_LOG_DEBUG:
  71. fprintf(fLog, "Debug ");
  72. break;
  73. }
  74. va_start(args, format);
  75. vfprintf(fLog, format, args);
  76. va_end(args);
  77. fprintf(fLog, "\n");
  78. switch (type) {
  79. case ACCEL_LOG_ERROR:
  80. zend_bailout();
  81. break;
  82. case ACCEL_LOG_FATAL:
  83. exit(-2);
  84. break;
  85. }
  86. fflush(fLog);
  87. if (fLog != stderr) {
  88. fclose(fLog);
  89. }
  90. }