refactor: Move logging functions to library file
This commit is contained in:
@@ -8,36 +8,10 @@ PODKOP_LIB="/usr/lib/podkop"
|
|||||||
. "$PODKOP_LIB/helpers.sh"
|
. "$PODKOP_LIB/helpers.sh"
|
||||||
. "$PODKOP_LIB/sing_box_config_manager.sh"
|
. "$PODKOP_LIB/sing_box_config_manager.sh"
|
||||||
. "$PODKOP_LIB/sing_box_config_facade.sh"
|
. "$PODKOP_LIB/sing_box_config_facade.sh"
|
||||||
|
. "$PODKOP_LIB/logging.sh"
|
||||||
|
|
||||||
config_load "$PODKOP_CONFIG"
|
config_load "$PODKOP_CONFIG"
|
||||||
|
|
||||||
log() {
|
|
||||||
local message="$1"
|
|
||||||
local level="$2"
|
|
||||||
|
|
||||||
if [ "$level" == "" ]; then
|
|
||||||
level="info"
|
|
||||||
fi
|
|
||||||
|
|
||||||
logger -t "podkop" "[$level] $message"
|
|
||||||
}
|
|
||||||
|
|
||||||
nolog() {
|
|
||||||
local message="$1"
|
|
||||||
local timestamp
|
|
||||||
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
echo -e "${COLOR_CYAN}[$timestamp]${COLOR_RESET} ${COLOR_GREEN}$message${COLOR_RESET}"
|
|
||||||
}
|
|
||||||
|
|
||||||
echolog() {
|
|
||||||
local message="$1"
|
|
||||||
local level="$2"
|
|
||||||
|
|
||||||
log "$message" "$level"
|
|
||||||
nolog "$message"
|
|
||||||
}
|
|
||||||
|
|
||||||
start_main() {
|
start_main() {
|
||||||
log "Starting podkop"
|
log "Starting podkop"
|
||||||
|
|
||||||
|
|||||||
@@ -9,10 +9,6 @@ FAKEIP_TEST_DOMAIN="fakeip.podkop.fyi"
|
|||||||
TMP_SING_BOX_FOLDER="/tmp/sing-box"
|
TMP_SING_BOX_FOLDER="/tmp/sing-box"
|
||||||
TMP_RULESET_FOLDER="$TMP_SING_BOX_FOLDER/rulesets"
|
TMP_RULESET_FOLDER="$TMP_SING_BOX_FOLDER/rulesets"
|
||||||
CLOUDFLARE_OCTETS="8.47 162.159 188.114" # Endpoints https://github.com/ampetelin/warp-endpoint-checker
|
CLOUDFLARE_OCTETS="8.47 162.159 188.114" # Endpoints https://github.com/ampetelin/warp-endpoint-checker
|
||||||
# Color constants
|
|
||||||
COLOR_CYAN="\033[0;36m"
|
|
||||||
COLOR_GREEN="\033[0;32m"
|
|
||||||
COLOR_RESET="\033[0m"
|
|
||||||
|
|
||||||
## nft
|
## nft
|
||||||
NFT_TABLE_NAME="PodkopTable"
|
NFT_TABLE_NAME="PodkopTable"
|
||||||
|
|||||||
30
podkop/files/usr/lib/logging.sh
Normal file
30
podkop/files/usr/lib/logging.sh
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
COLOR_CYAN="\033[0;36m"
|
||||||
|
COLOR_GREEN="\033[0;32m"
|
||||||
|
COLOR_RESET="\033[0m"
|
||||||
|
|
||||||
|
log() {
|
||||||
|
local message="$1"
|
||||||
|
local level="$2"
|
||||||
|
|
||||||
|
if [ "$level" == "" ]; then
|
||||||
|
level="info"
|
||||||
|
fi
|
||||||
|
|
||||||
|
logger -t "podkop" "[$level] $message"
|
||||||
|
}
|
||||||
|
|
||||||
|
nolog() {
|
||||||
|
local message="$1"
|
||||||
|
local timestamp
|
||||||
|
timestamp=$(date +"%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
echo -e "${COLOR_CYAN}[$timestamp]${COLOR_RESET} ${COLOR_GREEN}$message${COLOR_RESET}"
|
||||||
|
}
|
||||||
|
|
||||||
|
echolog() {
|
||||||
|
local message="$1"
|
||||||
|
local level="$2"
|
||||||
|
|
||||||
|
log "$message" "$level"
|
||||||
|
nolog "$message"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user