Skip to content

Commit c71ef3c

Browse files
committed
support set log level
1 parent 2f7f508 commit c71ef3c

File tree

4 files changed

+54
-5
lines changed

4 files changed

+54
-5
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,17 @@ $ sudo make && make install
4141
beast.cache_size = size
4242
beast.log_file = "path_to_log"
4343
beast.log_user = "user"
44+
beast.log_level = "debug"
4445
beast.enable = On
4546
</code></pre>
4647

48+
beast.log_level支持参数:
49+
<pre>
50+
1. DEBUG
51+
2. NOTICE
52+
3. ERROR
53+
</pre>
54+
4755
支持的模块有:
4856
<pre>
4957
1. AES

beast.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ extern struct beast_ops *ops_handler_list[];
8383
*/
8484
char *beast_log_file = NULL;
8585
char *beast_log_user = NULL;
86+
int log_level = beast_log_notice;
8687
int beast_ncpu = 1;
8788
int beast_is_root = 0;
8889
int beast_pid = -1;
@@ -848,6 +849,43 @@ ZEND_INI_MH(php_beast_log_user)
848849
#endif
849850
}
850851

852+
ZEND_INI_MH(php_beast_log_level)
853+
{
854+
char *level = NULL;
855+
#if ZEND_MODULE_API_NO >= 20151012
856+
857+
if (ZSTR_LEN(new_value) == 0) {
858+
return SUCCESS;
859+
}
860+
861+
level = ZSTR_VAL(new_value);
862+
863+
#else
864+
865+
if (new_value_length == 0) {
866+
return SUCCESS;
867+
}
868+
869+
level = new_value;
870+
871+
#endif
872+
if (level == NULL) {
873+
return FAILURE;
874+
}
875+
876+
if (strcasecmp(level, "debug") == 0) {
877+
log_level = beast_log_debug;
878+
} else if (strcasecmp(level, "notice") == 0) {
879+
log_level = beast_log_notice;
880+
} else if (strcasecmp(level, "error") == 0) {
881+
log_level = beast_log_error;
882+
} else {
883+
return FAILURE;
884+
}
885+
886+
return SUCCESS;
887+
}
888+
851889

852890
ZEND_INI_MH(php_beast_enable)
853891
{
@@ -1033,6 +1071,8 @@ PHP_INI_BEGIN()
10331071
php_beast_log_file)
10341072
PHP_INI_ENTRY("beast.log_user", "root", PHP_INI_ALL,
10351073
php_beast_log_user)
1074+
PHP_INI_ENTRY("beast.log_level", "notice", PHP_INI_ALL,
1075+
php_beast_log_level)
10361076
PHP_INI_ENTRY("beast.enable", "1", PHP_INI_ALL,
10371077
php_beast_enable)
10381078
PHP_INI_ENTRY("beast.networkcard", "eth0", PHP_INI_ALL,
@@ -1277,7 +1317,7 @@ PHP_MINIT_FUNCTION(beast)
12771317
return FAILURE;
12781318
}
12791319

1280-
if (beast_log_init(beast_log_file) == -1) {
1320+
if (beast_log_init(beast_log_file, log_level) == -1) {
12811321
php_error_docref(NULL TSRMLS_CC,
12821322
E_ERROR, "Unable open log file for beast");
12831323
return FAILURE;

beast_log.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include "beast_log.h"
1212

1313
static FILE *beast_log_fp = NULL;
14+
static int log_level = beast_log_notice;
1415

15-
16-
int beast_log_init(char *log_file)
16+
int beast_log_init(char *log_file, int level)
1717
{
1818
if (!log_file || strlen(log_file) == 0) {
1919
return 0;
@@ -22,6 +22,7 @@ int beast_log_init(char *log_file)
2222
beast_log_fp = fopen(log_file, "a+");
2323
if (!beast_log_fp)
2424
return -1;
25+
log_level = level;
2526
return 0;
2627
}
2728

@@ -55,7 +56,7 @@ void beast_write_log(beast_log_level level, const char *fmt, ...)
5556

5657
if (beast_log_fp == NULL ||
5758
level > beast_log_error ||
58-
level < beast_log_debug)
59+
level < log_level)
5960
{
6061
return;
6162
}

beast_log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ typedef enum {
1313
beast_log_error /* 2 */
1414
} beast_log_level;
1515

16-
int beast_log_init(char *log_file);
16+
int beast_log_init(char *log_file, int level);
1717
int beast_log_chown(uid_t uid, gid_t gid);
1818
void beast_write_log(beast_log_level level, const char *fmt, ...);
1919
void beast_log_destroy();

0 commit comments

Comments
 (0)