1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not visit scipopt.org. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15
16 /**@file scip_message.c
17 * @ingroup OTHER_CFILES
18 * @brief public methods for message handling
19 * @author Tobias Achterberg
20 * @author Timo Berthold
21 * @author Gerald Gamrath
22 * @author Leona Gottwald
23 * @author Stefan Heinz
24 * @author Gregor Hendel
25 * @author Thorsten Koch
26 * @author Alexander Martin
27 * @author Marc Pfetsch
28 * @author Michael Winkler
29 * @author Kati Wolter
30 *
31 * @todo check all SCIP_STAGE_* switches, and include the new stages TRANSFORMED and INITSOLVE
32 */
33
34 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36 #include "scip/debug.h"
37 #include "scip/pub_message.h"
38 #include "scip/scip_message.h"
39 #include "scip/struct_scip.h"
40 #include "scip/struct_set.h"
41 #include "scip/struct_stat.h"
42
43 /** installs the given message handler, such that all messages are passed to this handler. A messages handler can be
44 * created via SCIPmessagehdlrCreate().
45 *
46 * @return \ref SCIP_OKAY is returned if everything worked. Otherwise a suitable error code is passed. See \ref
47 * SCIP_Retcode "SCIP_RETCODE" for a complete list of error codes.
48 *
49 * @pre this method can be called in one of the following stages of the SCIP solving process:
50 * - \ref SCIP_STAGE_INIT
51 * - \ref SCIP_STAGE_PROBLEM
52 *
53 * @note The currently installed messages handler gets freed if this SCIP instance is its last user (w.r.t. capture/release).
54 */
55 SCIP_RETCODE SCIPsetMessagehdlr(
56 SCIP* scip, /**< SCIP data structure */
57 SCIP_MESSAGEHDLR* messagehdlr /**< message handler to install, or NULL to suppress all output */
58 )
59 {
60 SCIP_CALL( SCIPcheckStage(scip, "SCIPsetMessagehdlr", TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE) );
61
62 assert(scip != NULL);
63 assert(scip->set != NULL);
64
65 SCIPmessagehdlrCapture(messagehdlr);
66
67 SCIP_CALL( SCIPmessagehdlrRelease(&scip->messagehdlr) );
68 assert(scip->messagehdlr == NULL);
69
70 scip->messagehdlr = messagehdlr;
71
72 return SCIP_OKAY;
73 }
74
75 /** returns the currently installed message handler
76 *
77 * @return the currently installed message handler, or NULL if messages are currently suppressed
78 */
79 SCIP_MESSAGEHDLR* SCIPgetMessagehdlr(
80 SCIP* scip /**< SCIP data structure */
81 )
82 {
83 return scip->messagehdlr;
84 }
85
86 /** sets the log file name for the currently installed message handler */
87 void SCIPsetMessagehdlrLogfile(
88 SCIP* scip, /**< SCIP data structure */
89 const char* filename /**< name of log file, or NULL (no log) */
90 )
91 {
92 if( scip->messagehdlr != NULL )
93 {
94 SCIPmessagehdlrSetLogfile(scip->messagehdlr, filename);
95 }
96 }
97
98 /** sets the currently installed message handler to be quiet (or not) */
99 void SCIPsetMessagehdlrQuiet(
100 SCIP* scip, /**< SCIP data structure */
101 SCIP_Bool quiet /**< should screen messages be suppressed? */
102 )
103 {
104 if( scip->messagehdlr != NULL )
105 {
106 SCIPmessagehdlrSetQuiet(scip->messagehdlr, quiet);
107 }
108 }
109
110 /** prints a warning message via the message handler */
111 void SCIPwarningMessage(
112 SCIP* scip, /**< SCIP data structure */
113 const char* formatstr, /**< format string like in printf() function */
114 ... /**< format arguments line in printf() function */
115 )
116 {
117 va_list ap;
118
119 assert(scip != NULL);
120
121 va_start(ap, formatstr); /*lint !e838*/
122 SCIPmessageVFPrintWarning(scip->messagehdlr, formatstr, ap);
123 va_end(ap);
124 }
125
126 /** prints a debug message */
127 void SCIPprintDebugMessage(
128 SCIP* scip, /**< SCIP data structure */
129 const char* sourcefile, /**< name of the source file that called the function */
130 int sourceline, /**< line in the source file where the function was called */
131 const char* formatstr, /**< format string like in printf() function */
132 ... /**< format arguments line in printf() function */
133 )
134 {
135 const char* filename;
136 int subscipdepth = 0;
137 va_list ap;
138
139 assert( sourcefile != NULL );
140 assert( scip != NULL );
141
142 /* strip directory from filename */
143 #if defined(_WIN32) || defined(_WIN64)
144 filename = strrchr(sourcefile, '\\');
145 #else
146 filename = strrchr(sourcefile, '/');
147 #endif
148 if ( filename == NULL )
149 filename = sourcefile;
150 else
151 ++filename;
152
153 if ( scip->stat != NULL )
154 subscipdepth = scip->stat->subscipdepth;
155 if ( subscipdepth > 0 )
156 SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "%d: [%s:%d] debug: ", subscipdepth, filename, sourceline);
157 else
158 SCIPmessageFPrintInfo(scip->messagehdlr, NULL, "[%s:%d] debug: ", filename, sourceline);
159
160 va_start(ap, formatstr); /*lint !e838*/
161 SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
162 va_end(ap);
163 }
164
165 /** prints a debug message without precode */
166 void SCIPdebugMessagePrint(
167 SCIP* scip, /**< SCIP data structure */
168 const char* formatstr, /**< format string like in printf() function */
169 ... /**< format arguments line in printf() function */
170 )
171 {
172 va_list ap;
173
174 assert( scip != NULL );
175
176 va_start(ap, formatstr); /*lint !e838*/
177 SCIPmessageVFPrintInfo(scip->messagehdlr, NULL, formatstr, ap);
178 va_end(ap);
179 }
180
181 /** prints a dialog message that requests user interaction or is a direct response to a user interactive command */
182 void SCIPdialogMessage(
183 SCIP* scip, /**< SCIP data structure */
184 FILE* file, /**< file stream to print into, or NULL for stdout */
185 const char* formatstr, /**< format string like in printf() function */
186 ... /**< format arguments line in printf() function */
187 )
188 {
189 va_list ap;
190
191 assert(scip != NULL);
192
193 va_start(ap, formatstr); /*lint !e838*/
194 SCIPmessageVFPrintDialog(scip->messagehdlr, file, formatstr, ap);
195 va_end(ap);
196 }
197
198 /** prints a message */
199 void SCIPinfoMessage(
200 SCIP* scip, /**< SCIP data structure */
|
(1) Event noescape: |
"SCIPinfoMessage(SCIP *, FILE *, char const *, ...)" does not free or save its parameter "file". |
|
(1) Event noescape: |
"SCIPinfoMessage(SCIP *, FILE *, char const *, ...)" does not free or save its parameter "file". |
|
(1) Event noescape: |
"SCIPinfoMessage(SCIP *, FILE *, char const *, ...)" does not free or save its parameter "file". |
|
(1) Event noescape: |
"SCIPinfoMessage(SCIP *, FILE *, char const *, ...)" does not free or save its parameter "file". |
|
(1) Event noescape: |
"SCIPinfoMessage(SCIP *, FILE *, char const *, ...)" does not free or save its parameter "file". |
|
(1) Event noescape: |
"SCIPinfoMessage(SCIP *, FILE *, char const *, ...)" does not free or save its parameter "file". |
|
(1) Event noescape: |
"SCIPinfoMessage(SCIP *, FILE *, char const *, ...)" does not free or save its parameter "file". |
|
(1) Event noescape: |
"SCIPinfoMessage(SCIP *, FILE *, char const *, ...)" does not free or save its parameter "file". |
201 FILE* file, /**< file stream to print into, or NULL for stdout */
202 const char* formatstr, /**< format string like in printf() function */
203 ... /**< format arguments line in printf() function */
204 )
205 {
206 va_list ap;
207
208 assert(scip != NULL);
209
210 va_start(ap, formatstr); /*lint !e838*/
211 SCIPmessageVFPrintInfo(scip->messagehdlr, file, formatstr, ap);
212 va_end(ap);
213 }
214
215 /** prints a message depending on the verbosity level */
216 void SCIPverbMessage(
217 SCIP* scip, /**< SCIP data structure */
218 SCIP_VERBLEVEL msgverblevel, /**< verbosity level of this message */
219 FILE* file, /**< file stream to print into, or NULL for stdout */
220 const char* formatstr, /**< format string like in printf() function */
221 ... /**< format arguments line in printf() function */
222 )
223 {
224 va_list ap;
225
226 assert(scip != NULL);
227 assert(scip->set != NULL);
228
229 va_start(ap, formatstr); /*lint !e838*/
230 SCIPmessageVFPrintVerbInfo(scip->messagehdlr, scip->set->disp_verblevel, msgverblevel, file, formatstr, ap);
231 va_end(ap);
232 }
233
234 /** returns the current message verbosity level
235 *
236 * @return message verbosity level of SCIP
237 *
238 * @see \ref SCIP_VerbLevel "SCIP_VERBLEVEL" for a list of all verbosity levels
239 */
240 SCIP_VERBLEVEL SCIPgetVerbLevel(
241 SCIP* scip /**< SCIP data structure */
242 )
243 {
244 assert(scip != NULL);
245 assert(scip->set != NULL);
246
247 return scip->set->disp_verblevel;
248 }
249