@@ -81,140 +81,111 @@ class GpaLogger : public TSingleton<GpaLogger>
8181 // / @param [in] log_message The message to pass along.
8282 void Log (GpaLoggingType log_type, const char * log_message);
8383
84+ void Logfv (GpaLoggingType type, const char * msg_fmt, va_list args)
85+ {
86+ // If the supplied message type is among those that the user wants be notified of,
87+ // then pass the message along.
88+ if (type & logging_type_)
89+ {
90+ EnterCriticalSection (&lock_handle);
91+
92+ // Format string.
93+ char buffer[1024 * 50 ];
94+ buffer[0 ] = ' \0 ' ;
95+ #ifdef WIN32
96+ vsnprintf_s (buffer, sizeof (buffer), msg_fmt, args);
97+ #else
98+ vsnprintf (buffer, sizeof (buffer), msg_fmt, args);
99+ #endif
100+ Log (type, buffer);
101+
102+ LeaveCriticalSection (&lock_handle);
103+ }
104+ }
105+
106+ void Logf (GpaLoggingType type, const char * msg_fmt, ...) __attribute__((format(printf, 3 , 4 )))
107+ {
108+ va_list args;
109+ va_start (args, msg_fmt);
110+ Logfv (type, msg_fmt, args);
111+ va_end (args);
112+ }
113+
84114 // / @brief Logs an error message.
85115 // /
86- // / @param [in] message The message to pass along.
87- inline void LogError (const char * message )
116+ // / @param [in] msg_fmt The message to format and pass along.
117+ inline void LogError (const char * msg_fmt, ...) __attribute__((format(printf, 2 , 3 )) )
88118 {
89- Log (kGpaLoggingError , message);
119+ va_list args;
120+ va_start (args, msg_fmt);
121+ Logfv (kGpaLoggingError , msg_fmt, args);
122+ va_end (args);
90123 }
91124
92125 // / @brief Logs an informational message.
93126 // /
94- // / @param [in] message The message to pass along.
95- inline void LogMessage (const char * message )
127+ // / @param [in] msg_fmt The message to format and pass along.
128+ inline void LogMessage (const char * msg_fmt, ...) __attribute__((format(printf, 2 , 3 )) )
96129 {
97- Log (kGpaLoggingMessage , message);
130+ va_list args;
131+ va_start (args, msg_fmt);
132+ Logfv (kGpaLoggingMessage , msg_fmt, args);
133+ va_end (args);
98134 }
99135
100136 // / @brief Logs a trace message.
101137 // /
102- // / @param [in] message The message to pass along.
103- inline void LogTrace (const char * message )
138+ // / @param [in] msg_fmt The message to format and pass along.
139+ inline void LogTrace (const char * msg_fmt, ...) __attribute__((format(printf, 2 , 3 )) )
104140 {
105- Log (kGpaLoggingTrace , message);
141+ va_list args;
142+ va_start (args, msg_fmt);
143+ Logfv (kGpaLoggingTrace , msg_fmt, args);
144+ va_end (args);
106145 }
107146
108147 // / @brief Logs a formatted message in internal builds; does nothing in release.
109148 // /
110149 // / @param [in] msg_fmt The message to format and pass along.
111- void LogDebugMessage (const char * msg_fmt, ...)
150+ void LogDebugMessage (const char * msg_fmt, ...) __attribute__((format(printf, 2 , 3 )))
112151 {
113- // If the supplied message type is among those that the user wants be notified of,
114- // then pass the message along.
115- if (kGpaLoggingDebugMessage & logging_type_)
116- {
117- EnterCriticalSection (&lock_handle);
118-
119- // Format string.
120- char buffer[1024 * 50 ];
121- va_list arg_list;
122- va_start (arg_list, msg_fmt);
123- #ifdef WIN32
124- vsprintf_s (buffer, msg_fmt, arg_list);
125- #else
126- vsprintf (buffer, msg_fmt, arg_list);
127- #endif
128- va_end (arg_list);
129-
130- Log (kGpaLoggingDebugMessage , buffer);
131-
132- LeaveCriticalSection (&lock_handle);
133- }
152+ va_list args;
153+ va_start (args, msg_fmt);
154+ Logfv (kGpaLoggingDebugMessage , msg_fmt, args);
155+ va_end (args);
134156 }
135157
136158 // / @brief Logs a formatted error message in debug builds; does nothing in release.
137159 // /
138160 // / @param [in] msg_fmt The message to format and pass along.
139- void LogDebugError (const char * msg_fmt, ...)
161+ void LogDebugError (const char * msg_fmt, ...) __attribute__((format(printf, 2 , 3 )))
140162 {
141- // If the supplied message type is among those that the user wants be notified of,
142- // then pass the message along.
143- if (kGpaLoggingDebugError & logging_type_)
144- {
145- EnterCriticalSection (&lock_handle);
146-
147- // Format string.
148- char buffer[1024 * 50 ];
149- va_list arg_list;
150- va_start (arg_list, msg_fmt);
151- #ifdef WIN32
152- vsprintf_s (buffer, msg_fmt, arg_list);
153- #else
154- vsprintf (buffer, msg_fmt, arg_list);
155- #endif
156- va_end (arg_list);
157-
158- Log (kGpaLoggingDebugError , buffer);
159-
160- LeaveCriticalSection (&lock_handle);
161- }
163+ va_list args;
164+ va_start (args, msg_fmt);
165+ Logfv (kGpaLoggingDebugError , msg_fmt, args);
166+ va_end (args);
162167 }
163168
164169 // / @brief Logs a formatted error message in debug builds; does nothing in release.
165170 // /
166171 // / @param [in] msg_fmt The message to format and pass along.
167- void LogDebugTrace (const char * msg_fmt, ...)
172+ void LogDebugTrace (const char * msg_fmt, ...) __attribute__((format(printf, 2 , 3 )))
168173 {
169- // If the supplied message type is among those that the user wants be notified of,
170- // then pass the message along.
171- if (kGpaLoggingDebugTrace & logging_type_)
172- {
173- EnterCriticalSection (&lock_handle);
174-
175- // Format string.
176- char buffer[1024 * 50 ];
177- va_list arg_list;
178- va_start (arg_list, msg_fmt);
179- #ifdef WIN32
180- vsprintf_s (buffer, msg_fmt, arg_list);
181- #else
182- vsprintf (buffer, msg_fmt, arg_list);
183- #endif
184- va_end (arg_list);
185-
186- Log (kGpaLoggingDebugTrace , buffer);
187-
188- LeaveCriticalSection (&lock_handle);
189- }
174+ va_list args;
175+ va_start (args, msg_fmt);
176+ Logfv (kGpaLoggingDebugTrace , msg_fmt, args);
177+ va_end (args);
190178 }
191179
192180 // / @brief Logs a formatted message in internal builds; does nothing in public builds.
193181 // /
194182 // / @param [in] msg_fmt The message to format and pass along.
195- void LogDebugCounterDefs (const char * msg_fmt, ...)
183+ void LogDebugCounterDefs (const char * msg_fmt, ...) __attribute__((format(printf, 2 , 3 )))
196184 {
197- // If the supplied message type is among those that the user wants be notified of,
198- // then pass the message along.
199- if (kGpaLoggingDebugCounterDefinitions & logging_type_)
200- {
201- EnterCriticalSection (&lock_handle);
202-
203- // Format string.
204- char buffer[1024 * 50 ];
205- va_list arg_list;
206- va_start (arg_list, msg_fmt);
207- #ifdef WIN32
208- vsprintf_s (buffer, msg_fmt, arg_list);
209- #else
210- vsprintf (buffer, msg_fmt, arg_list);
211- #endif
212- va_end (arg_list);
213-
214- Log (kGpaLoggingDebugCounterDefinitions , buffer);
215-
216- LeaveCriticalSection (&lock_handle);
217- }
185+ va_list args;
186+ va_start (args, msg_fmt);
187+ Logfv (kGpaLoggingDebugCounterDefinitions , msg_fmt, args);
188+ va_end (args);
218189 }
219190
220191 // / @brief Checks whether the tracing is enabled or not.
0 commit comments