TkN 2.1
Toolkit for Nuclei
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 * This software is governed by the CeCILL-B license under French law and *
11 * abiding by the rules of distribution of free software. You can use, *
12 * modify and/ or redistribute the software under the terms of the *
13 * CeCILL-B license as circulated by CEA, CNRS and INRIA at the following *
14 * URL \"http://www.cecill.info\". *
15 * *
16 * As a counterpart to the access to the source code and rights to copy, *
17 * modify and redistribute granted by the license, users are provided *
18 * only with a limited warranty and the software's author, the holder of *
19 * the economic rights, and the successive licensors have only limited *
20 * liability. *
21 * *
22 * In this respect, the user's attention is drawn to the risks associated *
23 * with loading, using, modifying and/or developing or reproducing the *
24 * software by the user in light of its specific status of free software, *
25 * that may mean that it is complicated to manipulate, and that also *
26 * therefore means that it is reserved for developers and experienced *
27 * professionals having in-depth computer knowledge. Users are therefore *
28 * encouraged to load and test the software's suitability as regards *
29 * their requirements in conditions enabling the security of their *
30 * systems and/or data to be ensured and, more generally, to use and *
31 * operate it in the same conditions as regards security. *
32 * *
33 * The fact that you are presently reading this means that you have had *
34 * knowledge of the CeCILL-B license and that you accept its terms. *
35 ********************************************************************************/
36
37#include "tklog.h"
38
39namespace tkn {
47}
48
49using namespace tkn;
50
51thread_local tklog *tklog::g_log = nullptr;
52
53const tkstring tklog::freset_font = "\e[0m";
54
55tklog *tklog::the_log()
56{
57 if ( g_log == nullptr ) {
58 g_log = new tklog();
59 }
60
61 return g_log;
62}
63
64void tklog::progress_bar(int _max, int _value, const tkstring &_message)
65{
66 if(_value>_max) return;
67
68 int barWidth = 10;
69
70 get_mutex().lock();
71
72 std::cout << "\e[94;108;1m" << "[";
73 int pos = (int) (barWidth * (1.*_value/_max));
74 for (int i = 0; i < barWidth; ++i) {
75 if (i < pos) std::cout << "=";
76 else if (i == pos) std::cout << "=";
77 else std::cout << " ";
78 }
79 std::cout << "] " << freset_font << _message << " \r";
80 std::cout.flush();
81
82 if(_value==_max) std::cout << std::endl;
83
84 get_mutex().unlock();
85}
86
87void tklog::set_type(bType _type)
88{
89 fTypes.append(tkstring::Form(";%d",_type));
90}
91
92void tklog::reset()
93{
96 fTypes = "";
98 fskiplog=false;
99}
100
101void tklog::process_color()
102{
103 fHeader.str("");fHeader.clear();
104
105 tkstring fg_color, bg_color;
106
108 fg_color = tkstring::Form("%d",90+fFG_color);
109 bg_color = tkstring::Form("%d",100+fBG_color);
110 }
111 else {
112 fg_color = tkstring::Form("%d",30+fFG_color);
113 bg_color = tkstring::Form("%d",40+fBG_color);
114 }
115
116 fHeader << "\e[" + fg_color + ";" + bg_color + fTypes + "m";
117}
118
119#ifdef HAS_ROOT
121ClassImp(tklog);
122#endif
Classe used to print debugs, infos, warnings and errors into the terminal.
Definition: tklog.h:54
@ kDefault_color
Definition: tklog.h:144
tklog()
Definition: tklog.h:167
void progress_bar(int _max, int _value, const tkstring &_message="")
Definition: tklog.cpp:64
tkstring fTypes
Definition: tklog.h:157
bColor fFG_color
Definition: tklog.h:155
bool fHigh_intensity_colors
Definition: tklog.h:158
static const tkstring freset_font
Contains the style (color + type)
Definition: tklog.h:130
bColor fBG_color
Definition: tklog.h:156
std::ostringstream fHeader
Contains the core message string to be printed with the current style.
Definition: tklog.h:129
std::string with usefull tricks from TString (ROOT) and KVString (KaliVeda) and more....
Definition: tkstring.h:54
static tkstring Form(const char *_format,...)
Definition: tkstring.cpp:345
tkstring & append(const tkstring &_st)
Definition: tkstring.h:227
Definition: tklog.cpp:39