Freeciv21
Develop your civilization from humble roots to a global empire
srv_log.h
Go to the documentation of this file.
1 /**************************************************************************
2  Copyright (c) 1996-2020 Freeciv21 and Freeciv contributors. This file is
3  __ __ part of Freeciv21. Freeciv21 is free software: you can
4 / \\..// \ redistribute it and/or modify it under the terms of the GNU
5  ( oo ) General Public License as published by the Free Software
6  \__/ Foundation, either version 3 of the License, or (at your
7  option) any later version. You should have received
8  a copy of the GNU General Public License along with Freeciv21. If not,
9  see https://www.gnu.org/licenses/.
10 **************************************************************************/
11 #pragma once
12 
13 // Qt
14 #include <QString>
15 #include <QtGlobal>
16 
17 // utility
18 #include "bitvector.h"
19 #include "support.h"
20 
21 // common
22 #include "fc_types.h"
23 
24 // server
25 #include "notify.h"
26 
27 /*
28  * Change these and remake to watch logs from a specific
29  * part of the AI code.
30  * FIXME Obsolete, remove them
31  */
32 #define LOGLEVEL_BODYGUARD LOG_DEBUG
33 #define LOGLEVEL_UNIT LOG_DEBUG
34 #define LOGLEVEL_GOTO LOG_DEBUG
35 #define LOGLEVEL_CITY LOG_DEBUG
36 #define LOGLEVEL_BUILD LOG_DEBUG
37 #define LOGLEVEL_HUNT LOG_DEBUG
38 #define LOGLEVEL_PLAYER LOG_DEBUG
39 
40 #define LOG_AI_TEST LOG_NORMAL
41 
42 enum ai_timer {
74  AIT_LAST
75 };
76 
78 
79 QString city_log_prefix(const city *pcity);
80 #define CITY_LOG(_, pcity, msg, ...) \
81  { \
82  bool notify = pcity->server.debug; \
83  QString message = city_log_prefix(pcity) + QStringLiteral(" ") \
84  + QString::asprintf(msg, ##__VA_ARGS__); \
85  if (notify) { \
86  qInfo().noquote() << message; \
87  notify_conn(nullptr, nullptr, E_AI_DEBUG, ftc_log, "%s", \
88  qUtf8Printable(message)); \
89  } else { \
90  qDebug().noquote() << message; \
91  } \
92  }
93 
94 QString unit_log_prefix(const unit *punit);
95 #define UNIT_LOG(_, punit, msg, ...) \
96  { \
97  bool notify = punit->server.debug \
98  || (tile_city(unit_tile(punit)) \
99  && tile_city(unit_tile(punit))->server.debug); \
100  QString message = unit_log_prefix(punit) + QStringLiteral(" ") \
101  + QString::asprintf(msg, ##__VA_ARGS__); \
102  if (notify) { \
103  qInfo().noquote() << message; \
104  notify_conn(nullptr, nullptr, E_AI_DEBUG, ftc_log, "%s", \
105  qUtf8Printable(message)); \
106  } else { \
107  qDebug().noquote() << message; \
108  } \
109  }
110 
111 void timing_log_init();
112 void timing_log_free();
113 
114 void timing_log_real(enum ai_timer timer, enum ai_timer_activity activity);
115 void timing_results_real();
116 
117 #ifdef FREECIV_DEBUG
118 #define TIMING_LOG(timer, activity) timing_log_real(timer, activity)
119 #define TIMING_RESULTS() timing_results_real()
120 #else // FREECIV_DEBUG
121 #define TIMING_LOG(timer, activity)
122 #define TIMING_RESULTS()
123 #endif // FREECIV_DEBUG
void timing_log_init()
Initialize AI timing system.
Definition: srv_log.cpp:163
void timing_log_free()
Free AI timing system resources.
Definition: srv_log.cpp:177
QString unit_log_prefix(const unit *punit)
Log a unit, it will appear like this Polish Archers[139] (5,35)->(0,0){0,0} where [] is unit id,...
Definition: srv_log.cpp:61
QString city_log_prefix(const city *pcity)
Log a city, it will appear like this Polish Romenna(5,35) [s1 d106 u11 g1].
Definition: srv_log.cpp:43
ai_timer
Definition: srv_log.h:42
@ AIT_RECOVER
Definition: srv_log.h:70
@ AIT_FSTK
Definition: srv_log.h:56
@ AIT_GOVERNMENT
Definition: srv_log.h:49
@ AIT_CARAVAN
Definition: srv_log.h:58
@ AIT_RAMPAGE
Definition: srv_log.h:73
@ AIT_CITY_MILITARY
Definition: srv_log.h:65
@ AIT_BUILDINGS
Definition: srv_log.h:53
@ AIT_TAXES
Definition: srv_log.h:50
@ AIT_ATTACK
Definition: srv_log.h:68
@ AIT_HUNTER
Definition: srv_log.h:59
@ AIT_BODYGUARD
Definition: srv_log.h:71
@ AIT_DEFENDERS
Definition: srv_log.h:57
@ AIT_SETTLERS
Definition: srv_log.h:46
@ AIT_UNITS
Definition: srv_log.h:45
@ AIT_CITIES
Definition: srv_log.h:51
@ AIT_AIRUNIT
Definition: srv_log.h:62
@ AIT_EXPLORER
Definition: srv_log.h:63
@ AIT_TECH
Definition: srv_log.h:55
@ AIT_CITY_TERRAIN
Definition: srv_log.h:66
@ AIT_FERRY
Definition: srv_log.h:72
@ AIT_MILITARY
Definition: srv_log.h:69
@ AIT_ALL
Definition: srv_log.h:43
@ AIT_MOVEMAP
Definition: srv_log.h:44
@ AIT_WORKERS
Definition: srv_log.h:47
@ AIT_DIPLOMAT
Definition: srv_log.h:61
@ AIT_LAST
Definition: srv_log.h:74
@ AIT_AIDATA
Definition: srv_log.h:48
@ AIT_AIRLIFT
Definition: srv_log.h:60
@ AIT_CITIZEN_ARRANGE
Definition: srv_log.h:52
@ AIT_CITY_SETTLERS
Definition: srv_log.h:67
@ AIT_DANGER
Definition: srv_log.h:54
@ AIT_EMERGENCY
Definition: srv_log.h:64
ai_timer_activity
Definition: srv_log.h:77
@ TIMER_STOP
Definition: srv_log.h:77
@ TIMER_START
Definition: srv_log.h:77
void timing_log_real(enum ai_timer timer, enum ai_timer_activity activity)
Measure the time between the calls.
Definition: srv_log.cpp:86
void timing_results_real()
Print results.
Definition: srv_log.cpp:114
Definition: city.h:291
Definition: unit.h:134