Enhancements

Add no-resolve to generated Clash rule-set if exists (#679).
Do not set CURLOPT_USERAGENT if User-Agent header is provided.
Print curl verbose logs with standard format.
Change thread id in logs to thread name.
Optimize generation of rule contents.
This commit is contained in:
Tindy X committed 2023-12-05 18:37:14 +08:00
1 parent adaef88501
commit a0e25158f5
5 files changed
+130 -57

No files matched your search

+17 -6
View File
@@ -13,10 +13,10 @@ std::string getTime(int type)
time_t lt;
char tmpbuf[32], cMillis[7];
std::string format;
timeval tv;
gettimeofday(&tv, NULL);
timeval tv = {};
gettimeofday(&tv, nullptr);
snprintf(cMillis, 7, "%.6ld", (long)tv.tv_usec);
lt = time(NULL);
lt = time(nullptr);
struct tm *local = localtime(&lt);
switch(type)
{
@@ -27,19 +27,30 @@ std::string getTime(int type)
format = "%Y/%m/%d %a %H:%M:%S." + std::string(cMillis);
break;
case 3:
default:
format = "%Y-%m-%d %H:%M:%S";
break;
}
strftime(tmpbuf, 32, format.data(), local);
return std::string(tmpbuf);
return {tmpbuf};
}
static std::string get_thread_name()
{
static std::atomic_int counter = 0;
thread_local static std::string name = "Thread-" + std::to_string(counter++);
return name;
}
std::mutex log_mutex;
void writeLog(int type, const std::string &content, int level)
{
if(level > global.logLevel)
return;
std::lock_guard<std::mutex> lock(log_mutex);
const char *levels[] = {"[FATL]", "[ERRO]", "[WARN]", "[INFO]", "[DEBG]", "[VERB]"};
std::cerr<<getTime(2)<<" ["<<getpid()<<" "<<std::this_thread::get_id()<<"]"<<levels[level % 6];
std::cerr<<getTime(2)<<" ["<<getpid()<<" "<<get_thread_name()<<"]"<<levels[level % 6];
std::cerr<<" "<<content<<"\n";
}
@@ -53,7 +64,7 @@ std::string demangle(const char* name)
{
int status = -4;
std::unique_ptr<char, void(*)(void*)> res {
abi::__cxa_demangle(name, NULL, NULL, &status),
abi::__cxa_demangle(name, nullptr, nullptr, &status),
std::free
};
return (status == 0) ? res.get() : name;
+1
View File
@@ -10,6 +10,7 @@
using string = std::string;
using string_size = std::string::size_type;
using string_array = std::vector<std::string>;
using string_view_array = std::vector<std::string_view>;
using string_map = std::map<std::string, std::string>;
using string_multimap = std::multimap<std::string, std::string>;
using string_pair_array = std::vector<std::pair<std::string, std::string>>;