ScummVM API documentation
out.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 //=============================================================================
23 //
24 // Debug output interface provides functions which send a formatted message
25 // tagged with group ID and message type to the registered output handlers.
26 //
27 // Depending on configuration this message may be printed by any of those
28 // handlers, or none of them. The calling unit should not worry about where the
29 // message goes.
30 //
31 //-----------------------------------------------------------------------------
32 //
33 // On using message types.
34 //
35 // Please keep in mind, that there are different levels of errors. AGS logging
36 // system allows to classify debug message by two parameters: debug group and
37 // message type. Sometimes message type alone is not enough. Debug groups can
38 // also be used to distinct messages that has less (or higher) importance.
39 //
40 // For example, there are engine errors and user (game-dev) mistakes. Script
41 // commands that cannot be executed under given circumstances are user
42 // mistakes, and usually are not as severe as internal engine errors. This is
43 // why it is advised to use a separate debug group for mistakes like that to
44 // distinct them from reports on the internal engine's problems and make
45 // verbosity configuration flexible.
46 //
47 // kDbgMsg_Debug - is the most mundane type of message (if the printing function
48 // argument list does not specify message type, it is probably kDbgMsg_Debug).
49 // You can use it for almost anything, from noting some process steps to
50 // displaying current object state. If certain messages are meant to be printed
51 // very often, consider using another distinct debug group so that it may be
52 // disabled to reduce log verbosity.
53 //
54 // kDbgMsg_Info - is a type for important notifications, such as initialization
55 // and stopping of engine components.
56 //
57 // kDbgMsg_Warn - this is suggested for more significant cases, when you find
58 // out that something is not right, but is not immediately affecting engine
59 // processing. For example: certain object was constructed in a way that
60 // would make them behave unexpectedly, or certain common files are missing but
61 // it is not clear yet whether the game will be accessing them.
62 // In other words: use kDbgMsg_Warn when there is no problem right away, but
63 // you are *anticipating* that one may happen under certain circumstances.
64 //
65 // kDbgMsg_Error - use this kind of message is for actual serious problems.
66 // If certain operation assumes both positive and negative results are
67 // acceptable, it is preferred to report such negative result with simple
68 // kDbgMsg_Debug message. kDbgMsg_Error is for negative results that are not
69 // considered acceptable for normal run.
70 //
71 // kDbgMsg_Fatal - is the message type to be reported when the program or
72 // component abortion is imminent.
73 //
74 //=============================================================================
75 
76 #ifndef AGS_SHARED_CORE_DEBUGGING_OUT_H
77 #define AGS_SHARED_CORE_DEBUGGING_OUT_H
78 
79 #include "ags/shared/util/string.h"
80 
81 namespace AGS3 {
82 namespace AGS {
83 namespace Shared {
84 
85 // Message types provide distinction for debug messages by their intent.
86 enum MessageType {
87  kDbgMsg_None = 0,
88  // Alerts may be informative messages with topmost level of importance,
89  // such as reporting engine startup and shutdown.
90  kDbgMsg_Alert,
91  // Fatal errors are ones that make program abort immediately.
92  kDbgMsg_Fatal,
93  // Error messages are about engine not being able to perform requested
94  // operation in a situation when that will affect game playability and
95  // further execution.
96  kDbgMsg_Error,
97  // Warnings are made when unexpected or non-standart behavior
98  // is detected in program, which is not immediately critical,
99  // but may be a symptom of a bigger problem.
100  kDbgMsg_Warn,
101  // General information messages.
102  kDbgMsg_Info,
103  // Debug reason is for arbitrary information about events and current
104  // game state.
105  kDbgMsg_Debug,
106 
107 
108  // Convenient aliases
109  kDbgMsg_Default = kDbgMsg_Debug,
110  kDbgMsg_All = kDbgMsg_Debug
111 };
112 
113 // This enumeration is a list of common hard-coded groups, but more could
114 // be added via debugging configuration interface (see 'debug/debug.h').
115 enum CommonDebugGroup : uint32 {
116  kDbgGroup_None = UINT32_MAX,
117  // Main debug group is for reporting general engine status and issues
118  kDbgGroup_Main = 0,
119  // Game group is for logging game logic state and issues
120  kDbgGroup_Game,
121  // Log from the game script
122  kDbgGroup_Script,
123  // Sprite cache logging
124  kDbgGroup_SprCache,
125  // Group for debugging managed object state (can slow engine down!)
126  kDbgGroup_ManObj
127 };
128 
129 // Debug group identifier defining either numeric or string id, or both
130 struct DebugGroupID {
131  uint32_t ID;
132  String SID;
133 
134  DebugGroupID() : ID((uint32_t)kDbgGroup_None) {
135  }
136  DebugGroupID(uint32_t id, const String &sid = "") : ID(id), SID(sid) {
137  }
138  DebugGroupID(const String &sid) : ID((uint32_t)kDbgGroup_None), SID(sid) {
139  }
140  // Tells if any of the id components is valid
141  bool IsValid() const {
142  return ID != (uint32_t)kDbgGroup_None || !SID.IsEmpty();
143  }
144  // Tells if both id components are properly set
145  bool IsComplete() const {
146  return ID != (uint32_t)kDbgGroup_None && !SID.IsEmpty();
147  }
148 };
149 
150 namespace Debug {
151 //
152 // Debug output
153 //
154 // Output a plain message of default group and default type
155 void Printf(const String &text);
156 // Output a plain message of default group and given type
157 void Printf(MessageType mt, const String &text);
158 // Output a plain message of given group and type
159 void Printf(DebugGroupID group_id, MessageType mt, const String &text);
160 // Output formatted message of default group and default type
161 void Printf(const char *fmt, ...);
162 // Output formatted message of default group and given type
163 void Printf(MessageType mt, const char *fmt, ...);
164 // Output formatted message of given group and type
165 void Printf(DebugGroupID group_id, MessageType mt, const char *fmt, ...);
166 
167 } // namespace Debug
168 
169 } // namespace Shared
170 } // namespace AGS
171 } // namespace AGS3
172 
173 #endif
Definition: achievements_tables.h:27
Definition: out.h:130
Definition: string.h:62
Definition: ags.h:40