Debian Codegraph @

www/errlog.html

raw
1 <!DOCTYPE html>
2 <html><head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0">
4 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 <link href="sqlite.css" rel="stylesheet">
6 <title>The Error And Warning Log</title>
7 <!-- path= -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="index.html">
12 <img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0">
13 </a>
14 <div><!-- IE hack to prevent disappearing logo --></div>
15 <div class="tagline desktoponly">
16 Small. Fast. Reliable.<br>Choose any three.
17 </div>
18 <div class="menu mainmenu">
19 <ul>
20 <li><a href="index.html">Home</a>
21 <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
22 <li class='wideonly'><a href='about.html'>About</a>
23 <li class='desktoponly'><a href="docs.html">Documentation</a>
24 <li class='desktoponly'><a href="download.html">Download</a>
25 <li class='wideonly'><a href='copyright.html'>License</a>
26 <li class='desktoponly'><a href="support.html">Support</a>
27 <li class='desktoponly'><a href="prosupport.html">Purchase</a>
28 <li class='search' id='search_menubutton'>
29 <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
30 </ul>
31 </div>
32 <div class="menu submenu" id="submenu">
33 <ul>
34 <li><a href='about.html'>About</a>
35 <li><a href='docs.html'>Documentation</a>
36 <li><a href='download.html'>Download</a>
37 <li><a href='support.html'>Support</a>
38 <li><a href='prosupport.html'>Purchase</a>
39 </ul>
40 </div>
41 <div class="searchmenu" id="searchmenu">
42 <form method="GET" action="search">
43 <select name="s" id="searchtype">
44 <option value="d">Search Documentation</option>
45 <option value="c">Search Changelog</option>
46 </select>
47 <input type="text" name="q" id="searchbox" value="">
48 <input type="submit" value="Go">
49 </form>
50 </div>
51 </div>
52 <script>
53 function toggle_div(nm) {
54 var w = document.getElementById(nm);
55 if( w.style.display=="block" ){
56 w.style.display = "none";
57 }else{
58 w.style.display = "block";
59 }
60 }
61 function toggle_search() {
62 var w = document.getElementById("searchmenu");
63 if( w.style.display=="block" ){
64 w.style.display = "none";
65 } else {
66 w.style.display = "block";
67 setTimeout(function(){
68 document.getElementById("searchbox").focus()
69 }, 30);
70 }
71 }
72 function div_off(nm){document.getElementById(nm).style.display="none";}
73 window.onbeforeunload = function(e){div_off("submenu");}
74 /* Disable the Search feature if we are not operating from CGI, since */
75 /* Search is accomplished using CGI and will not work without it. */
76 if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
77 document.getElementById("search_menubutton").style.display = "none";
78 }
79 /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
80 function hideorshow(btn,obj){
81 var x = document.getElementById(obj);
82 var b = document.getElementById(btn);
83 if( x.style.display!='none' ){
84 x.style.display = 'none';
85 b.innerHTML='show';
86 }else{
87 x.style.display = '';
88 b.innerHTML='hide';
89 }
90 return false;
91 }
92 var antiRobot = 0;
93 function antiRobotGo(){
94 if( antiRobot!=3 ) return;
95 antiRobot = 7;
96 var j = document.getElementById("mtimelink");
97 if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
98 }
99 function antiRobotDefense(){
100 document.body.onmousedown=function(){
101 antiRobot |= 2;
102 antiRobotGo();
103 document.body.onmousedown=null;
104 }
105 document.body.onmousemove=function(){
106 antiRobot |= 2;
107 antiRobotGo();
108 document.body.onmousemove=null;
109 }
110 setTimeout(function(){
111 antiRobot |= 1;
112 antiRobotGo();
113 }, 100)
114 antiRobotGo();
115 }
116 antiRobotDefense();
117 </script>
118 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 The Error And Warning Log
122 </div>
123 <div class="fancy_toc">
124 <a onclick="toggle_toc()">
125 <span class="fancy_toc_mark" id="toc_mk">&#x25ba;</span>
126 Table Of Contents
127 </a>
128 <div id="toc_sub"><div class="fancy-toc1"><a href="#setting_up_the_error_logging_callback">1. Setting Up The Error Logging Callback</a></div>
129 <div class="fancy-toc1"><a href="#interface_details">2. Interface Details</a></div>
130 <div class="fancy-toc1"><a href="#variety_of_error_messages">3. Variety of Error Messages</a></div>
131 <div class="fancy-toc1"><a href="#summary">4. Summary</a></div>
132 </div>
133 </div>
134 <script>
135 function toggle_toc(){
136 var sub = document.getElementById("toc_sub")
137 var mk = document.getElementById("toc_mk")
138 if( sub.style.display!="block" ){
139 sub.style.display = "block";
140 mk.innerHTML = "&#x25bc;";
141 } else {
142 sub.style.display = "none";
143 mk.innerHTML = "&#x25ba;";
144 }
145 }
146 </script>
147 </div>
148
149
150
151
152 <h2 style="margin-left:1.0em" notoc="1" id="overview"> Overview</h2>
153
154 <p>SQLite can be configured to invoke a callback function containing
155 an error code and a terse error message whenever anomalies occur.
156 This mechanism is very helpful in tracking obscure problems that
157 occur rarely and in the field. Application developers are encouraged
158 to take advantage of the error logging facility of SQLite in their
159 products, as it is very low CPU and memory cost but can be a
160 huge aid for debugging.</p>
161
162 <h1 id="setting_up_the_error_logging_callback"><span>1. </span>Setting Up The Error Logging Callback</h1>
163
164 <p>There can only be a single error logging callback per process.
165 The error logging callback is registered at start-time using C-code
166 similar to the following:
167
168 </p><blockquote><pre>
169 <a href="c3ref/config.html">sqlite3_config</a>(<a href="c3ref/c_config_covering_index_scan.html#sqliteconfiglog">SQLITE_CONFIG_LOG</a>, errorLogCallback, pData);
170 </pre></blockquote>
171
172 <p>The error logger callback function might look something like this:</p>
173
174 <blockquote><pre>
175 void errorLogCallback(void *pArg, int iErrCode, const char *zMsg){
176 fprintf(stderr, "(%d) %s\n", iErrCode, zMsg);
177 }
178 </pre></blockquote>
179
180 <p>The example above illustrates the signature of the error logger callback.
181 However, in an embedded application, one usually does not print
182 messages on stderr. Instead, one might store the messages in a
183 preallocated circular buffer where they can be accessed when diagnostic
184 information is needed during debugging. Or perhaps the messages can be
185 sent to <a href="http://en.wikipedia.org/wiki/Syslog">Syslog</a>. Somehow, the
186 messages need to be stored where they are accessible to developers,
187 not displayed to end users.</p>
188
189 <p>Do not misunderstand: There is nothing technically wrong with displaying
190 the error logger messages to end users. The messages do not contain
191 sensitive or private information that must be protected from unauthorized
192 viewing. Rather the messages are technical in nature and are not useful
193 or meaningful to the typical end user. The messages coming from the
194 error logger are intended for database geeks. Display them accordingly.</p>
195
196 <h1 id="interface_details"><span>2. </span>Interface Details</h1>
197
198 <p>The third argument to the <a href="c3ref/config.html">sqlite3_config</a>(<a href="c3ref/c_config_covering_index_scan.html#sqliteconfiglog">SQLITE_CONFIG_LOG</a>,...)
199 interface (the "pData" argument in the example above) is a pointer to arbitrary
200 data. SQLite passes this pointer through to the first argument of the
201 error logger callback. The pointer can be used to pass application-specific
202 setup or state information, if desired. Or it can simply be a NULL
203 pointer which is ignored by the callback.</p>
204
205 <p>The second argument to the error logger callback is an integer
206 <a href="rescode.html#extrc">extended error code</a>. The third argument to the error logger is the
207 text of the error message. The error message text is stored in a fixed-length
208 stack buffer in the calling function and so will only be valid for the
209 duration of the error logger callback function. The error logger should
210 make a copy of this message into persistent storage if retention of the
211 message is needed.</p>
212
213 <p>The error logger callback should be treated like a signal handler.
214 The application should save off or otherwise process the error, then return
215 as soon as possible. No other SQLite APIs should be invoked, directly or
216 indirectly, from the error logger. SQLite is <u>not</u> reentrant through
217 the error logger callback. In particular, the error logger callback
218 is invoked when a memory allocation fails, so it is generally a bad idea
219 to try to allocate memory inside the error logger. Do not even think
220 about trying to store the error message in another SQLite database.</p>
221
222 <p>Applications can use the <a href="c3ref/log.html">sqlite3_log(E,F,..)</a> API to send new messages
223 to the log, if desired, but this is discouraged. The <a href="c3ref/log.html">sqlite3_log()</a>
224 interface is intended for use by extensions only, not by applications.</p>
225
226 <h1 id="variety_of_error_messages"><span>3. </span>Variety of Error Messages</h1>
227
228 <p>The error messages that might be sent to the error logger and their
229 exact format is subject to changes from one release to the next. So
230 applications should not depend on any particular error message text formats or
231 error codes. Things do not change capriciously, but they do sometimes
232 changes.</p>
233
234 <p>The following is a partial list of the kinds of messages that might
235 appear in the error logger callback.</p>
236
237 <ul>
238 <li><p>
239 Any time there is an error either compiling an SQL statement
240 (using <a href="c3ref/prepare.html">sqlite3_prepare_v2()</a> or its siblings) or running an SQL
241 statement (using <a href="c3ref/step.html">sqlite3_step()</a>) that error is logged.
242 </p>
243
244 </li><li><p>
245 When a schema change occurs that requires a prepared statement to be reparsed
246 and reprepared, that event is logged with the error code SQLITE_SCHEMA.
247 The reparse and reprepare is normally automatic (assuming that
248 <a href="c3ref/prepare.html">sqlite3_prepare_v2()</a> has been used to prepare the statements originally,
249 which is recommended) and so these logging events are normally the only
250 way to know that reprepares are taking place.</p>
251
252 </li><li><p>
253 SQLITE_NOTICE messages are logged whenever a database has to be recovered
254 because the previous writer crashed without completing its transaction.
255 The error code is SQLITE_NOTICE_RECOVER_ROLLBACK when recovering a
256 <a href="lockingv3.html#rollback">rollback journal</a> and SQLITE_NOTICE_RECOVER_WAL when recovering a
257 <a href="wal.html">write-ahead log</a>.
258 </p>
259
260 </li><li><p>
261 SQLITE_WARNING messages are logged when database files are renamed or
262 aliased in ways that can lead to database corruption.
263 (See <a href="howtocorrupt.html#unlink">1</a> and <a href="howtocorrupt.html#alias">2</a> for
264 additional information.)
265 </p>
266
267 </li><li><p>
268 Out of memory (OOM) error conditions generate error logging events
269 with the SQLITE_NOMEM error code and a message that says how many bytes
270 of memory were requested by the failed allocation.
271 </p>
272
273 </li><li><p>I/O errors in the OS-interface generate error logging events.
274 The message to these events gives the line number in the source code where
275 the error originated and the filename associated with the event when
276 there is a corresponding file. </p>
277
278 </li><li><p>When database corruption is detected, an SQLITE_CORRUPT error
279 logger callback is invoked. As with I/O errors, the error message text
280 contains the line number in the original source code where the error
281 was first detected.</p>
282
283 </li><li><p>
284 An error logger callback is invoked on SQLITE_MISUSE errors.
285 This is useful in detecting application design issues when return codes
286 are not consistently checked in the application code.
287 </p></li></ul>
288
289 <p>SQLite strives to keep error logger traffic low and only send messages
290 to the error logger when there really is something wrong. Applications
291 might further cull the error message traffic
292 by deliberately ignoring certain classes of error
293 messages that they do not care about. For example, an application that
294 makes frequent database schema changes might want to ignore all
295 SQLITE_SCHEMA errors.</p>
296
297 <h1 id="summary"><span>4. </span>Summary</h1>
298
299 <p>The use of the error logger callback is highly recommended.
300 The debugging information that the error logger provides has proven
301 very useful in tracking down obscure problems that occur with applications
302 after they get into the field. The error logger callback has also
303 proven useful in catching occasional errors that the application
304 misses because of inconsistent checking of API return codes.
305 Developers are encouraged to implement an error logger callback early
306 in the development cycle in order to spot unexpected behavior quickly,
307 and to leave the error logger callback turned on through deployment.
308 If the error logger never finds a problem, then no harm is done.
309 But failure to set up an appropriate error logger might compromise
310 diagnostic capabilities later on.</p>
311 <p align="center"><small><i>This page last modified on <a href="https://sqlite.org/docsrc/honeypot" id="mtimelink" data-href="https://sqlite.org/docsrc/finfo/pages/errlog.in?m=20f20663c0">2022-04-18 02:55:50</a> UTC </small></i></p>
312