logging.xml 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  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 JSON configuration, 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. This value determines the type of output. There are several
  210. special values allowed here: <command>stdout</command> (messages
  211. are printed on standard output), <command>stderr</command>
  212. (messages are printed on stderr), <command>syslog</command> (messages
  213. are logged to syslog using default name, <command>syslog:name</command>
  214. (messages are logged to syslog using specified name). Any other
  215. value is interpreted as a filename that the logs should be written to.
  216. </para>
  217. <para>
  218. The other options for <option>output_options</option> are:
  219. </para>
  220. <!-- configuration of flush is not supported yet.
  221. <section>
  222. <title>flush (true of false)</title>
  223. <para>
  224. Flush buffers after each log message. Doing this will
  225. reduce performance but will ensure that if the program
  226. terminates abnormally, all messages up to the point of
  227. termination are output.
  228. </para>
  229. </section> -->
  230. <section>
  231. <title>maxsize (integer)</title>
  232. <para>
  233. Only relevant when destination is file, this is maximum
  234. file size of output files in bytes. When the maximum
  235. size is reached, the file is renamed and a new file opened.
  236. (For example, a ".1" is appended to the name &mdash;
  237. if a ".1" file exists, it is renamed ".2",
  238. etc.)
  239. </para>
  240. <para>
  241. If this is 0, no maximum file size is used.
  242. </para>
  243. <note>
  244. <simpara>
  245. Due to a limitation of the underlying logging library
  246. (log4cplus), rolling over the log files (from ".1" to
  247. ".2", etc) may show odd results: There can be
  248. multiple small files at the timing of roll over. This
  249. can happen when multiple processes try to roll
  250. over the files simultaneously.
  251. Version 1.1.0 of log4cplus solved this problem, so if
  252. this or higher version of log4cplus is used to build
  253. Kea, it shouldn't happen. Even for older versions
  254. it is normally expected to happen rarely unless the log
  255. messages are produced very frequently by multiple
  256. different processes.
  257. </simpara>
  258. </note>
  259. </section>
  260. <section>
  261. <title>maxver (integer)</title>
  262. <para>
  263. Maximum number of old log files to keep around when
  264. rolling the output file. Only relevant when
  265. <option>output</option> is <quote>file</quote>.
  266. </para>
  267. </section>
  268. </section>
  269. </section>
  270. <section>
  271. <title>Example Logger configurations</title>
  272. <para>
  273. In this example we want to set the global logging to
  274. write to the console using standard output.
  275. </para>
  276. <screen><userinput>
  277. "Logging": {
  278. "loggers": [
  279. {
  280. "name": "kea",
  281. "output_options": [
  282. {
  283. "output": "stdout"
  284. }
  285. ],
  286. "severity": "WARN"
  287. }
  288. ]
  289. }
  290. </userinput>
  291. </screen>
  292. <para>In this second example, we want to store debug log messages
  293. in a file that is at most 2MB and keep up to 8 copies of old logfiles.
  294. Once the logfile grows to 2MB, it will be renamed and a new file
  295. file be created.</para>
  296. <screen><userinput>
  297. "Logging": {
  298. "loggers": [
  299. {
  300. "name": "kea",
  301. "output_options": [
  302. {
  303. "output": "/var/log/kea-debug.log",
  304. "maxver": 8,
  305. "maxsize": 204800,
  306. "destination": "file"
  307. }
  308. ],
  309. "severity": "DEBUG",
  310. "debuglevel": 99
  311. }
  312. ]
  313. }</userinput></screen>
  314. </section>
  315. </section>
  316. <section>
  317. <title>Logging Message Format</title>
  318. <para>
  319. Each message written to the configured logging
  320. destinations comprises a number of components that identify
  321. the origin of the message and, if the message indicates
  322. a problem, information about the problem that may be
  323. useful in fixing it.
  324. </para>
  325. <para>
  326. Consider the message below logged to a file:
  327. <screen>2014-04-11 12:58:01.005 INFO [kea-dhcp4.dhcpsrv/27456]
  328. DHCPSRV_MEMFILE_DB opening memory file lease database: type=memfile universe=4</screen>
  329. </para>
  330. <para>
  331. Note: the layout of messages written to the system logging
  332. file (syslog) may be slightly different. This message has
  333. been split across two lines here for display reasons; in the
  334. logging file, it will appear on one line.)
  335. </para>
  336. <para>
  337. The log message comprises a number of components:
  338. <variablelist>
  339. <varlistentry>
  340. <term>2014-04-11 12:58:01.005</term>
  341. <!-- TODO: timestamp repeated even if using syslog? -->
  342. <listitem><para>
  343. The date and time at which the message was generated.
  344. </para></listitem>
  345. </varlistentry>
  346. <varlistentry>
  347. <term>INFO</term>
  348. <listitem><para>
  349. The severity of the message.
  350. </para></listitem>
  351. </varlistentry>
  352. <varlistentry>
  353. <term>[kea-dhcp4.dhcpsrv/27456]</term>
  354. <listitem><para>
  355. The source of the message. This comprises two components:
  356. the BIND 10 process generating the message (in this
  357. case, <command>kea-dhcp4</command>) and the module
  358. within the program from which the message originated
  359. (which is the name of the common library used by DHCP server
  360. implementations).
  361. </para></listitem>
  362. </varlistentry>
  363. <varlistentry>
  364. <term>DHCPSRV_MEMFILE_DB</term>
  365. <listitem><para>
  366. The message identification. Every message in Kea
  367. has a unique identification, which can be used as an
  368. index into the <ulink
  369. url="kea-messages.html"><citetitle>Kea Messages
  370. Manual</citetitle></ulink> (<ulink
  371. url="http://kea.isc.org/docs/kea-messages.html"
  372. />) from which more information can be obtained.
  373. </para></listitem>
  374. </varlistentry>
  375. <varlistentry>
  376. <term>opening memory file lease database: type=memfile universe=4</term>
  377. <listitem><para>
  378. A brief description.
  379. Within this text, information relating to the condition
  380. that caused the message to be logged will be included.
  381. In this example, the information is logged that the in-memory
  382. lease database backend will be used to store DHCP leases.
  383. </para></listitem>
  384. </varlistentry>
  385. </variablelist>
  386. </para>
  387. </section>
  388. </chapter>