Skip to content

Commit a4f861f

Browse files
committed
Improved the logging function to support more actions, and a bit of code cleanup.
1 parent 6ac6391 commit a4f861f

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

include/logging.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace templ{
77

88
struct log_t{
99
enum values{
10-
ERROR, WARNING, PANIC, INFO
10+
ERROR, WARNING, PANIC, INFO, LOG, OK
1111
};
1212

1313
struct ctx{

src/cli/main.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
with both files added via pipes, like `vs.tmpl <(cat template.xml) <(cat data.xml)
1212
*/
1313

14+
#include "logging.hpp"
1415
#include <format>
1516
#include <pugixml.hpp>
1617

@@ -22,13 +23,15 @@ using namespace vs::templ;
2223

2324
void logfn(log_t::values type, const char* msg, const log_t::ctx&ctx){
2425
static const char* severity_table[] = {
25-
"\033[31;1m[ERROR]\033[0m : ",
26-
"\033[33;1m[WARNING]\033[0m: ",
27-
"\033[41;30;1m[PANIC]\033[0m : ",
28-
"\033[34;1m[INFO]\033[0m : ",
26+
"\033[31;1m[ERROR]\033[0m : ",
27+
"\033[33;1m[WARNING]\033[0m: ",
28+
"\033[41;30;1m[PANIC]\033[0m : ",
29+
"\033[34;1m[INFO]\033[0m : ",
30+
"\033[37;1m[LOG]\033[0m : ",
31+
"\032[34;1m[OK]\033[0m : ",
2932
};
30-
//TODO show context information
31-
std::cerr<<std::format("\033\n[33;1m╭\033[0m {}{} \033\n[33;1m├\033[0m src:/{}\n\033[33;1m├\033[0m tmpl:/{}\n\033[33;1m╰\033[0m dst:/{}\n",severity_table[type],msg,ctx.data_path,ctx.template_path,ctx.generated_path);
33+
34+
fprintf(type<=vs::templ::log_t::INFO?stderr:stdout,"%s",std::format("\033\n[33;1m╭\033[0m {}{} \033\n[33;1m├\033[0m src:/{}\n\033[33;1m├\033[0m tmpl:/{}\n\033[33;1m╰\033[0m dst:/{}\n",severity_table[type],msg,ctx.data_path,ctx.template_path,ctx.generated_path).c_str());
3235
}
3336

3437
bool loadfn (const pugi::xml_node ctx,pugi::xml_document& ref){
@@ -72,13 +75,11 @@ int main(int argc, const char* argv[]){
7275

7376
{auto t = tmpl.load(std::cin); if(!t){std::cerr<<t.description()<<" @ `template file`\n";exit(2);}}
7477
{auto t = data.load(std::cin); if(!t){std::cerr<<t.description()<<" @ `data file`\n";exit(3);}}
75-
7678
}
7779

7880
preprocessor doc({data,tmpl,ns_prefix, logfn, includefn, loadfn, seed});
7981
auto& result = doc.parse();
8082

81-
8283
result.save(std::cout);
8384

8485
return 0;

0 commit comments

Comments
 (0)