当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
seaslog.c 29.73 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
/*
+----------------------------------------------------------------------+
| SeasLog |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Author: Chitao Gao <neeke@php.net> |
+----------------------------------------------------------------------+
*/
#include "php_seaslog.h"
ZEND_DECLARE_MODULE_GLOBALS(seaslog);
static PHP_GINIT_FUNCTION(seaslog);
static PHP_GSHUTDOWN_FUNCTION(seaslog);
#ifdef COMPILE_DL_SEASLOG
ZEND_GET_MODULE(seaslog)
#endif
#include "src/Common.c"
#include "src/Performance.c"
#include "src/Analyzer.c"
#include "src/StreamWrapper.c"
#include "src/TemplateFormatter.c"
#include "src/Appender.c"
#include "src/Buffer.c"
#include "src/Datetime.c"
#include "src/ErrorHook.c"
#include "src/ExceptionHook.c"
#include "src/Logger.c"
#include "src/Request.c"
const zend_function_entry seaslog_functions[] =
{
PHP_FE(seaslog_get_version, NULL)
PHP_FE(seaslog_get_author, NULL)
{
NULL, NULL, NULL
}
};
#if ZEND_MODULE_API_NO >= 20050922
zend_module_dep seaslog_deps[] =
{
{
NULL, NULL, NULL
}
};
#endif
ZEND_BEGIN_ARG_INFO_EX(seaslog_setBasePath_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, base_path)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(seaslog_setRequestID_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, request_id)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(seaslog_setLogger_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, logger)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(seaslog_setDatetimeFormat_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, format)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(seaslog_analyzerCount_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, level)
ZEND_ARG_INFO(0, log_path)
ZEND_ARG_INFO(0, key_word)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(seaslog_analyzerDetail_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, level)
ZEND_ARG_INFO(0, log_path)
ZEND_ARG_INFO(0, key_word)
ZEND_ARG_INFO(0, start)
ZEND_ARG_INFO(0, limit)
ZEND_ARG_INFO(0, order)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(seaslog_log_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, level)
ZEND_ARG_INFO(0, message)
ZEND_ARG_INFO(0, content)
ZEND_ARG_INFO(0, logger)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(seaslog_log_common_arginfo, 0, 0, 1)
ZEND_ARG_INFO(0, message)
ZEND_ARG_INFO(0, content)
ZEND_ARG_INFO(0, logger)
ZEND_END_ARG_INFO()
const zend_function_entry seaslog_methods[] =
{
PHP_ME(SEASLOG_RES_NAME, __construct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_CTOR)
PHP_ME(SEASLOG_RES_NAME, __destruct, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_DTOR)
PHP_ME(SEASLOG_RES_NAME, setBasePath, seaslog_setBasePath_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, getBasePath, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, setLogger, seaslog_setLogger_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, getLastLogger, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, setRequestID, seaslog_setRequestID_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, getRequestID, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, setDatetimeFormat, seaslog_setDatetimeFormat_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, getDatetimeFormat, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, analyzerCount, seaslog_analyzerCount_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, analyzerDetail,seaslog_analyzerDetail_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, getBuffer, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, flushBuffer, NULL, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, log, seaslog_log_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, debug, seaslog_log_common_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, info, seaslog_log_common_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, notice, seaslog_log_common_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, warning, seaslog_log_common_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, error, seaslog_log_common_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, critical, seaslog_log_common_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, alert, seaslog_log_common_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
PHP_ME(SEASLOG_RES_NAME, emergency, seaslog_log_common_arginfo, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC)
{
NULL, NULL, NULL
}
};
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("seaslog.default_basepath", "/var/log/www", PHP_INI_SYSTEM, OnUpdateString, default_basepath, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.default_logger", "default", PHP_INI_SYSTEM, OnUpdateString, default_logger, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.default_datetime_format", "Y-m-d H:i:s", PHP_INI_SYSTEM, OnUpdateString, default_datetime_format, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.default_template", "%T | %L | %P | %Q | %t | %M", PHP_INI_SYSTEM, OnUpdateString, default_template, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.disting_folder", "1", PHP_INI_SYSTEM, OnUpdateBool, disting_folder, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.disting_type", "0", PHP_INI_SYSTEM, OnUpdateBool, disting_type, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.disting_by_hour", "0", PHP_INI_SYSTEM, OnUpdateBool, disting_by_hour, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.use_buffer", "0", PHP_INI_SYSTEM, OnUpdateBool, use_buffer, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.trace_notice", "0", PHP_INI_ALL, OnUpdateBool, trace_notice, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.trace_warning", "0", PHP_INI_ALL, OnUpdateBool, trace_warning, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.trace_error", "1", PHP_INI_ALL, OnUpdateBool, trace_error, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.trace_exception", "0", PHP_INI_SYSTEM, OnUpdateBool, trace_exception, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.buffer_size", "0", PHP_INI_ALL, OnUpdateLongGEZero, buffer_size, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.level", "8", PHP_INI_ALL, OnUpdateLongGEZero, level, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.recall_depth", "0", PHP_INI_ALL, OnUpdateLongGEZero, recall_depth, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.appender", "1", PHP_INI_SYSTEM, OnUpdateLongGEZero, appender, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.appender_retry", "0", PHP_INI_ALL, OnUpdateLongGEZero, appender_retry, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.remote_host", "127.0.0.1", PHP_INI_ALL, OnUpdateString, remote_host, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_ENTRY("seaslog.remote_port", "514", PHP_INI_ALL, OnUpdateLongGEZero, remote_port, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.trim_wrap", "0", PHP_INI_ALL, OnUpdateBool, trim_wrap, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.throw_exception", "1", PHP_INI_ALL, OnUpdateBool, throw_exception, zend_seaslog_globals, seaslog_globals)
STD_PHP_INI_BOOLEAN("seaslog.ignore_warning", "1", PHP_INI_ALL, OnUpdateBool, ignore_warning, zend_seaslog_globals, seaslog_globals)
PHP_INI_END()
static PHP_GINIT_FUNCTION(seaslog)
{
memset(seaslog_globals, 0, sizeof(zend_seaslog_globals));
}
static PHP_GSHUTDOWN_FUNCTION(seaslog)
{
}
PHP_MINIT_FUNCTION(seaslog)
{
zend_class_entry seaslog;
REGISTER_INI_ENTRIES();
REGISTER_STRINGL_CONSTANT("SEASLOG_VERSION", SEASLOG_VERSION, sizeof(SEASLOG_VERSION) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_AUTHOR", SEASLOG_AUTHOR, sizeof(SEASLOG_AUTHOR) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_ALL", SEASLOG_ALL, sizeof(SEASLOG_ALL) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_DEBUG", SEASLOG_DEBUG, sizeof(SEASLOG_DEBUG) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_INFO", SEASLOG_INFO, sizeof(SEASLOG_INFO) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_NOTICE", SEASLOG_NOTICE, sizeof(SEASLOG_NOTICE) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_WARNING", SEASLOG_WARNING, sizeof(SEASLOG_WARNING) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_ERROR", SEASLOG_ERROR, sizeof(SEASLOG_ERROR) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_CRITICAL", SEASLOG_CRITICAL, sizeof(SEASLOG_CRITICAL) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_ALERT", SEASLOG_ALERT, sizeof(SEASLOG_ALERT) - 1, CONST_PERSISTENT | CONST_CS);
REGISTER_STRINGL_CONSTANT("SEASLOG_EMERGENCY", SEASLOG_EMERGENCY, sizeof(SEASLOG_EMERGENCY) - 1,CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("SEASLOG_DETAIL_ORDER_ASC", SEASLOG_DETAIL_ORDER_ASC, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("SEASLOG_DETAIL_ORDER_DESC", SEASLOG_DETAIL_ORDER_DESC, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("SEASLOG_APPENDER_FILE", SEASLOG_APPENDER_FILE, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("SEASLOG_APPENDER_TCP", SEASLOG_APPENDER_TCP, CONST_PERSISTENT | CONST_CS);
REGISTER_LONG_CONSTANT("SEASLOG_APPENDER_UDP", SEASLOG_APPENDER_UDP, CONST_PERSISTENT | CONST_CS);
INIT_CLASS_ENTRY(seaslog, SEASLOG_RES_NAME, seaslog_methods);
#if PHP_VERSION_ID >= 70000
seaslog_ce = zend_register_internal_class_ex(&seaslog, NULL);
#else
seaslog_ce = zend_register_internal_class_ex(&seaslog, NULL, NULL TSRMLS_CC);
#endif
seaslog_ce->ce_flags = ZEND_ACC_IMPLICIT_PUBLIC;
initErrorHooks(TSRMLS_C);
initExceptionHooks(TSRMLS_C);
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(seaslog)
{
recoveryErrorHooks(TSRMLS_C);
recoveryExceptionHooks(TSRMLS_C);
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_RINIT_FUNCTION(seaslog)
{
initRStart(TSRMLS_C);
seaslog_init_slash_or_underline(TSRMLS_C);
seaslog_init_pid(TSRMLS_C);
seaslog_init_host_name(TSRMLS_C);
seaslog_init_request_id(TSRMLS_C);
seaslog_init_auto_globals(TSRMLS_C);
seaslog_init_request_variable(TSRMLS_C);
seaslog_init_last_time(TSRMLS_C);
seaslog_init_template(TSRMLS_C);
seaslog_init_logger_list(TSRMLS_C);
seaslog_init_logger(TSRMLS_C);
seaslog_init_buffer(TSRMLS_C);
seaslog_init_stream_list(TSRMLS_C);
initREnd(TSRMLS_C);
return SUCCESS;
}
PHP_RSHUTDOWN_FUNCTION(seaslog)
{
seaslog_shutdown_buffer(SEASLOG_BUFFER_RE_INIT_NO TSRMLS_CC);
seaslog_clear_buffer(TSRMLS_C);
seaslog_clear_logger(TSRMLS_C);
seaslog_clear_logger_list(TSRMLS_C);
seaslog_clear_last_time(TSRMLS_C);
seaslog_clear_request_id(TSRMLS_C);
seaslog_clear_pid(TSRMLS_C);
seaslog_clear_host_name(TSRMLS_C);
seaslog_clear_template(TSRMLS_C);
seaslog_clear_request_variable(TSRMLS_C);
seaslog_clear_stream_list(TSRMLS_C);
return SUCCESS;
}
PHP_MINFO_FUNCTION(seaslog)
{
php_info_print_table_start();
php_info_print_table_header(2, "SeasLog support", "Enabled");
php_info_print_table_row(2, "SeasLog Version", SEASLOG_VERSION);
php_info_print_table_row(2, "SeasLog Author", SEASLOG_AUTHOR);
php_info_print_table_row(2, "SeasLog Supports", SEASLOG_SUPPORTS);
php_info_print_table_end();
DISPLAY_INI_ENTRIES();
}
zend_module_entry seaslog_module_entry =
{
#if ZEND_MODULE_API_NO >= 20050922
STANDARD_MODULE_HEADER_EX, NULL,
seaslog_deps,
#else
STANDARD_MODULE_HEADER,
#endif
SEASLOG_RES_NAME,
seaslog_functions,
PHP_MINIT(seaslog),
PHP_MSHUTDOWN(seaslog),
PHP_RINIT(seaslog),
PHP_RSHUTDOWN(seaslog),
PHP_MINFO(seaslog),
SEASLOG_VERSION,
PHP_MODULE_GLOBALS(seaslog),
PHP_GINIT(seaslog),
PHP_GSHUTDOWN(seaslog),
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
static void seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAMETERS, char *level, int level_int)
{
int argc = ZEND_NUM_ARGS();
#if PHP_VERSION_ID >= 70000
zend_string *message;
zval *content = NULL;
zend_string *logger = NULL;
char *logger_str = "";
int logger_len = 0;
if (zend_parse_parameters(argc TSRMLS_CC, "S|zS", &message, &content, &logger) == FAILURE)
{
return;
}
if (argc > 1 && IS_ARRAY != Z_TYPE_P(content))
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The second argument is not an array");
RETURN_FALSE;
}
if (logger != NULL)
{
logger_str = ZSTR_VAL(logger);
logger_len = ZSTR_LEN(logger);
}
if (argc > 1)
{
if (seaslog_log_content(argc, level, level_int, ZSTR_VAL(message), ZSTR_LEN(message), HASH_OF(content), logger_str, logger_len, seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
else
{
if (seaslog_log_ex(argc, level, level_int, ZSTR_VAL(message), ZSTR_LEN(message), "", 0, seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
#else
char *message;
zval *content = NULL;
char *logger = NULL;
int message_len = 0, logger_len = 0;
if (zend_parse_parameters(argc TSRMLS_CC, "s|zs", &message, &message_len, &content, &logger, &logger_len) == FAILURE)
{
return;
}
if (argc > 1 && IS_ARRAY != Z_TYPE_P(content))
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The second argument is not an array");
RETURN_FALSE;
}
if (argc > 1)
{
if (seaslog_log_content(argc, level, level_int, message, message_len, HASH_OF(content), logger, logger_len, seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
else
{
if (seaslog_log_ex(argc, level, level_int, message, message_len, "", 0, seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
#endif
RETURN_TRUE;
}
/* {{{ proto string seaslog_get_version()
Return SeasLog version */
PHP_FUNCTION(seaslog_get_version)
{
char *str;
int len = 0;
len = spprintf(&str, 0, "%s", SEASLOG_VERSION);
SEASLOG_RETURN_STRINGL(str, len);
}
/* }}} */
/* {{{ proto string seaslog_get_author()
Return SeasLog author */
PHP_FUNCTION(seaslog_get_author)
{
char *str;
int len = 0;
len = spprintf(&str, 0, "%s", SEASLOG_AUTHOR);
SEASLOG_RETURN_STRINGL(str, len);
}
/* }}} */
PHP_METHOD(SEASLOG_RES_NAME, __construct)
{
seaslog_init_logger(TSRMLS_C);
seaslog_init_buffer(TSRMLS_C);
}
PHP_METHOD(SEASLOG_RES_NAME, __destruct)
{
seaslog_shutdown_buffer(SEASLOG_BUFFER_RE_INIT_NO TSRMLS_CC);
}
/* {{{ proto bool setBasePath(string base_path)
Set SeasLog base path */
PHP_METHOD(SEASLOG_RES_NAME, setBasePath)
{
zval *_base_path;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "z", &_base_path) == FAILURE)
{
return;
}
if (argc > 0 && (IS_STRING == Z_TYPE_P(_base_path) && Z_STRLEN_P(_base_path) > 0))
{
if (SEASLOG_G(base_path))
{
efree(SEASLOG_G(base_path));
SEASLOG_G(base_path) = estrdup(Z_STRVAL_P(_base_path));
seaslog_init_default_last_logger(TSRMLS_C);
}
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto string getBasePath()
Get SeasLog base path */
PHP_METHOD(SEASLOG_RES_NAME, getBasePath)
{
SEASLOG_RETURN_STRINGL(SEASLOG_G(base_path), strlen(SEASLOG_G(base_path)));
}
/* }}} */
/* {{{ proto bool setBasePath(string logger)
Set SeasLog logger path */
PHP_METHOD(SEASLOG_RES_NAME, setLogger)
{
zval *_module;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "z", &_module) == FAILURE)
{
return;
}
if (argc > 0 && (IS_STRING == Z_TYPE_P(_module) && Z_STRLEN_P(_module) > 0))
{
if (strncmp(SEASLOG_G(last_logger)->logger,Z_STRVAL_P(_module),Z_STRLEN_P(_module)))
{
process_logger(Z_STRVAL_P(_module), Z_STRLEN_P(_module), SEASLOG_PROCESS_LOGGER_LAST TSRMLS_CC);
}
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto string getLastLogger()
Get SeasLog last logger path */
PHP_METHOD(SEASLOG_RES_NAME, getLastLogger)
{
SEASLOG_RETURN_STRINGL(SEASLOG_G(last_logger)->logger, SEASLOG_G(last_logger)->logger_len);
}
/* }}} */
/* {{{ proto bool setDatetimeFormat(string format)
Set SeasLog datetime format style */
PHP_METHOD(SEASLOG_RES_NAME, setDatetimeFormat)
{
zval *_format;
int now;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "z", &_format) == FAILURE)
{
return;
}
if (argc > 0 && (IS_STRING == Z_TYPE_P(_format) || Z_STRLEN_P(_format) > 0))
{
if (!strcmp(SEASLOG_G(current_datetime_format), SEASLOG_G(default_datetime_format)))
{
efree(SEASLOG_G(current_datetime_format));
}
SEASLOG_G(current_datetime_format) = estrdup(Z_STRVAL_P(_format));
now = (long)time(NULL);
seaslog_process_last_sec(now, SEASLOG_INIT_FIRST_NO TSRMLS_CC);
#if PHP_VERSION_ID >= 70000
zval_ptr_dtor(_format);
#else
zval_ptr_dtor(&_format);
#endif
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto string getDatetimeFormat()
Get SeasLog datetime format style */
PHP_METHOD(SEASLOG_RES_NAME, getDatetimeFormat)
{
char *str;
int len = 0;
len = spprintf(&str, 0, "%s", SEASLOG_G(current_datetime_format));
SEASLOG_RETURN_STRINGL(str, len);
}
/* }}} */
/* {{{ proto bool setRequestID(string request_id)
Set SeasLog request_id differentiated requests */
PHP_METHOD(SEASLOG_RES_NAME, setRequestID)
{
zval *_request_id;
int argc = ZEND_NUM_ARGS();
if (zend_parse_parameters(argc TSRMLS_CC, "z", &_request_id) == FAILURE)
{
return;
}
if (argc > 0 && (IS_STRING == Z_TYPE_P(_request_id) || IS_LONG == Z_TYPE_P(_request_id) || IS_DOUBLE == Z_TYPE_P(_request_id)))
{
if (SEASLOG_G(request_id))
{
efree(SEASLOG_G(request_id));
switch (Z_TYPE_P(_request_id))
{
case IS_STRING:
SEASLOG_G(request_id_len) = spprintf(&SEASLOG_G(request_id), 0, "%s", Z_STRVAL_P(_request_id));
break;
case IS_LONG:
SEASLOG_G(request_id_len) = spprintf(&SEASLOG_G(request_id), 0, "%ld", Z_LVAL_P(_request_id));
break;
case IS_DOUBLE:
SEASLOG_G(request_id_len) = spprintf(&SEASLOG_G(request_id), 0, "%.*G", (int) EG(precision), Z_DVAL_P(_request_id));
break;
default:
RETURN_FALSE;
}
}
RETURN_TRUE;
}
RETURN_FALSE;
}
/* }}} */
/* {{{ proto string getRequestID()
Get SeasLog request_id differentiated requests */
PHP_METHOD(SEASLOG_RES_NAME, getRequestID)
{
SEASLOG_RETURN_STRINGL(SEASLOG_G(request_id), strlen(SEASLOG_G(request_id)));
}
/* }}} */
/* {{{ proto array or int analyzerCount(string level [,string log_path, string key_word])
Get log count by level, log_path and key_word */
PHP_METHOD(SEASLOG_RES_NAME, analyzerCount)
{
int argc = ZEND_NUM_ARGS();
char *log_path = NULL, *level = NULL, *key_word = NULL;
int len = 0;
int log_path_len = 0, level_len = 0, key_word_len = 0;
long count = 0;
#if PHP_VERSION_ID >= 70000
zend_string *_log_path = NULL;
zend_string *_level = NULL;
zend_string *_key_word = NULL;
if (zend_parse_parameters(argc TSRMLS_CC, "|SSS", &_level, &_log_path, &_key_word) == FAILURE)
{
return;
}
if (argc < 2)
{
log_path = SEASLOG_ASTERISK;
}
if (_log_path)
{
log_path = ZSTR_VAL(_log_path);
}
if (_level == NULL || ZSTR_LEN(_level) < 1 || (_level && !strcmp(ZSTR_VAL(_level), SEASLOG_ALL)))
{
level = SEASLOG_ALL;
}
else
{
level = ZSTR_VAL(_level);
}
if (_key_word)
{
key_word = ZSTR_VAL(_key_word);
}
#else
if (zend_parse_parameters(argc TSRMLS_CC, "|sss", &level, &level_len, &log_path, &log_path_len, &key_word, &key_word_len) == FAILURE)
{
return;
}
if (argc < 2)
{
log_path = SEASLOG_ASTERISK;
}
#endif
if (argc == 0 || (argc == 1 && level != NULL && !strcmp(level, SEASLOG_ALL)))
{
long count_debug, count_info, count_notice, count_warn, count_error, count_critical, count_alert, count_emergency;
array_init(return_value);
count_debug = get_type_count(log_path, SEASLOG_DEBUG, key_word TSRMLS_CC);
count_info = get_type_count(log_path, SEASLOG_INFO, key_word TSRMLS_CC);
count_notice = get_type_count(log_path, SEASLOG_NOTICE, key_word TSRMLS_CC);
count_warn = get_type_count(log_path, SEASLOG_WARNING, key_word TSRMLS_CC);
count_error = get_type_count(log_path, SEASLOG_ERROR, key_word TSRMLS_CC);
count_critical = get_type_count(log_path, SEASLOG_CRITICAL, key_word TSRMLS_CC);
count_alert = get_type_count(log_path, SEASLOG_ALERT, key_word TSRMLS_CC);
count_emergency = get_type_count(log_path, SEASLOG_EMERGENCY, key_word TSRMLS_CC);
add_assoc_long(return_value, SEASLOG_DEBUG, count_debug);
add_assoc_long(return_value, SEASLOG_INFO, count_info);
add_assoc_long(return_value, SEASLOG_NOTICE, count_notice);
add_assoc_long(return_value, SEASLOG_WARNING, count_warn);
add_assoc_long(return_value, SEASLOG_ERROR, count_error);
add_assoc_long(return_value, SEASLOG_CRITICAL, count_critical);
add_assoc_long(return_value, SEASLOG_ALERT, count_alert);
add_assoc_long(return_value, SEASLOG_EMERGENCY, count_emergency);
}
else
{
count = get_type_count(log_path, level, key_word TSRMLS_CC);
RETURN_LONG(count);
}
}
/* }}} */
/* {{{ proto array analyzerDetail(string level [,string log_path, string key_word, int start, int limit, int order])
Get log detail by level, log_path, key_word, start, limit, order */
PHP_METHOD(SEASLOG_RES_NAME, analyzerDetail)
{
char *level = NULL, *log_path = NULL, *key_word = NULL;
int log_path_len = 0, level_len = 0, key_word_len = 0;
long start = 1;
long limit = 20;
long order = SEASLOG_DETAIL_ORDER_ASC;
int argc = ZEND_NUM_ARGS();
#if PHP_VERSION_ID >= 70000
zend_string *_log_path = NULL;
zend_string *_level = NULL;
zend_string *_key_word = NULL;
if (zend_parse_parameters(argc TSRMLS_CC, "S|SSlll", &_level, &_log_path, &_key_word, &start, &limit, &order) == FAILURE)
{
return;
}
if (argc < 2)
{
log_path = SEASLOG_ASTERISK;
}
else if (argc > 3)
{
#ifdef WINDOWS
seaslog_throw_exception(SEASLOG_EXCEPTION_WINDOWS_ERROR TSRMLS_CC, "%s", "Param start and limit don't support Windows");
RETURN_FALSE;
#endif
}
if (_log_path)
{
log_path = ZSTR_VAL(_log_path);
}
if (ZSTR_LEN(_level) < 1 || (_level && !strcmp(ZSTR_VAL(_level), SEASLOG_ALL)))
{
level = SEASLOG_ALL;
}
else
{
level = ZSTR_VAL(_level);
}
if (_key_word)
{
key_word = ZSTR_VAL(_key_word);
}
#else
if (zend_parse_parameters(argc TSRMLS_CC, "s|sslll", &level, &level_len, &log_path, &log_path_len, &key_word, &key_word_len, &start, &limit, &order) == FAILURE)
{
return;
}
if (argc < 2)
{
log_path = SEASLOG_ASTERISK;
}
else if (argc > 3)
{
#ifdef WINDOWS
seaslog_throw_exception(SEASLOG_EXCEPTION_WINDOWS_ERROR TSRMLS_CC, "%s", "Param start and limit don't support Windows");
RETURN_FALSE;
#endif
}
else
{
// do nothing
}
if (level_len < 1 || (level && !strcmp(level, SEASLOG_ALL)))
{
level = SEASLOG_ALL;
}
#endif
get_detail(log_path, level, key_word, start, start + limit - 1, order, return_value TSRMLS_CC);
}
/* }}} */
/* {{{ proto array getBuffer()
Get the logs buffer in memory as array */
PHP_METHOD(SEASLOG_RES_NAME, getBuffer)
{
if (SEASLOG_G(use_buffer))
{
#if PHP_VERSION_ID >= 70000
RETURN_ZVAL(&SEASLOG_G(buffer), 1, 0);
#else
RETURN_ZVAL(SEASLOG_G(buffer), 1, 0);
#endif
}
}
/* }}} */
/* {{{ proto bool flushBuffer()
Flush logs buffer, dump to appender file, or send to remote api with tcp/udp */
PHP_METHOD(SEASLOG_RES_NAME, flushBuffer)
{
seaslog_shutdown_buffer(SEASLOG_BUFFER_RE_INIT_YES TSRMLS_CC);
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool log(string level, string message [, array content, string logger])
The Common Record Log Function */
PHP_METHOD(SEASLOG_RES_NAME, log)
{
int argc = ZEND_NUM_ARGS();
int level_int;
#if PHP_VERSION_ID >= 70000
zend_string *level;
zend_string *message;
zend_string *logger = NULL;
zval *content = NULL;
if (zend_parse_parameters(argc TSRMLS_CC, "SS|zS", &level, &message, &content, &logger) == FAILURE)
{
return;
}
if (argc > 2 && IS_ARRAY != Z_TYPE_P(content))
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The three argument is not an array");
RETURN_FALSE;
}
level_int = seaslog_get_level_int(ZSTR_VAL(level));
if (argc > 3)
{
if (seaslog_log_content(argc, ZSTR_VAL(level), level_int, ZSTR_VAL(message), ZSTR_LEN(message), HASH_OF(content), ZSTR_VAL(logger), ZSTR_LEN(logger), seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
else if (argc > 2)
{
if (seaslog_log_content(argc, ZSTR_VAL(level), level_int, ZSTR_VAL(message), ZSTR_LEN(message), HASH_OF(content), "", 0, seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
else
{
if (seaslog_log_ex(argc, ZSTR_VAL(level), level_int, ZSTR_VAL(message), ZSTR_LEN(message), "", 0, seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
#else
char *level;
char *message;
zval *content = NULL;
char *logger = NULL;
int message_len = 0, level_len = 0, logger_len = 0;
if (zend_parse_parameters(argc TSRMLS_CC, "ss|zs", &level, &level_len, &message, &message_len, &content, &logger, &logger_len) == FAILURE)
{
return;
}
if (argc > 2 && IS_ARRAY != Z_TYPE_P(content))
{
php_error_docref(NULL TSRMLS_CC, E_WARNING, "The three argument is not an array");
RETURN_FALSE;
}
level_int = seaslog_get_level_int(level);
if (argc > 2)
{
if (seaslog_log_content(argc, level, level_int, message, message_len, HASH_OF(content), logger, logger_len, seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
else
{
if (seaslog_log_ex(argc, level, level_int, message, message_len, logger, logger_len, seaslog_ce TSRMLS_CC) == FAILURE)
{
RETURN_FALSE;
}
}
#endif
RETURN_TRUE;
}
/* }}} */
/* {{{ proto bool debug(string message [, array content, string logger])
Record debug log information */
PHP_METHOD(SEASLOG_RES_NAME, debug)
{
seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, SEASLOG_DEBUG, SEASLOG_DEBUG_INT);
}
/* }}} */
/* {{{ proto bool info(string message [, array content, string logger])
Record info log information */
PHP_METHOD(SEASLOG_RES_NAME, info)
{
seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, SEASLOG_INFO, SEASLOG_INFO_INT);
}
/* }}} */
/* {{{ proto bool notice(string message [, array content, string logger])
Record notice log information */
PHP_METHOD(SEASLOG_RES_NAME, notice)
{
seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, SEASLOG_NOTICE, SEASLOG_NOTICE_INT);
}
/* }}} */
/* {{{ proto bool warning(string message [, array content, string logger])
Record warning log information */
PHP_METHOD(SEASLOG_RES_NAME, warning)
{
seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, SEASLOG_WARNING, SEASLOG_WARNING_INT);
}
/* }}} */
/* {{{ proto bool error(string message [, array content, string logger])
Record error log information */
PHP_METHOD(SEASLOG_RES_NAME, error)
{
seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, SEASLOG_ERROR, SEASLOG_ERROR_INT);
}
/* }}} */
/* {{{ proto bool critical(string message [, array content, string logger])
Record critical log information */
PHP_METHOD(SEASLOG_RES_NAME, critical)
{
seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, SEASLOG_CRITICAL, SEASLOG_CRITICAL_INT);
}
/* }}} */
/* {{{ proto bool alert(string message [, array content, string logger])
Record alert log information */
PHP_METHOD(SEASLOG_RES_NAME, alert)
{
seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, SEASLOG_ALERT, SEASLOG_ALERT_INT);
}
/* }}} */
/* {{{ proto bool emergency(string message [, array content, string logger])
Record emergency log information */
PHP_METHOD(SEASLOG_RES_NAME, emergency)
{
seaslog_log_by_level_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, SEASLOG_EMERGENCY, SEASLOG_EMERGENCY_INT);
}
/* }}} */
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化