Add log_level option to filter output logs

This commit is contained in:
Tindy X committed 2020-03-05 13:57:58 +08:00
1 parent 15a66609af
commit 908d8ec19d
10 files changed
+244 -79

No files matched your search

+17 -8
View File
@@ -8,6 +8,7 @@
#include "multithread.h"
#include "socket.h"
#include "string_hash.h"
#include "logger.h"
#include <algorithm>
#include <iostream>
@@ -2446,21 +2447,24 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
if(!fileExist("gistconf.ini"))
{
std::cerr<<"gistconf.ini not found. Skipping...\n";
//std::cerr<<"gistconf.ini not found. Skipping...\n";
writeLog(0, "gistconf.ini not found. Skipping...", LOG_LEVEL_ERROR);
return -1;
}
ini.ParseFile("gistconf.ini");
if(ini.EnterSection("common") != 0)
{
std::cerr<<"gistconf.ini has incorrect format. Skipping...\n";
//std::cerr<<"gistconf.ini has incorrect format. Skipping...\n";
writeLog(0, "gistconf.ini has incorrect format. Skipping...", LOG_LEVEL_ERROR);
return -1;
}
token = ini.Get("token");
if(!token.size())
{
std::cerr<<"No token is provided. Skipping...\n";
//std::cerr<<"No token is provided. Skipping...\n";
writeLog(0, "No token is provided. Skipping...", LOG_LEVEL_ERROR);
return -1;
}
@@ -2476,24 +2480,28 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
if(!id.size())
{
std::cerr<<"No gist id is provided. Creating new gist...\n";
//std::cerr<<"No gist id is provided. Creating new gist...\n";
writeLog(0, "No Gist id is provided. Creating new Gist...", LOG_LEVEL_ERROR);
retVal = curlPost("https://api.github.com/gists", buildGistData(path, content), getSystemProxy(), token, &retData);
if(retVal != 201)
{
std::cerr<<"Create new Gist failed! Return data:\n"<<retData<<"\n";
//std::cerr<<"Create new Gist failed! Return data:\n"<<retData<<"\n";
writeLog(0, "Create new Gist failed! Return data:\n" + retData, LOG_LEVEL_ERROR);
return -1;
}
}
else
{
url = "https://gist.githubusercontent.com/" + username + "/" + id + "/raw/" + path;
std::cerr<<"Gist id provided. Modifying gist...\n";
//std::cerr<<"Gist id provided. Modifying Gist...\n";
writeLog(0, "Gist id provided. Modifying Gist...", LOG_LEVEL_INFO);
if(writeManageURL)
content = "#!MANAGED-CONFIG " + url + "\n" + content;
retVal = curlPatch("https://api.github.com/gists/" + id, buildGistData(path, content), getSystemProxy(), token, &retData);
if(retVal != 200)
{
std::cerr<<"Modify gist failed! Return data:\n"<<retData<<"\n";
//std::cerr<<"Modify gist failed! Return data:\n"<<retData<<"\n";
writeLog(0, "Modify Gist failed! Return data:\n" + retData, LOG_LEVEL_ERROR);
return -1;
}
}
@@ -2502,7 +2510,8 @@ int uploadGist(std::string name, std::string path, std::string content, bool wri
if(json.HasMember("owner"))
GetMember(json["owner"], "login", username);
url = "https://gist.githubusercontent.com/" + username + "/" + id + "/raw/" + path;
std::cerr<<"Writing to Gist success!\nGenerator: "<<name<<"\nPath: "<<path<<"\nRaw URL: "<<url<<"\nGist owner: "<<username<<"\n";
//std::cerr<<"Writing to Gist success!\nGenerator: "<<name<<"\nPath: "<<path<<"\nRaw URL: "<<url<<"\nGist owner: "<<username<<"\n";
writeLog(0, "Writing to Gist success!\nGenerator: " + name + "\nPath: " + path + "\nRaw URL: " + url + "\nGist owner: " + username, LOG_LEVEL_INFO);
ini.EraseSection();
ini.Set("token", token);