logging.xml 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
  4. <!ENTITY mdash "&#x2014;" >
  5. ]>
  6. <chapter id="logging">
  7. <title>Logging</title>
  8. <section>
  9. <title>Logging configuration</title>
  10. <para>
  11. The logging system in Kea is configured through the
  12. Logging module. All modules will look at the
  13. configuration in Logging to see what should be logged and
  14. to where.
  15. <!-- TODO: what is context of Logging module for readers of this guide? -->
  16. </para>
  17. <section>
  18. <title>Loggers</title>
  19. <para>
  20. Within Kea, a message is logged through a component
  21. called a "logger". Different parts of log messages
  22. through different loggers, and each logger can be configured
  23. independently of one another.
  24. </para>
  25. <para>
  26. In the Logging module, you can specify the configuration
  27. for zero or more loggers; any that are not specified will
  28. take appropriate default values.
  29. </para>
  30. <para>
  31. The three most important elements of a logger configuration
  32. are the <option>name</option> (the component that is
  33. generating the messages), the <option>severity</option>
  34. (what to log), and the <option>output_options</option>
  35. (where to log).
  36. </para>
  37. <section>
  38. <title>name (string)</title>
  39. <para>
  40. Each logger in the system has a name, the name being that
  41. of the component using it to log messages. For instance,
  42. if you want to configure logging for the Dhcp4 module,
  43. you add an entry for a logger named <quote>Dhcp4</quote>. This
  44. configuration will then be used by the loggers in the
  45. Dhcp4 module, and all the libraries used by it.
  46. </para>
  47. <!-- TODO: later we will have a way to know names of all modules
  48. Right now you can only see what their names are if they are running
  49. (a simple 'help' without anything else in bindctl for instance).
  50. -->
  51. <para>
  52. If you want to specify logging for one specific library
  53. within the module, you set the name to
  54. <replaceable>module.library</replaceable>. For example, the
  55. logger used by the nameserver address store component
  56. has the full name of <quote>Dhcp4.dhcpsrv</quote>. If
  57. there is no entry in Logging for a particular library,
  58. it will use the configuration given for the module.
  59. </para>
  60. <para>
  61. To illustrate this, suppose you want the dhcpsrv library
  62. to log messages of severity DEBUG, and the rest of the
  63. Dhcp4 code to log messages of severity INFO. To achieve
  64. this you specify two loggers, one with the name
  65. <quote>Dhcp4</quote> and severity INFO, and one with
  66. the name <quote>Dhcp4.dhcpsrv</quote> with severity
  67. DEBUG. As there are no entries for other libraries,
  68. they will use the configuration for the module
  69. (<quote>Dhcp4</quote>), so giving the desired behavior.
  70. </para>
  71. <para>
  72. One special case is that of a module name of <quote>*</quote>
  73. (asterisks), which is interpreted as <emphasis>any</emphasis>
  74. module. You can set global logging options by using this,
  75. including setting the logging configuration for a library
  76. that is used by multiple modules (e.g. <quote>*.config</quote>
  77. specifies the configuration library code in whatever
  78. module is using it).
  79. </para>
  80. <para>
  81. If there are multiple logger specifications in the
  82. configuration that might match a particular logger, the
  83. specification with the more specific logger name takes
  84. precedence. For example, if there are entries for
  85. both <quote>*</quote> and <quote>Dhcp4</quote>, the
  86. Dhcp4 module &mdash; and all libraries it uses &mdash;
  87. will log messages according to the configuration in the
  88. second entry (<quote>Dhcp4</quote>). All other modules
  89. will use the configuration of the first entry
  90. (<quote>*</quote>).
  91. </para>
  92. <para>
  93. One final note about the naming. When specifying the
  94. module name within a logger, use the name of the module
  95. as specified in <command>bindctl</command>, e.g.
  96. <quote>Dhcp4</quote> for the Dhcp4 module,
  97. <quote>Dhcp6</quote> for the Dhcp6 module, etc. When
  98. the message is logged, the message will include the name
  99. of the logger generating the message, but with the module
  100. name replaced by the name of the process implementing
  101. the module (so for example, a message generated by the
  102. <quote>Dhcp4</quote> logger will appear in the output
  103. with a logger name of <quote>kea-dhcp4</quote>).
  104. </para>
  105. </section>
  106. <section>
  107. <title>severity (string)</title>
  108. <para>
  109. This specifies the category of messages logged.
  110. Each message is logged with an associated severity which
  111. may be one of the following (in descending order of
  112. severity):
  113. </para>
  114. <itemizedlist>
  115. <listitem>
  116. <simpara> FATAL </simpara>
  117. </listitem>
  118. <listitem>
  119. <simpara> ERROR </simpara>
  120. </listitem>
  121. <listitem>
  122. <simpara> WARN </simpara>
  123. </listitem>
  124. <listitem>
  125. <simpara> INFO </simpara>
  126. </listitem>
  127. <listitem>
  128. <simpara> DEBUG </simpara>
  129. </listitem>
  130. </itemizedlist>
  131. <para>
  132. When the severity of a logger is set to one of these
  133. values, it will only log messages of that severity, and
  134. the severities above it. The severity may also be set to
  135. NONE, in which case all messages from that logger are
  136. inhibited.
  137. <!-- TODO: worded wrong? If I set to INFO, why would it show DEBUG which is literally below in that list? -->
  138. </para>
  139. </section>
  140. <section>
  141. <title>output_options (list)</title>
  142. <para>
  143. Each logger can have zero or more
  144. <option>output_options</option>. These specify where log
  145. messages are sent to. These are explained in detail below.
  146. </para>
  147. <para>
  148. The other options for a logger are:
  149. </para>
  150. </section>
  151. <section>
  152. <title>debuglevel (integer)</title>
  153. <para>
  154. When a logger's severity is set to DEBUG, this value
  155. specifies what debug messages should be printed. It ranges
  156. from 0 (least verbose) to 99 (most verbose).
  157. </para>
  158. <!-- TODO: complete this sentence:
  159. The general classification of debug message types is
  160. TODO; there's a ticket to determine these levels, see #1074
  161. -->
  162. <para>
  163. If severity for the logger is not DEBUG, this value is ignored.
  164. </para>
  165. </section>
  166. <section>
  167. <title>additive (true or false)</title>
  168. <para>
  169. If this is true, the <option>output_options</option> from
  170. the parent will be used. For example, if there are two
  171. loggers configured; <quote>Dhcp4</quote> and
  172. <quote>Dhcp4.dhcpsrv</quote>, and <option>additive</option>
  173. is true in the second, it will write the log messages
  174. not only to the destinations specified for
  175. <quote>Dhcp4.dhcpsrv</quote>, but also to the destinations
  176. as specified in the <option>output_options</option> in
  177. the logger named <quote>Dhcp4</quote>.
  178. </para>
  179. </section>
  180. </section>
  181. <section>
  182. <title>Output Options</title>
  183. <para>
  184. The main settings for an output option are the
  185. <option>destination</option> and a value called
  186. <option>output</option>, the meaning of which depends on
  187. the destination that is set.
  188. </para>
  189. <section>
  190. <title>destination (string)</title>
  191. <para>
  192. The destination is the type of output. It can be one of:
  193. </para>
  194. <itemizedlist>
  195. <listitem>
  196. <simpara> console </simpara>
  197. </listitem>
  198. <listitem>
  199. <simpara> file </simpara>
  200. </listitem>
  201. <listitem>
  202. <simpara> syslog </simpara>
  203. </listitem>
  204. </itemizedlist>
  205. </section>
  206. <section>
  207. <title>output (string)</title>
  208. <para>
  209. Depending on what is set as the output destination, this
  210. value is interpreted as follows:
  211. </para>
  212. <variablelist>
  213. <varlistentry>
  214. <term><option>destination</option> is <quote>console</quote></term>
  215. <listitem>
  216. <para>
  217. The value of output must be one of <quote>stdout</quote>
  218. (messages printed to standard output) or
  219. <quote>stderr</quote> (messages printed to standard
  220. error).
  221. </para>
  222. <para>
  223. Note: if output is set to <quote>stderr</quote> and a lot of
  224. messages are produced in a short time (e.g. if the logging
  225. level is set to DEBUG), you may occasionally see some messages
  226. jumbled up together. This is due to a combination of the way
  227. that messages are written to the screen and the unbuffered
  228. nature of the standard error stream. If this occurs, it is
  229. recommended that output be set to <quote>stdout</quote>.
  230. </para>
  231. </listitem>
  232. </varlistentry>
  233. <varlistentry>
  234. <term><option>destination</option> is <quote>file</quote></term>
  235. <listitem>
  236. <para>
  237. The value of output is interpreted as a file name;
  238. log messages will be appended to this file.
  239. </para>
  240. </listitem>
  241. </varlistentry>
  242. <varlistentry>
  243. <term><option>destination</option> is <quote>syslog</quote></term>
  244. <listitem>
  245. <para>
  246. The value of output is interpreted as the
  247. <command>syslog</command> facility (e.g.
  248. <emphasis>local0</emphasis>) that should be used
  249. for log messages.
  250. </para>
  251. </listitem>
  252. </varlistentry>
  253. </variablelist>
  254. <para>
  255. The other options for <option>output_options</option> are:
  256. </para>
  257. <section>
  258. <title>flush (true of false)</title>
  259. <para>
  260. Flush buffers after each log message. Doing this will
  261. reduce performance but will ensure that if the program
  262. terminates abnormally, all messages up to the point of
  263. termination are output.
  264. </para>
  265. </section>
  266. <section>
  267. <title>maxsize (integer)</title>
  268. <para>
  269. Only relevant when destination is file, this is maximum
  270. file size of output files in bytes. When the maximum
  271. size is reached, the file is renamed and a new file opened.
  272. (For example, a ".1" is appended to the name &mdash;
  273. if a ".1" file exists, it is renamed ".2",
  274. etc.)
  275. </para>
  276. <para>
  277. If this is 0, no maximum file size is used.
  278. </para>
  279. <note>
  280. <simpara>
  281. Due to a limitation of the underlying logging library
  282. (log4cplus), rolling over the log files (from ".1" to
  283. ".2", etc) may show odd results: There can be
  284. multiple small files at the timing of roll over. This
  285. can happen when multiple processes try to roll
  286. over the files simultaneously.
  287. Version 1.1.0 of log4cplus solved this problem, so if
  288. this or higher version of log4cplus is used to build
  289. Kea, it shouldn't happen. Even for older versions
  290. it is normally expected to happen rarely unless the log
  291. messages are produced very frequently by multiple
  292. different processes.
  293. </simpara>
  294. </note>
  295. </section>
  296. <section>
  297. <title>maxver (integer)</title>
  298. <para>
  299. Maximum number of old log files to keep around when
  300. rolling the output file. Only relevant when
  301. <option>destination</option> is <quote>file</quote>.
  302. </para>
  303. </section>
  304. </section>
  305. </section>
  306. <section>
  307. <title>Example session</title>
  308. <para>
  309. In this example we want to set the global logging to
  310. write to the file <filename>/var/log/my_bind10.log</filename>,
  311. at severity WARN. We want the authoritative server to
  312. log at DEBUG with debuglevel 40, to a different file
  313. (<filename>/tmp/debug_messages</filename>).
  314. </para>
  315. <para>
  316. Start <command>bindctl</command>.
  317. </para>
  318. <para>
  319. <screen>["login success "]
  320. &gt; <userinput>config show Logging</userinput>
  321. Logging/loggers [] list
  322. </screen>
  323. </para>
  324. <para>
  325. By default, no specific loggers are configured, in which
  326. case the severity defaults to INFO and the output is
  327. written to stderr.
  328. </para>
  329. <para>
  330. Let's first add a default logger:
  331. </para>
  332. <!-- TODO: adding the empty loggers makes no sense -->
  333. <para>
  334. <screen>&gt; <userinput>config add Logging/loggers</userinput>
  335. &gt; <userinput>config show Logging</userinput>
  336. Logging/loggers/ list (modified)
  337. </screen>
  338. </para>
  339. <para>
  340. The loggers value line changed to indicate that it is no
  341. longer an empty list:
  342. </para>
  343. <para>
  344. <screen>&gt; <userinput>config show Logging/loggers</userinput>
  345. Logging/loggers[0]/name "" string (default)
  346. Logging/loggers[0]/severity "INFO" string (default)
  347. Logging/loggers[0]/debuglevel 0 integer (default)
  348. Logging/loggers[0]/additive false boolean (default)
  349. Logging/loggers[0]/output_options [] list (default)
  350. </screen>
  351. </para>
  352. <para>
  353. The name is mandatory, so we must set it. We will also
  354. change the severity as well. Let's start with the global
  355. logger.
  356. </para>
  357. <para>
  358. <screen>&gt; <userinput>config set Logging/loggers[0]/name *</userinput>
  359. &gt; <userinput>config set Logging/loggers[0]/severity WARN</userinput>
  360. &gt; <userinput>config show Logging/loggers</userinput>
  361. Logging/loggers[0]/name "*" string (modified)
  362. Logging/loggers[0]/severity "WARN" string (modified)
  363. Logging/loggers[0]/debuglevel 0 integer (default)
  364. Logging/loggers[0]/additive false boolean (default)
  365. Logging/loggers[0]/output_options [] list (default)
  366. </screen>
  367. </para>
  368. <para>
  369. Of course, we need to specify where we want the log
  370. messages to go, so we add an entry for an output option.
  371. </para>
  372. <para>
  373. <screen>&gt; <userinput> config add Logging/loggers[0]/output_options</userinput>
  374. &gt; <userinput> config show Logging/loggers[0]/output_options</userinput>
  375. Logging/loggers[0]/output_options[0]/destination "console" string (default)
  376. Logging/loggers[0]/output_options[0]/output "stdout" string (default)
  377. Logging/loggers[0]/output_options[0]/flush false boolean (default)
  378. Logging/loggers[0]/output_options[0]/maxsize 0 integer (default)
  379. Logging/loggers[0]/output_options[0]/maxver 0 integer (default)
  380. </screen>
  381. </para>
  382. <para>
  383. These aren't the values we are looking for.
  384. </para>
  385. <para>
  386. <screen>&gt; <userinput> config set Logging/loggers[0]/output_options[0]/destination file</userinput>
  387. &gt; <userinput> config set Logging/loggers[0]/output_options[0]/output /var/log/kea.log</userinput>
  388. &gt; <userinput> config set Logging/loggers[0]/output_options[0]/maxsize 204800</userinput>
  389. &gt; <userinput> config set Logging/loggers[0]/output_options[0]/maxver 8</userinput>
  390. </screen>
  391. </para>
  392. <para>
  393. Which would make the entire configuration for this logger
  394. look like:
  395. </para>
  396. <para>
  397. <screen>&gt; <userinput> config show all Logging/loggers</userinput>
  398. Logging/loggers[0]/name "*" string (modified)
  399. Logging/loggers[0]/severity "WARN" string (modified)
  400. Logging/loggers[0]/debuglevel 0 integer (default)
  401. Logging/loggers[0]/additive false boolean (default)
  402. Logging/loggers[0]/output_options[0]/destination "file" string (modified)
  403. Logging/loggers[0]/output_options[0]/output "/var/log/kea.log" string (modified)
  404. Logging/loggers[0]/output_options[0]/flush false boolean (default)
  405. Logging/loggers[0]/output_options[0]/maxsize 204800 integer (modified)
  406. Logging/loggers[0]/output_options[0]/maxver 8 integer (modified)
  407. </screen>
  408. </para>
  409. <para>
  410. That looks OK, so let's commit it before we add the
  411. configuration for the authoritative server's logger.
  412. </para>
  413. <para>
  414. <screen>&gt; <userinput> config commit</userinput></screen>
  415. </para>
  416. <para>
  417. Now that we have set it, and checked each value along
  418. the way, adding a second entry is quite similar.
  419. </para>
  420. <para>
  421. <screen>&gt; <userinput> config add Logging/loggers</userinput>
  422. &gt; <userinput> config set Logging/loggers[1]/name Dhcp4</userinput>
  423. &gt; <userinput> config set Logging/loggers[1]/severity DEBUG</userinput>
  424. &gt; <userinput> config set Logging/loggers[1]/debuglevel 40</userinput>
  425. &gt; <userinput> config add Logging/loggers[1]/output_options</userinput>
  426. &gt; <userinput> config set Logging/loggers[1]/output_options[0]/destination file</userinput>
  427. &gt; <userinput> config set Logging/loggers[1]/output_options[0]/output /tmp/dhcp4_debug.log</userinput>
  428. &gt; <userinput> config commit</userinput>
  429. </screen>
  430. </para>
  431. <para>
  432. And that's it. Once we have found whatever it was we
  433. needed the debug messages for, we can simply remove the
  434. second logger to let the DHCP server use the
  435. same settings as the rest.
  436. </para>
  437. <para>
  438. <screen>&gt; <userinput> config remove Logging/loggers[1]</userinput>
  439. &gt; <userinput> config commit</userinput>
  440. </screen>
  441. </para>
  442. <para>
  443. And every module will now be using the values from the
  444. logger named <quote>*</quote>.
  445. </para>
  446. </section>
  447. </section>
  448. <section>
  449. <title>Logging Message Format</title>
  450. <para>
  451. Each message written to the configured logging
  452. destinations comprises a number of components that identify
  453. the origin of the message and, if the message indicates
  454. a problem, information about the problem that may be
  455. useful in fixing it.
  456. </para>
  457. <para>
  458. Consider the message below logged to a file:
  459. <screen>2014-04-11 12:58:01.005 INFO [kea-dhcp4.dhcpsrv/27456]
  460. DHCPSRV_MEMFILE_DB opening memory file lease database: type=memfile universe=4</screen>
  461. </para>
  462. <para>
  463. Note: the layout of messages written to the system logging
  464. file (syslog) may be slightly different. This message has
  465. been split across two lines here for display reasons; in the
  466. logging file, it will appear on one line.)
  467. </para>
  468. <para>
  469. The log message comprises a number of components:
  470. <variablelist>
  471. <varlistentry>
  472. <term>2014-04-11 12:58:01.005</term>
  473. <!-- TODO: timestamp repeated even if using syslog? -->
  474. <listitem><para>
  475. The date and time at which the message was generated.
  476. </para></listitem>
  477. </varlistentry>
  478. <varlistentry>
  479. <term>INFO</term>
  480. <listitem><para>
  481. The severity of the message.
  482. </para></listitem>
  483. </varlistentry>
  484. <varlistentry>
  485. <term>[kea-dhcp4.dhcpsrv/27456]</term>
  486. <listitem><para>
  487. The source of the message. This comprises two components:
  488. the BIND 10 process generating the message (in this
  489. case, <command>kea-dhcp4</command>) and the module
  490. within the program from which the message originated
  491. (which is the name of the common library used by DHCP server
  492. implementations).
  493. </para></listitem>
  494. </varlistentry>
  495. <varlistentry>
  496. <term>DHCPSRV_MEMFILE_DB</term>
  497. <listitem><para>
  498. The message identification. Every message in Kea
  499. has a unique identification, which can be used as an
  500. index into the <ulink
  501. url="kea-messages.html"><citetitle>Kea Messages
  502. Manual</citetitle></ulink> (<ulink
  503. url="http://kea.isc.org/docs/kea-messages.html"
  504. />) from which more information can be obtained.
  505. </para></listitem>
  506. </varlistentry>
  507. <varlistentry>
  508. <term>opening memory file lease database: type=memfile universe=4</term>
  509. <listitem><para>
  510. A brief description.
  511. Within this text, information relating to the condition
  512. that caused the message to be logged will be included.
  513. In this example, the information is logged that the in-memory
  514. lease database backend will be used to store DHCP leases.
  515. </para></listitem>
  516. </varlistentry>
  517. </variablelist>
  518. </para>
  519. </section>
  520. </chapter>