TkN 2.4
Toolkit for Nuclei
Loading...
Searching...
No Matches
tklog.cpp
1/********************************************************************************
2 * Copyright (c) : Université de Lyon 1, CNRS/IN2P3, UMR5822, *
3 * IP2I, F-69622 Villeurbanne Cedex, France *
4 * Normandie Université, ENSICAEN, UNICAEN, CNRS/IN2P3, *
5 * LPC Caen, F-14000 Caen, France *
6 * Contibutor(s) : *
7 * Jérémie Dudouet jeremie.dudouet@cnrs.fr [2020] *
8 * Diego Gruyer diego.gruyer@cnrs.fr [2020] *
9 * *
10 * Licensed under the MIT License <http://opensource.org/licenses/MIT>. *
11 * SPDX-License-Identifier: MIT *
12 ********************************************************************************/
13
14#include "tklog.h"
15
16namespace tkn {
24}
25
26using namespace tkn;
27
28thread_local tklog *tklog::g_log = nullptr;
29
30const tkstring tklog::freset_font = "\e[0m";
31
33{
34 if ( g_log == nullptr ) {
35 g_log = new tklog();
36 }
37
38 return g_log;
39}
40
41void tklog::progress_bar(int _max, int _value, const tkstring &_message)
42{
43 if(_value>_max) return;
44
45 int barWidth = 10;
46
47 get_mutex().lock();
48
49 std::cout << "\e[94;108;1m" << "[";
50 int pos = (int) (barWidth * (1.*_value/_max));
51 for (int i = 0; i < barWidth; ++i) {
52 if (i < pos) std::cout << "=";
53 else if (i == pos) std::cout << "=";
54 else std::cout << " ";
55 }
56 std::cout << "] " << freset_font << _message << " \r";
57 std::cout.flush();
58
59 if(_value==_max) std::cout << std::endl;
60
61 get_mutex().unlock();
62}
63
64void tklog::set_type(bType _type)
65{
66 fTypes.append(tkstring::Form(";%d",_type));
67}
68
69void tklog::reset()
70{
73 fTypes = "";
75 fskiplog=false;
76}
77
78void tklog::process_color()
79{
80 fHeader.str("");fHeader.clear();
81
82 tkstring fg_color, bg_color;
83
85 fg_color = tkstring::Form("%d",90+fFG_color);
86 bg_color = tkstring::Form("%d",100+fBG_color);
87 }
88 else {
89 fg_color = tkstring::Form("%d",30+fFG_color);
90 bg_color = tkstring::Form("%d",40+fBG_color);
91 }
92
93 fHeader << "\e[" + fg_color + ";" + bg_color + fTypes + "m";
94}
95
96#ifdef HAS_ROOT
98ClassImp(tklog);
99#endif
Classe used to print debugs, infos, warnings and errors into the terminal.
Definition tklog.h:31
@ kDefault_color
Definition tklog.h:121
void progress_bar(int _max, int _value, const tkstring &_message="")
Definition tklog.cpp:41
friend tklog & reset(tklog &)
To print the current message, then reset the log.
Definition tklog.h:226
tkstring fTypes
Definition tklog.h:134
bColor fFG_color
Definition tklog.h:132
bool fHigh_intensity_colors
Definition tklog.h:135
static tklog * the_log()
glog is a singleton used for fancy prints in the terminal
Definition tklog.cpp:32
static const tkstring freset_font
Contains the style (color + type)
Definition tklog.h:107
bColor fBG_color
Definition tklog.h:133
std::ostringstream fHeader
Contains the core message string to be printed with the current style.
Definition tklog.h:106
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition tkstring.h:31
static tkstring Form(const char *_format,...)
Definition tkstring.cpp:322
tkstring & append(const tkstring &_st)
Definition tkstring.h:204
Definition tklog.cpp:16