logging.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  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 (unless
  46. a library defines its own logger).
  47. </para>
  48. <!-- TODO: later we will have a way to know names of all modules
  49. Right now you can only see what their names are if they are running
  50. (a simple 'help' without anything else in bindctl for instance).
  51. -->
  52. <para>
  53. If you want to specify logging for one specific library
  54. within the module, you set the name to
  55. <replaceable>module.library</replaceable>. For example, the
  56. logger used by the nameserver address store component
  57. has the full name of <quote>Dhcp4.dhcpsrv</quote>. If
  58. there is no entry in Logging for a particular library,
  59. it will use the configuration given for the module.
  60. </para>
  61. <para>
  62. To illustrate this, suppose you want the dhcpsrv library
  63. to log messages of severity DEBUG, and the rest of the
  64. Dhcp4 code to log messages of severity INFO. To achieve
  65. this you specify two loggers, one with the name
  66. <quote>Dhcp4</quote> and severity INFO, and one with
  67. the name <quote>Dhcp4.dhcpsrv</quote> with severity
  68. DEBUG. As there are no entries for other libraries,
  69. they will use the configuration for the module
  70. (<quote>Dhcp4</quote>), so giving the desired behavior.
  71. </para>
  72. <para>
  73. One special case is that of a module name of <quote>*</quote>
  74. (asterisks), which is interpreted as <emphasis>any</emphasis>
  75. module. You can set global logging options by using this,
  76. including setting the logging configuration for a library
  77. that is used by multiple modules (e.g. <quote>*.config</quote>
  78. specifies the configuration library code in whatever
  79. module is using it).
  80. </para>
  81. <para>
  82. If there are multiple logger specifications in the
  83. configuration that might match a particular logger, the
  84. specification with the more specific logger name takes
  85. precedence. For example, if there are entries for
  86. both <quote>*</quote> and <quote>Dhcp4</quote>, the
  87. Dhcp4 module &mdash; and all libraries it uses &mdash;
  88. will log messages according to the configuration in the
  89. second entry (<quote>Dhcp4</quote>). All other modules
  90. will use the configuration of the first entry
  91. (<quote>*</quote>).
  92. </para>
  93. <para>
  94. One final note about the naming. When specifying the
  95. module name within a logger, use the name of the binary file,
  96. e.g. <quote>kea-dhcp4</quote> for the DHCPv4 module,
  97. <quote>kea-dhcp6</quote> for the DHCPv6 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>DHCPv4</quote> logger will appear in the output
  103. with a logger name of <quote>kea-dhcp4</quote>).
  104. </para>
  105. <para>
  106. Currently defined loggers are:
  107. </para>
  108. <itemizedlist>
  109. <listitem>
  110. <simpara>kea-dhcp4.dhcp4</simpara>
  111. </listitem>
  112. <listitem>
  113. <simpara>kea-dhcp6.dhcp6</simpara>
  114. </listitem>
  115. <listitem>
  116. <simpara>kea-dhcp-ddns.dhcpddns</simpara>
  117. </listitem>
  118. <listitem>
  119. <simpara>kea-dhcp4.dhcpsrv</simpara>
  120. </listitem>
  121. <listitem>
  122. <simpara>kea-dhcp6.dhcpsrv</simpara>
  123. </listitem>
  124. </itemizedlist>
  125. <para>Additional loggers may be defined in the future.</para>
  126. </section>
  127. <section>
  128. <title>severity (string)</title>
  129. <para>
  130. This specifies the category of messages logged.
  131. Each message is logged with an associated severity which
  132. may be one of the following (in descending order of
  133. severity):
  134. </para>
  135. <itemizedlist>
  136. <listitem>
  137. <simpara> FATAL </simpara>
  138. </listitem>
  139. <listitem>
  140. <simpara> ERROR </simpara>
  141. </listitem>
  142. <listitem>
  143. <simpara> WARN </simpara>
  144. </listitem>
  145. <listitem>
  146. <simpara> INFO </simpara>
  147. </listitem>
  148. <listitem>
  149. <simpara> DEBUG </simpara>
  150. </listitem>
  151. </itemizedlist>
  152. <para>
  153. When the severity of a logger is set to one of these
  154. values, it will only log messages of that severity, and
  155. the severities above it. The severity may also be set to
  156. NONE, in which case all messages from that logger are
  157. inhibited.
  158. <!-- TODO: worded wrong? If I set to INFO, why would it show DEBUG which is literally below in that list? -->
  159. </para>
  160. </section>
  161. <section>
  162. <title>output_options (list)</title>
  163. <para>
  164. Each logger can have zero or more
  165. <option>output_options</option>. These specify where log
  166. messages are sent to. These are explained in detail below.
  167. </para>
  168. <para>
  169. The other options for a logger are:
  170. </para>
  171. </section>
  172. <section>
  173. <title>debuglevel (integer)</title>
  174. <para>
  175. When a logger's severity is set to DEBUG, this value
  176. specifies what debug messages should be printed. It ranges
  177. from 0 (least verbose) to 99 (most verbose).
  178. </para>
  179. <!-- TODO: complete this sentence:
  180. The general classification of debug message types is
  181. TODO; there's a ticket to determine these levels, see #1074
  182. -->
  183. <para>
  184. If severity for the logger is not DEBUG, this value is ignored.
  185. </para>
  186. </section>
  187. <section>
  188. <title>additive (true or false)</title>
  189. <para>
  190. If this is true, the <option>output_options</option> from
  191. the parent will be used. For example, if there are two
  192. loggers configured; <quote>Dhcp4</quote> and
  193. <quote>Dhcp4.dhcpsrv</quote>, and <option>additive</option>
  194. is true in the second, it will write the log messages
  195. not only to the destinations specified for
  196. <quote>Dhcp4.dhcpsrv</quote>, but also to the destinations
  197. as specified in the <option>output_options</option> in
  198. the logger named <quote>Dhcp4</quote>.
  199. </para>
  200. </section>
  201. </section>
  202. <section>
  203. <title>Output Options</title>
  204. <para>
  205. The main settings for an output option are the
  206. <option>destination</option> and a value called
  207. <option>output</option>, the meaning of which depends on
  208. the destination that is set.
  209. </para>
  210. <section>
  211. <title>destination (string)</title>
  212. <para>
  213. The destination is the type of output. It can be one of:
  214. </para>
  215. <itemizedlist>
  216. <listitem>
  217. <simpara> console </simpara>
  218. </listitem>
  219. <listitem>
  220. <simpara> file </simpara>
  221. </listitem>
  222. <listitem>
  223. <simpara> syslog </simpara>
  224. </listitem>
  225. </itemizedlist>
  226. </section>
  227. <section>
  228. <title>output (string)</title>
  229. <para>
  230. This value determines the type of output. There are several
  231. special values allowed here: <command>stdout</command> (messages
  232. are printed on standard output), <command>stderr</command>
  233. (messages are printed on stderr), <command>syslog</command> (messages
  234. are logged to syslog using default name, <command>syslog:name</command>
  235. (messages are logged to syslog using specified name). Any other
  236. value is interpreted as a filename that the logs should be written to.
  237. </para>
  238. <para>
  239. The other options for <option>output_options</option> are:
  240. </para>
  241. <!-- configuration of flush is not supported yet.
  242. <section>
  243. <title>flush (true of false)</title>
  244. <para>
  245. Flush buffers after each log message. Doing this will
  246. reduce performance but will ensure that if the program
  247. terminates abnormally, all messages up to the point of
  248. termination are output.
  249. </para>
  250. </section> -->
  251. <section>
  252. <title>maxsize (integer)</title>
  253. <para>
  254. Only relevant when destination is file, this is maximum
  255. file size of output files in bytes. When the maximum
  256. size is reached, the file is renamed and a new file opened.
  257. (For example, a ".1" is appended to the name &mdash;
  258. if a ".1" file exists, it is renamed ".2",
  259. etc.)
  260. </para>
  261. <para>
  262. If this is 0, no maximum file size is used.
  263. </para>
  264. <note>
  265. <simpara>
  266. Due to a limitation of the underlying logging library
  267. (log4cplus), rolling over the log files (from ".1" to
  268. ".2", etc) may show odd results: There can be
  269. multiple small files at the timing of roll over. This
  270. can happen when multiple processes try to roll
  271. over the files simultaneously.
  272. Version 1.1.0 of log4cplus solved this problem, so if
  273. this or higher version of log4cplus is used to build
  274. Kea, it shouldn't happen. Even for older versions
  275. it is normally expected to happen rarely unless the log
  276. messages are produced very frequently by multiple
  277. different processes.
  278. </simpara>
  279. </note>
  280. </section>
  281. <section>
  282. <title>maxver (integer)</title>
  283. <para>
  284. Maximum number of old log files to keep around when
  285. rolling the output file. Only relevant when
  286. <option>output</option> is <quote>file</quote>.
  287. </para>
  288. </section>
  289. </section>
  290. </section>
  291. <section>
  292. <title>Example Logger configurations</title>
  293. <para>
  294. In this example we want to set the global logging to
  295. write to the console using standard output.
  296. </para>
  297. <screen><userinput>
  298. "Logging": {
  299. "loggers": [
  300. {
  301. "name": "kea-dhcp4",
  302. "output_options": [
  303. {
  304. "output": "stdout"
  305. }
  306. ],
  307. "severity": "WARN"
  308. }
  309. ]
  310. }
  311. </userinput>
  312. </screen>
  313. <para>In this second example, we want to store debug log messages
  314. in a file that is at most 2MB and keep up to 8 copies of old logfiles.
  315. Once the logfile grows to 2MB, it will be renamed and a new file
  316. file be created.</para>
  317. <screen><userinput>
  318. "Logging": {
  319. "loggers": [
  320. {
  321. "name": "kea-dhcp6",
  322. "output_options": [
  323. {
  324. "output": "/var/log/kea-debug.log",
  325. "maxver": 8,
  326. "maxsize": 204800,
  327. "destination": "file"
  328. }
  329. ],
  330. "severity": "DEBUG",
  331. "debuglevel": 99
  332. }
  333. ]
  334. }</userinput></screen>
  335. </section>
  336. </section>
  337. <section>
  338. <title>Logging Message Format</title>
  339. <para>
  340. Each message written to the configured logging
  341. destinations comprises a number of components that identify
  342. the origin of the message and, if the message indicates
  343. a problem, information about the problem that may be
  344. useful in fixing it.
  345. </para>
  346. <para>
  347. Consider the message below logged to a file:
  348. <screen>2014-04-11 12:58:01.005 INFO [kea-dhcp4.dhcpsrv/27456]
  349. DHCPSRV_MEMFILE_DB opening memory file lease database: type=memfile universe=4</screen>
  350. </para>
  351. <para>
  352. Note: the layout of messages written to the system logging
  353. file (syslog) may be slightly different. This message has
  354. been split across two lines here for display reasons; in the
  355. logging file, it will appear on one line.
  356. </para>
  357. <para>
  358. The log message comprises a number of components:
  359. <variablelist>
  360. <varlistentry>
  361. <term>2014-04-11 12:58:01.005</term>
  362. <!-- TODO: timestamp repeated even if using syslog? -->
  363. <listitem><para>
  364. The date and time at which the message was generated.
  365. </para></listitem>
  366. </varlistentry>
  367. <varlistentry>
  368. <term>INFO</term>
  369. <listitem><para>
  370. The severity of the message.
  371. </para></listitem>
  372. </varlistentry>
  373. <varlistentry>
  374. <term>[kea-dhcp4.dhcpsrv/27456]</term>
  375. <listitem><para>
  376. The source of the message. This comprises two components:
  377. the Kea process generating the message (in this
  378. case, <command>kea-dhcp4</command>) and the module
  379. within the program from which the message originated
  380. (which is the name of the common library used by DHCP server
  381. implementations).
  382. </para></listitem>
  383. </varlistentry>
  384. <varlistentry>
  385. <term>DHCPSRV_MEMFILE_DB</term>
  386. <listitem><para>
  387. The message identification. Every message in Kea
  388. has a unique identification, which can be used as an
  389. index into the <ulink
  390. url="kea-messages.html"><citetitle>Kea Messages
  391. Manual</citetitle></ulink> (<ulink
  392. url="http://kea.isc.org/docs/kea-messages.html"
  393. />) from which more information can be obtained.
  394. </para></listitem>
  395. </varlistentry>
  396. <varlistentry>
  397. <term>opening memory file lease database: type=memfile universe=4</term>
  398. <listitem><para>
  399. A brief description.
  400. Within this text, information relating to the condition
  401. that caused the message to be logged will be included.
  402. In this example, the information is logged that the in-memory
  403. lease database backend will be used to store DHCP leases.
  404. </para></listitem>
  405. </varlistentry>
  406. </variablelist>
  407. </para>
  408. </section>
  409. </chapter>