2018-05-26 17:30:56 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file logger.php
|
2020-01-23 12:44:27 +00:00
|
|
|
* @created_on 2018-05-27
|
2020-06-21 08:16:27 +00:00
|
|
|
* @updated_on 2020-06-21
|
2022-11-25 14:15:20 +00:00
|
|
|
* @author Go Namhyeon <abuse@catswords.net>
|
2018-05-26 17:35:32 +00:00
|
|
|
* @brief Logger module for ReasonableFramework
|
2018-05-26 17:30:56 +00:00
|
|
|
*/
|
2019-12-05 10:41:58 +00:00
|
|
|
|
2020-02-10 06:23:04 +00:00
|
|
|
if(!is_fn("append_log_to_file")) {
|
2020-01-23 12:43:58 +00:00
|
|
|
function append_log_to_file($data, $filename) {
|
2020-06-21 08:16:27 +00:00
|
|
|
$config = get_config();
|
|
|
|
|
|
|
|
$rotate_size = get_value_in_array("log_rotate_size", $config, 0);
|
2020-06-21 08:16:39 +00:00
|
|
|
$rotate_ratio = get_value_in_array("log_rotate_ratio", $config, 0.9);
|
2020-06-21 08:16:27 +00:00
|
|
|
|
2019-12-05 10:41:58 +00:00
|
|
|
return append_storage_file($data, array(
|
|
|
|
"storage_type" => "logs",
|
|
|
|
"filename" => $filename,
|
|
|
|
"chmod" => 0644,
|
|
|
|
"nl" => "<",
|
2020-06-21 08:16:27 +00:00
|
|
|
"rotate_size" => $rotate_size,
|
|
|
|
"rotate_ratio" => $rotate_ratio,
|
2019-12-05 10:41:58 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-10 06:23:04 +00:00
|
|
|
if(!is_fn("write_visit_log")) {
|
2020-06-14 09:45:15 +00:00
|
|
|
function write_visit_log($mode="") {
|
2019-05-20 08:19:05 +00:00
|
|
|
$fw = false;
|
2020-06-14 09:46:53 +00:00
|
|
|
|
2020-06-14 09:45:15 +00:00
|
|
|
$nevt = false;
|
2019-05-20 08:19:05 +00:00
|
|
|
if(loadHelper("networktool")) {
|
2019-12-05 10:41:58 +00:00
|
|
|
$nevt = get_network_event();
|
2020-06-14 09:45:15 +00:00
|
|
|
}
|
2020-06-14 09:46:53 +00:00
|
|
|
|
|
|
|
if($nevt === false) return $fw;
|
2020-06-14 09:45:15 +00:00
|
|
|
|
|
|
|
if($mode == "database") {
|
|
|
|
$tablename = exec_db_table_create(array(
|
|
|
|
"datetime" => array("datetime"),
|
|
|
|
"server" => array("varchar", 255),
|
|
|
|
"hostname" => array("varchar", 255),
|
|
|
|
"client" => array("varchar", 255),
|
|
|
|
"agent" => array("text"),
|
|
|
|
"referrer" => array("text"),
|
|
|
|
"self" => array("varchar", 255),
|
|
|
|
"method" => array("varchar", 255)
|
|
|
|
), "rsf_visit_log", array(
|
|
|
|
"setindex" => array(
|
|
|
|
"index_1" => array("datetime"),
|
|
|
|
"index_2" => array("client")
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
$bind = array(
|
|
|
|
"datetime" => $nevt['datetime'],
|
|
|
|
"server" => $nevt['server'],
|
|
|
|
"hostname" => $nevt['hostname'],
|
|
|
|
"client" => $nevt['client'],
|
2020-06-14 11:09:32 +00:00
|
|
|
"agent" => $nevt['agent'],
|
2020-06-14 09:45:15 +00:00
|
|
|
"referrer" => $nevt['referrer'],
|
|
|
|
"self" => $nevt['self'],
|
|
|
|
"method" => $nevt['method']
|
|
|
|
);
|
|
|
|
$sql = get_bind_to_sql_insert($tablename, $bind);
|
|
|
|
exec_db_query($sql, $bind);
|
|
|
|
} else {
|
|
|
|
$line = "";
|
2019-05-27 08:16:04 +00:00
|
|
|
if(loadHelper("catsplit.format")) {
|
2020-06-14 09:45:15 +00:00
|
|
|
$line = catsplit_encode($nevt);
|
2019-05-25 17:33:30 +00:00
|
|
|
} else {
|
2020-06-14 09:45:15 +00:00
|
|
|
$line = json_encode($nevt);
|
2019-05-25 17:33:30 +00:00
|
|
|
}
|
2020-06-14 09:45:15 +00:00
|
|
|
$fw = append_log_to_file($line, "network.log");
|
2019-05-20 08:19:05 +00:00
|
|
|
}
|
2020-06-14 09:45:15 +00:00
|
|
|
|
2019-05-20 08:19:05 +00:00
|
|
|
return $fw;
|
|
|
|
}
|
2018-09-29 21:18:44 +00:00
|
|
|
}
|
2019-05-25 17:43:28 +00:00
|
|
|
|
2020-02-10 06:23:04 +00:00
|
|
|
if(!is_fn("write_common_log")) {
|
2020-01-23 12:43:58 +00:00
|
|
|
function write_common_log($message, $component="None", $program="") {
|
2019-05-25 17:51:13 +00:00
|
|
|
$fw = false;
|
2020-04-28 02:40:25 +00:00
|
|
|
|
|
|
|
$mypid = get_shared_var("mypid");
|
|
|
|
$data = implode("\t", array(get_current_datetime(), $mypid, $component, $message));
|
2020-01-23 12:43:58 +00:00
|
|
|
$fw = append_log_to_file($data, "common.log");
|
2019-05-25 17:51:13 +00:00
|
|
|
|
2020-01-23 12:43:58 +00:00
|
|
|
// if enabled RFC3164 remote debugging
|
|
|
|
if(loadHelper("rfc3164.proto")) {
|
|
|
|
rfc3164_send_message($message, $component, $program);
|
2019-05-25 17:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $fw;
|
2019-05-20 08:19:05 +00:00
|
|
|
}
|
2018-05-26 17:30:56 +00:00
|
|
|
}
|
2019-12-05 10:41:58 +00:00
|
|
|
|
2020-02-10 06:23:04 +00:00
|
|
|
if(!is_fn("write_debug_log")) {
|
2020-01-23 12:43:58 +00:00
|
|
|
function write_debug_log($message, $component="Debug", $program="") {
|
|
|
|
$fw = false;
|
|
|
|
|
|
|
|
// if not debug mode
|
|
|
|
if(APP_DEVELOPMENT === false) return $fw;
|
|
|
|
|
|
|
|
// if debug mode
|
|
|
|
$data = implode("\t", array(get_current_datetime(), $type, $message));
|
|
|
|
$fw = append_log_to_file($data, "debug.log");
|
|
|
|
|
|
|
|
// if enabled RFC3164 remote debugging
|
|
|
|
if(loadHelper("rfc3164.proto")) {
|
|
|
|
rfc3164_send_message($message, $component, $program);
|
2019-12-05 10:41:58 +00:00
|
|
|
}
|
2020-01-23 12:43:58 +00:00
|
|
|
|
|
|
|
return $fw;
|
2019-12-05 10:41:58 +00:00
|
|
|
}
|
|
|
|
}
|