Coverage Report

Created: 2025-12-31 06:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ntopng/include/Trace.h
Line
Count
Source
1
/*
2
 *
3
 * (C) 2013-25 - ntop.org
4
 *
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 *
20
 */
21
22
#ifndef _TRACE_H_
23
#define _TRACE_H_
24
25
#include "ntop_includes.h"
26
27
0
#define TRACE_LEVEL_ERROR 0
28
6.27k
#define TRACE_LEVEL_WARNING 1
29
7.12k
#define TRACE_LEVEL_NORMAL 2
30
911
#define TRACE_LEVEL_INFO 3
31
3.11k
#define TRACE_LEVEL_DEBUG 6
32
0
#define TRACE_LEVEL_TRACE 9
33
34
0
#define TRACE_ERROR TRACE_LEVEL_ERROR, __FILE__, __LINE__
35
6.27k
#define TRACE_WARNING TRACE_LEVEL_WARNING, __FILE__, __LINE__
36
7.12k
#define TRACE_NORMAL TRACE_LEVEL_NORMAL, __FILE__, __LINE__
37
911
#define TRACE_INFO TRACE_LEVEL_INFO, __FILE__, __LINE__
38
3.11k
#define TRACE_DEBUG TRACE_LEVEL_DEBUG, __FILE__, __LINE__
39
#define TRACE_TRACE TRACE_LEVEL_TRACE, __FILE__, __LINE__
40
41
2
#define MAX_TRACE_LEVEL 9
42
#define TRACE_DEBUGGING MAX_TRACE_LEVEL
43
44
class Mutex; /* Forward */
45
class Redis;
46
47
/* ******************************* */
48
49
class Trace {
50
 private:
51
  char *logFile;
52
  FILE *logFd;
53
  Redis *traceRedis;
54
  int numLogLines;
55
  bool dontFreeRedis;
56
  volatile u_int8_t traceLevel;
57
  Mutex rotate_mutex;
58
  void open_log();
59
#ifdef WIN32
60
  void AddToMessageLog(LPTSTR lpszMsg);
61
#endif
62
63
 public:
64
  Trace();
65
  ~Trace();
66
67
  void init();
68
  void initRedis(const char *redis_host, const char *redis_password,
69
                 u_int16_t redis_port, u_int8_t _redis_db_id);
70
  void setRedis(Redis *r);
71
  void rotate_logs(bool forceRotation);
72
  void set_log_file(const char *log_file);
73
  void set_trace_level(u_int8_t id);
74
0
  inline u_int8_t get_trace_level() { return (traceLevel); };
75
  void traceEvent(int eventTraceLevel, const char *file, const int line,
76
                  const char *format, ...);
77
  void logEvent(int eventTraceLevel, char *log_line);
78
};
79
80
#endif /* _TRACE_H_ */