reasonableframework/system/logger.php

76 lines
2.0 KiB
PHP
Raw Normal View History

<?php
/**
* @file logger.php
2020-01-23 12:44:27 +00:00
* @created_on 2018-05-27
* @updated_on 2020-01-23
* @author Go Namhyeon <gnh1201@gmail.com>
2018-05-26 17:35:32 +00:00
* @brief Logger module for ReasonableFramework
*/
2019-12-05 10:41:58 +00:00
2020-01-23 12:43:58 +00:00
if(!check_function_exists("append_log_to_file")) {
function append_log_to_file($data, $filename) {
2019-12-05 10:41:58 +00:00
return append_storage_file($data, array(
"storage_type" => "logs",
"filename" => $filename,
"chmod" => 0644,
"nl" => "<",
));
}
}
2019-02-26 05:40:03 +00:00
if(!check_function_exists("write_visit_log")) {
2019-05-20 08:19:05 +00:00
function write_visit_log() {
$fw = false;
2019-12-05 10:41:58 +00:00
2019-05-25 17:51:13 +00:00
$data = "";
2019-05-20 08:19:05 +00:00
if(loadHelper("networktool")) {
2019-12-05 10:41:58 +00:00
$nevt = get_network_event();
2019-05-27 08:16:04 +00:00
if(loadHelper("catsplit.format")) {
2019-12-05 10:41:58 +00:00
$data = catsplit_encode($nevt);
2019-05-25 17:33:30 +00:00
} else {
2019-12-05 10:41:58 +00:00
$data = json_encode($nevt);
2019-05-25 17:33:30 +00:00
}
2020-01-23 12:43:58 +00:00
$fw = append_log_to_file($data, "network.log");
2019-05-20 08:19:05 +00:00
}
2018-09-28 06:38:18 +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
2019-02-26 05:40:03 +00:00
if(!check_function_exists("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-01-23 12:43:58 +00:00
$data = implode("\t", array(get_current_datetime(), $component, $message));
$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
}
}
2019-12-05 10:41:58 +00:00
if(!check_function_exists("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
}
}