logging.xml 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  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. <!-- Note: Please use the following terminology:
  7. - daemon - one process (e.g. kea-dhcp4)
  8. - component - one piece of code within a daemon (e.g. libdhcp or hooks)
  9. - server - currently equal to daemon, but the difference will be more
  10. prominent once we add client or relay support
  11. - logger - one instance of isc::log::Logger
  12. - structure - an element in config file (e.g. "Dhcp4")
  13. Do not use:
  14. - module => daemon
  15. -->
  16. <chapter id="logging">
  17. <title>Logging</title>
  18. <section>
  19. <title>Logging Configuration</title>
  20. <para>
  21. During its operation Kea may produce many messages. They differ in
  22. severity (some are more important than others) and source (some are
  23. produced by specific components, e.g. hooks). It is useful to understand
  24. which log messages are needed and which are not and configure your
  25. logging appropriately. For example, debug level messages can be safely
  26. ignored in a typical deployment. They are, however, very useful when
  27. debugging a problem.
  28. </para>
  29. <para>
  30. The logging system in Kea is configured through the
  31. <replaceable>Logging</replaceable> structure in your configuration
  32. file. All daemons (e.g. DHCPv4 and DHCPv6 servers) will use the
  33. configuration in the <replaceable>Logging</replaceable> structure to see
  34. what should be logged and to where. This allows for sharing identical
  35. logging configuration between daemons.
  36. </para>
  37. <section>
  38. <title>Loggers</title>
  39. <para>
  40. Within Kea, a message is logged through an entity
  41. called a "logger". Different parts of the code log messages
  42. through different loggers, and each logger can be configured
  43. independently of one another. For example there are different
  44. components that deal with hooks ("hooks" logger) and with
  45. DHCP engine ("dhcpsrv" logger).
  46. </para>
  47. <para>
  48. In the Logging structure in a configuration file you can
  49. specify the configuration for zero or more loggers. If there are
  50. no loggers specified, the code will use default values which
  51. cause Kea to log messages on at least INFO severity to standard
  52. output.
  53. <!-- @todo: add reference to section about controlling default
  54. behavior with env. variables, after #3591 is merged. -->
  55. </para>
  56. <para>
  57. The three most important elements of a logger configuration
  58. are the <option>name</option> (the component that is
  59. generating the messages), the <option>severity</option>
  60. (what to log), and the <option>output_options</option>
  61. (where to log).
  62. </para>
  63. <section>
  64. <title>name (string)</title>
  65. <para>
  66. Each logger in the system has a name, the name being that of the
  67. component binary file using it to log messages. For instance, if you
  68. want to configure logging for the DHCPv4 server, you add an entry
  69. for a logger named <quote>kea-dhcp4</quote>. This configuration will
  70. then be used by the loggers in the DHCPv4 server, and all the
  71. libraries used by it (unless a library defines its own logger and
  72. there is specific logger configuration that applies to that logger).
  73. </para>
  74. <para>
  75. If you want to specify logging for one specific library within a
  76. daemon, you set the name to
  77. <replaceable>daemon.library</replaceable>. For example, the logger
  78. used by the code from libdhcpsrv used in kea-dhcp4 binary has the
  79. full name of <quote>kea-dhcp4.dhcpsrv</quote>. If there is no entry
  80. in Logging for a particular library, it will use the configuration
  81. given for the whole daemon.
  82. </para>
  83. <para>
  84. To illustrate this, suppose you want the dhcpsrv library
  85. to log messages of severity DEBUG, and the rest of the
  86. DHCPv4 server code to log messages of severity INFO. To achieve
  87. this you specify two loggers, one with the name
  88. <quote>kea-dhcp4</quote> and severity INFO, and one with
  89. the name <quote>kea-dhcp4.dhcpsrv</quote> with severity
  90. DEBUG. As there are no entries for other libraries,
  91. they will use the configuration for the daemon
  92. (<quote>kea-dhcp4</quote>), so giving the desired behavior.
  93. </para>
  94. <!-- we don't support asterisk anymore.
  95. <para>
  96. One special case is that of a component name of <quote>*</quote>
  97. (asterisks), which is interpreted as <emphasis>any</emphasis>
  98. component. You can set global logging options by using this,
  99. including setting the logging configuration for a library
  100. that is used by multiple daemons (e.g. <quote>*.config</quote>
  101. specifies the configuration library code in whatever
  102. daemon is using it).
  103. </para> -->
  104. <para>
  105. If there are multiple logger specifications in the configuration
  106. that might match a particular logger, the specification with the
  107. more specific logger name takes precedence. For example, if there
  108. are entries for both <quote>kea-dhcp4</quote> and
  109. <quote>kea-dhcp4.dhcpsrv</quote>, the DHCPv4 server &mdash; and all
  110. libraries it uses that are not dhcpsrv &mdash; will log messages
  111. according to the configuration in the first entry
  112. (<quote>kea-dhcp4</quote>).
  113. </para>
  114. <para>
  115. One final note about the naming. When specifying the daemon name
  116. within a logger, use the name of the binary file,
  117. e.g. <quote>kea-dhcp4</quote> for the DHCPv4 server,
  118. <quote>kea-dhcp6</quote> for the DHCPv6 server, etc. When the
  119. message is logged, the message will include the name of the process
  120. (e.g. <quote>kea-dhcp4</quote>) followed by the specific component
  121. in that process, e.g. <quote>hooks</quote>. It is possible to
  122. specify either just the process name (<quote>kea-dhcp4</quote>, will
  123. apply to everything logged within that process) or process name
  124. followed by specific logger,
  125. e.g. <quote>kea-dhcp4.hooks</quote>. That will apply only to
  126. messages originating from that component.
  127. </para>
  128. <para>
  129. Currently defined loggers are:
  130. </para>
  131. <itemizedlist>
  132. <listitem>
  133. <simpara><command>kea-dhcp4</command> - this is the root logger for
  134. the DHCPv4 server. All components used by the DHCPv4 server inherit
  135. the settings from this logger if there is no specialized logger
  136. provided.</simpara>
  137. </listitem>
  138. <listitem>
  139. <simpara><command>kea-dhcp4.bad_packet</command> - this is the
  140. logger used by the DHCPv4 server deamon for logging inbound client
  141. packets that were dropped or to which the server responded with a
  142. NAK. The allows adminstrators to configure a separate log
  143. output that contains only packet drop and reject entries.</simpara>
  144. </listitem>
  145. <listitem>
  146. <simpara><command>kea-dhcp4.dhcp4</command> - this is the logger
  147. used solely by the DHCPv4 server deamon. This logger does not
  148. specify logging settings for libraries used by the deamon.</simpara>
  149. </listitem>
  150. <listitem>
  151. <simpara><command>kea-dhcp4.dhcpsrv</command> - this logger is used
  152. by the libdhcpsrv library. This covers mostly DHCP engine (the lease
  153. allocation and renewal process), database operations and
  154. configuration.</simpara>
  155. </listitem>
  156. <listitem>
  157. <simpara><command>kea-dhcp4.hooks</command> - this logger is used
  158. during DHCPv4 hooks operation, i.e. anything related to user
  159. libraries will be logged using this logger.</simpara>
  160. </listitem>
  161. <listitem>
  162. <simpara><command>kea-dhcp4.hosts</command> - this logger is used
  163. within the libdhcpsrv and it logs messages related to the management
  164. of the DHCPv4 host reservations, i.e. retrieval of the resevations
  165. and adding new reservations.</simpara>
  166. </listitem>
  167. <listitem>
  168. <simpara><command>kea-dhcp6</command> - this is the root logger for
  169. the DHCPv6 server. All components used by the DHCPv6 server inherit
  170. the settings from this logger if there is no specialized logger
  171. provided.</simpara>
  172. </listitem>
  173. <listitem>
  174. <simpara><command>kea-dhcp6.dhcp6</command> - this is the logger
  175. used solely by the DHCPv6 server deamon. This logger does not
  176. specify logging settings for libraries used by the daemon.</simpara>
  177. </listitem>
  178. <listitem>
  179. <simpara><command>kea-dhcp6.dhcpsrv</command> - this logger is used
  180. by the libdhcpsrv library. This covers mostly DHCP engine (the lease
  181. allocation and renewal process), database operations and
  182. configuration.</simpara>
  183. </listitem>
  184. <listitem>
  185. <simpara><command>kea-dhcp6.hooks</command> - this logger is used
  186. during DHCPv6 hooks operation, i.e. anything related to user
  187. libraries will be logged using this logger.</simpara>
  188. </listitem>
  189. <listitem>
  190. <simpara><command>kea-dhcp6.hosts</command> - this logger is used
  191. within the libdhcpsrv and it logs messages related to the management
  192. of the DHCPv6 host reservations, i.e. retrieval of the resevations
  193. and adding new reservations.</simpara>
  194. </listitem>
  195. <listitem>
  196. <simpara><command>kea-dhcp-ddns</command> - this is the root logger for
  197. the kea-dhcp-ddns deamon. All components used by this deamon inherit
  198. the settings from this logger if there is no specialized logger
  199. provided.</simpara>
  200. </listitem>
  201. <listitem>
  202. <simpara><command>kea-dhcp-ddns.dhcpddns</command> - this is the logger
  203. used solely by the kea-dhcp-ddns deamon. This logger does not
  204. specify logging settings for libraries used by the deamon.</simpara>
  205. </listitem>
  206. </itemizedlist>
  207. <para>Additional loggers may be defined in the future. The easiest
  208. way to find out the logger name is to configure all logging to go
  209. to a single destination and look for specific logger names. See
  210. <xref linkend="logging-message-format"/> for details.</para>
  211. </section>
  212. <section>
  213. <title>severity (string)</title>
  214. <para>
  215. This specifies the category of messages logged.
  216. Each message is logged with an associated severity which
  217. may be one of the following (in descending order of
  218. severity):
  219. </para>
  220. <itemizedlist>
  221. <listitem>
  222. <simpara> FATAL </simpara>
  223. </listitem>
  224. <listitem>
  225. <simpara> ERROR </simpara>
  226. </listitem>
  227. <listitem>
  228. <simpara> WARN </simpara>
  229. </listitem>
  230. <listitem>
  231. <simpara> INFO </simpara>
  232. </listitem>
  233. <listitem>
  234. <simpara> DEBUG </simpara>
  235. </listitem>
  236. </itemizedlist>
  237. <para>
  238. When the severity of a logger is set to one of these
  239. values, it will only log messages of that severity, and
  240. the severities above it. The severity may also be set to
  241. NONE, in which case all messages from that logger are
  242. inhibited.
  243. <!-- TODO: worded wrong? If I set to INFO, why would it show DEBUG which is literally below in that list? -->
  244. </para>
  245. </section>
  246. <section>
  247. <title>output_options (list)</title>
  248. <para>
  249. Each logger can have zero or more
  250. <option>output_options</option>. These specify where log
  251. messages are sent. These are explained in detail below.
  252. </para>
  253. <para>
  254. The other options for a logger are:
  255. </para>
  256. </section>
  257. <section>
  258. <title>debuglevel (integer)</title>
  259. <para>
  260. When a logger's severity is set to DEBUG, this value
  261. specifies what debug messages should be printed. It ranges
  262. from 0 (least verbose) to 99 (most verbose).
  263. </para>
  264. <!-- TODO: complete this sentence:
  265. The general classification of debug message types is
  266. TODO; there's a ticket to determine these levels, see #1074
  267. -->
  268. <para>
  269. If severity for the logger is not DEBUG, this value is ignored.
  270. </para>
  271. </section>
  272. </section>
  273. <section>
  274. <title>Output Options</title>
  275. <para>
  276. The main settings for an output option are the
  277. <option>destination</option> and a value called
  278. <option>output</option>, the meaning of which depends on
  279. the destination that is set.
  280. </para>
  281. <section>
  282. <title>destination (string)</title>
  283. <para>
  284. The destination is the type of output. It can be one of:
  285. </para>
  286. <itemizedlist>
  287. <listitem>
  288. <simpara> console </simpara>
  289. </listitem>
  290. <listitem>
  291. <simpara> file </simpara>
  292. </listitem>
  293. <listitem>
  294. <simpara> syslog </simpara>
  295. </listitem>
  296. </itemizedlist>
  297. </section>
  298. <section>
  299. <title>output (string)</title>
  300. <para>
  301. This value determines the type of output. There are several
  302. special values allowed here: <command>stdout</command> (messages
  303. are printed on standard output), <command>stderr</command>
  304. (messages are printed on stderr), <command>syslog</command> (messages
  305. are logged to syslog using default name, <command>syslog:name</command>
  306. (messages are logged to syslog using specified name). Any other
  307. value is interpreted as a filename that the logs should be written to.
  308. </para>
  309. <para>
  310. The other options for <option>output_options</option> are:
  311. </para>
  312. <!-- configuration of flush is not supported yet.
  313. <section>
  314. <title>flush (true of false)</title>
  315. <para>
  316. Flush buffers after each log message. Doing this will
  317. reduce performance but will ensure that if the program
  318. terminates abnormally, all messages up to the point of
  319. termination are output.
  320. </para>
  321. </section> -->
  322. <section>
  323. <title>maxsize (integer)</title>
  324. <para>
  325. Only relevant when destination is file, this is maximum
  326. file size of output files in bytes. When the maximum
  327. size is reached, the file is renamed and a new file opened.
  328. (For example, a ".1" is appended to the name &mdash;
  329. if a ".1" file exists, it is renamed ".2",
  330. etc.)
  331. </para>
  332. <para>
  333. If this is 0, no maximum file size is used.
  334. </para>
  335. <note>
  336. <simpara>
  337. Due to a limitation of the underlying logging library
  338. (log4cplus), rolling over the log files (from ".1" to
  339. ".2", etc) may show odd results: There can be
  340. multiple small files at the timing of roll over. This
  341. can happen when multiple processes try to roll
  342. over the files simultaneously.
  343. Version 1.1.0 of log4cplus solved this problem, so if
  344. this or higher version of log4cplus is used to build
  345. Kea, it shouldn't happen. Even for older versions
  346. it is normally expected to happen rarely unless the log
  347. messages are produced very frequently by multiple
  348. different processes.
  349. </simpara>
  350. </note>
  351. </section>
  352. <section>
  353. <title>maxver (integer)</title>
  354. <para>
  355. Maximum number of old log files to keep around when
  356. rolling the output file. Only relevant when
  357. <option>output</option> is <quote>file</quote>.
  358. </para>
  359. </section>
  360. </section>
  361. </section>
  362. <section>
  363. <title>Example Logger Configurations</title>
  364. <para>
  365. In this example we want to set the global logging to
  366. write to the console using standard output.
  367. </para>
  368. <screen><userinput>
  369. "Logging": {
  370. "loggers": [
  371. {
  372. "name": "kea-dhcp4",
  373. "output_options": [
  374. {
  375. "output": "stdout"
  376. }
  377. ],
  378. "severity": "WARN"
  379. }
  380. ]
  381. }
  382. </userinput>
  383. </screen>
  384. <para>In this second example, we want to store debug log messages
  385. in a file that is at most 2MB and keep up to 8 copies of old logfiles.
  386. Once the logfile grows to 2MB, it will be renamed and a new file
  387. file be created.</para>
  388. <screen><userinput>
  389. "Logging": {
  390. "loggers": [
  391. {
  392. "name": "kea-dhcp6",
  393. "output_options": [
  394. {
  395. "output": "/var/log/kea-debug.log",
  396. "maxver": 8,
  397. "maxsize": 204800,
  398. "destination": "file"
  399. }
  400. ],
  401. "severity": "DEBUG",
  402. "debuglevel": 99
  403. }
  404. ]
  405. }</userinput></screen>
  406. </section>
  407. </section>
  408. <section id="logging-message-format">
  409. <title>Logging Message Format</title>
  410. <para>
  411. Each message written to the configured logging
  412. destinations comprises a number of components that identify
  413. the origin of the message and, if the message indicates
  414. a problem, information about the problem that may be
  415. useful in fixing it.
  416. </para>
  417. <para>
  418. Consider the message below logged to a file:
  419. <screen>2014-04-11 12:58:01.005 INFO [kea-dhcp4.dhcpsrv/27456]
  420. DHCPSRV_MEMFILE_DB opening memory file lease database: type=memfile universe=4</screen>
  421. </para>
  422. <para>
  423. Note: the layout of messages written to the system logging
  424. file (syslog) may be slightly different. This message has
  425. been split across two lines here for display reasons; in the
  426. logging file, it will appear on one line.
  427. </para>
  428. <para>
  429. The log message comprises a number of components:
  430. <variablelist>
  431. <varlistentry>
  432. <term>2014-04-11 12:58:01.005</term>
  433. <!-- TODO: timestamp repeated even if using syslog? -->
  434. <listitem><para>
  435. The date and time at which the message was generated.
  436. </para></listitem>
  437. </varlistentry>
  438. <varlistentry>
  439. <term>INFO</term>
  440. <listitem><para>
  441. The severity of the message.
  442. </para></listitem>
  443. </varlistentry>
  444. <varlistentry>
  445. <term>[kea-dhcp4.dhcpsrv/27456]</term>
  446. <listitem><para>
  447. The source of the message. This comprises two elements:
  448. the Kea process generating the message (in this
  449. case, <command>kea-dhcp4</command>) and the component
  450. within the program from which the message originated
  451. (which is the name of the common library used by DHCP server
  452. implementations). The number after the slash is a process id
  453. (pid).
  454. </para></listitem>
  455. </varlistentry>
  456. <varlistentry>
  457. <term>DHCPSRV_MEMFILE_DB</term>
  458. <listitem><para>
  459. The message identification. Every message in Kea
  460. has a unique identification, which can be used as an
  461. index into the <ulink
  462. url="kea-messages.html"><citetitle>Kea Messages
  463. Manual</citetitle></ulink> (<ulink
  464. url="http://kea.isc.org/docs/kea-messages.html"
  465. />) from which more information can be obtained.
  466. </para></listitem>
  467. </varlistentry>
  468. <varlistentry>
  469. <term>opening memory file lease database: type=memfile universe=4</term>
  470. <listitem><para>
  471. A brief description.
  472. Within this text, information relating to the condition
  473. that caused the message to be logged will be included.
  474. In this example, the information is logged that the in-memory
  475. lease database backend will be used to store DHCP leases.
  476. </para></listitem>
  477. </varlistentry>
  478. </variablelist>
  479. </para>
  480. </section>
  481. <section>
  482. <title>Logging During Kea Startup</title>
  483. <para>
  484. The logging configuration is specified in the configuration file.
  485. However, when Kea starts, the file is not read until some way into the
  486. initialization process. Prior to that, the logging settings are
  487. set to default values, although it is possible to modify some
  488. aspects of the settings by means of environment variables. Note
  489. that in the absence of any logging configuration in the configuration
  490. file, the settings of (possibly modified) default configuration will
  491. persist while the program is running.
  492. </para>
  493. <para>
  494. The following environment variables can be used to control the
  495. behavio of logging during startup:
  496. </para>
  497. <variablelist>
  498. <varlistentry>
  499. <term>KEA_LOCKFILE_DIR</term>
  500. <listitem><para>
  501. Specifies a directory where the logging system should create its
  502. lock file. If not specified, it is
  503. <replaceable>prefix</replaceable>/var/run/kea, where
  504. <replaceable>prefix</replaceable> defaults to /usr/local.
  505. This variable must not end
  506. with a slash. There is one special value: "none", which
  507. instructs Kea to not create lock file at all. This may cause
  508. issues if several processes log to the same file.
  509. </para></listitem>
  510. </varlistentry>
  511. <varlistentry>
  512. <term>KEA_LOGGER_DESTINATION</term>
  513. <listitem><para>
  514. Specifies logging output. There are several special values.
  515. <variablelist>
  516. <varlistentry>
  517. <term>stdout</term>
  518. <listitem><para>
  519. Log to standard output.
  520. </para></listitem>
  521. </varlistentry>
  522. <varlistentry>
  523. <term>stderr</term>
  524. <listitem><para>
  525. Log to standard error.
  526. </para></listitem>
  527. </varlistentry>
  528. <varlistentry>
  529. <term>syslog<optional>:<replaceable>fac</replaceable></optional></term>
  530. <listitem><para>
  531. Log via syslog. The optional
  532. <replaceable>fac</replaceable> (which is
  533. separated from the word "syslog" by a colon)
  534. specifies the
  535. facility to be used for the log messages. Unless
  536. specified, messages will be logged using the
  537. facility "local0".
  538. </para></listitem>
  539. </varlistentry>
  540. </variablelist>
  541. Any other value is treated as a name
  542. of the output file. If not specified otherwise, Kea will log to
  543. standard output.
  544. </para></listitem>
  545. </varlistentry>
  546. </variablelist>
  547. </section>
  548. </chapter>