logging.xml 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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. When diagnosing the problem with the server's operation it is often
  76. desired to use the DEBUG logging level to obtain the verbose output
  77. from the server and libraries it uses. However, high verbosity may
  78. be an overkill for the logging system in cases when the server
  79. is processing high volume traffic. To mitigate this problem, Kea
  80. is using multiple loggers, which can be configured independently
  81. and which are responsible for logging messages from different
  82. functional parts of the server. If the user, trying to diagnose the
  83. problem, has a reasonably high confidence that the problem origins
  84. in a specific function of the server, or the problem is related
  85. to the specific type of operation, he may enable high verbosity
  86. only for the relevant logger, thus limiting the debug messages
  87. to the required minimum.
  88. </para>
  89. <para>
  90. The loggers are associated with a particular library or binary
  91. of Kea. However, each library or binary may (and usually does)
  92. include multiple loggers. For example, the DHCPv4 server binary
  93. contains separate loggers for: packet parsing, for dropped packets,
  94. for callouts etc. Each logger "derives" its configuration from the
  95. root logger. In the typical case, the root logger configuration
  96. is the only logging configuration specified in the configuration
  97. file. Creating a specific configuration for the selected logger,
  98. thus overriding the configuration settings specified in the
  99. root logger configuration, requires putting its configuration
  100. aside of the root logger's configuration with some of the
  101. parameters modified.
  102. </para>
  103. <para>
  104. To illustrate this, suppose you are using the DHCPv4 server
  105. with the root logger <quote>kea-dhcp4</quote> logging at the
  106. INFO level. In order to enable DEBUG verbosity for the DHCPv4
  107. packet drops, you must create configuration entry for the
  108. logger called <quote>kea-dhcp4.bad_packet</quote> and specify
  109. severity DEBUG for this logger. All other configuration
  110. parameters may be omited for this logger if the logger should
  111. use the default values specified in the root logger's
  112. configuration.
  113. </para>
  114. <!-- we don't support asterisk anymore.
  115. <para>
  116. One special case is that of a component name of <quote>*</quote>
  117. (asterisks), which is interpreted as <emphasis>any</emphasis>
  118. component. You can set global logging options by using this,
  119. including setting the logging configuration for a library
  120. that is used by multiple daemons (e.g. <quote>*.config</quote>
  121. specifies the configuration library code in whatever
  122. daemon is using it).
  123. </para> -->
  124. <para>
  125. If there are multiple logger specifications in the configuration
  126. that might match a particular logger, the specification with the
  127. more specific logger name takes precedence. For example, if there
  128. are entries for both <quote>kea-dhcp4</quote> and
  129. <quote>kea-dhcp4.dhcpsrv</quote>, the DHCPv4 server &mdash; and all
  130. libraries it uses that are not dhcpsrv &mdash; will log messages
  131. according to the configuration in the first entry
  132. (<quote>kea-dhcp4</quote>).
  133. </para>
  134. <para>
  135. Currently defined loggers are:
  136. </para>
  137. <itemizedlist>
  138. <listitem>
  139. <simpara><command>kea-dhcp4</command> - this is the root logger for
  140. the DHCPv4 server. All components used by the DHCPv4 server inherit
  141. the settings from this logger if there is no specialized logger
  142. provided.</simpara>
  143. </listitem>
  144. <listitem>
  145. <simpara><command>kea-dhcp4.bad_packet</command> - this is the
  146. logger used by the DHCPv4 server deamon for logging inbound client
  147. packets that were dropped or to which the server responded with a
  148. DHCPNAK. The allows adminstrators to configure a separate log
  149. output that contains only packet drop and reject entries.</simpara>
  150. </listitem>
  151. <listitem>
  152. <simpara><command>kea-dhcp4.dhcp4</command> - this is the logger
  153. used solely by the DHCPv4 server deamon. This logger does not
  154. specify logging settings for libraries used by the deamon.</simpara>
  155. </listitem>
  156. <listitem>
  157. <simpara><command>kea-dhcp4.dhcpsrv</command> - this logger is used
  158. by the libdhcpsrv library. This covers mostly DHCP engine (the lease
  159. allocation and renewal process), database operations and
  160. configuration.</simpara>
  161. </listitem>
  162. <listitem>
  163. <simpara><command>kea-dhcp4.hooks</command> - this logger is used
  164. to log messages related to management of hooks libraries, e.g.
  165. registration and deregistration of the libraries, and to the
  166. initialization of the callouts execution for various hook points
  167. within the DHCPv4 server.</simpara>
  168. </listitem>
  169. <listitem>
  170. <simpara><command>kea-dhcp4.callouts</command> - this logger is used
  171. to log messages pertaining to the callouts registration and execution
  172. for the particular hook point.
  173. </simpara>
  174. </listitem>
  175. <listitem>
  176. <simpara><command>kea-dhcp4.ddns</command> - this logger is used by
  177. the DHCPv4 server to log messages related to the Client FQDN and
  178. Hostname option processing. It also includes log messages
  179. related to the relevant DNS updates.</simpara>
  180. </listitem>
  181. <listitem>
  182. <simpara><command>kea-dhcp4.hosts</command> - this logger is used
  183. within the libdhcpsrv and it logs messages related to the management
  184. of the DHCPv4 host reservations, i.e. retrieval of the resevations
  185. and adding new reservations.</simpara>
  186. </listitem>
  187. <listitem>
  188. <simpara><command>kea-dhcp4.leases</command> - this logger is used
  189. by the DHCPv4 server to log messages related to the lease allocation.
  190. The messages include detailed information about the allocated or
  191. offered leases, errors during the lease allocation etc.
  192. </simpara>
  193. </listitem>
  194. <listitem>
  195. <simpara><command>kea-dhcp4.options</command> - this logger is
  196. used by the DHCPv4 server to log messages related to processing
  197. of the options in the DHCPv4 messages, i.e. parsing options,
  198. encoding options into on-wire format and packet classification
  199. using options contained in the received packets.</simpara>
  200. </listitem>
  201. <listitem>
  202. <simpara><command>kea-dhcp4.packets</command> - this logger
  203. is mostly used to log messages related to transmission of the DHCPv4
  204. packets, i.e. packet reception and sending a response. Such messages
  205. include the information about the source and destination IP addresses
  206. and interfaces used to transmit packets. This logger is also used
  207. to log messages related to subnet selection, as this selection is
  208. usually based on the IP addresses and/or interface names, which can
  209. be retrieved from the received packet, even before the DHCPv4 message
  210. carried in the packet is parsed.
  211. </simpara>
  212. </listitem>
  213. <listitem>
  214. <simpara><command>kea-dhcp6</command> - this is the root logger for
  215. the DHCPv6 server. All components used by the DHCPv6 server inherit
  216. the settings from this logger if there is no specialized logger
  217. provided.</simpara>
  218. </listitem>
  219. <listitem>
  220. <simpara><command>kea-dhcp6.dhcp6</command> - this is the logger
  221. used solely by the DHCPv6 server deamon. This logger does not
  222. specify logging settings for libraries used by the daemon.</simpara>
  223. </listitem>
  224. <listitem>
  225. <simpara><command>kea-dhcp6.dhcpsrv</command> - this logger is used
  226. by the libdhcpsrv library. This covers mostly DHCP engine (the lease
  227. allocation and renewal process), database operations and
  228. configuration.</simpara>
  229. </listitem>
  230. <listitem>
  231. <simpara><command>kea-dhcp6.hooks</command> - this logger is used
  232. during DHCPv6 hooks operation, i.e. anything related to user
  233. registration and deregistration of the libraries.</simpara>
  234. </listitem>
  235. <listitem>
  236. <simpara><command>kea-dhcp6.callouts</command> - this logger is used
  237. to log messages pertaining to the callouts registration and execution
  238. for the particular hook point.
  239. </simpara>
  240. </listitem>
  241. <listitem>
  242. <simpara><command>kea-dhcp6.hosts</command> - this logger is used
  243. within the libdhcpsrv and it logs messages related to the management
  244. of the DHCPv6 host reservations, i.e. retrieval of the resevations
  245. and adding new reservations.</simpara>
  246. </listitem>
  247. <listitem>
  248. <simpara><command>kea-dhcp-ddns</command> - this is the root logger for
  249. the kea-dhcp-ddns deamon. All components used by this deamon inherit
  250. the settings from this logger if there is no specialized logger
  251. provided.</simpara>
  252. </listitem>
  253. <listitem>
  254. <simpara><command>kea-dhcp-ddns.dhcpddns</command> - this is the logger
  255. used solely by the kea-dhcp-ddns deamon. This logger does not
  256. specify logging settings for libraries used by the deamon.</simpara>
  257. </listitem>
  258. </itemizedlist>
  259. <para>Additional loggers may be defined in the future. The easiest
  260. way to find out the logger name is to configure all logging to go
  261. to a single destination and look for specific logger names. See
  262. <xref linkend="logging-message-format"/> for details.</para>
  263. </section>
  264. <section>
  265. <title>severity (string)</title>
  266. <para>
  267. This specifies the category of messages logged.
  268. Each message is logged with an associated severity which
  269. may be one of the following (in descending order of
  270. severity):
  271. </para>
  272. <itemizedlist>
  273. <listitem>
  274. <simpara> FATAL </simpara>
  275. </listitem>
  276. <listitem>
  277. <simpara> ERROR </simpara>
  278. </listitem>
  279. <listitem>
  280. <simpara> WARN </simpara>
  281. </listitem>
  282. <listitem>
  283. <simpara> INFO </simpara>
  284. </listitem>
  285. <listitem>
  286. <simpara> DEBUG </simpara>
  287. </listitem>
  288. </itemizedlist>
  289. <para>
  290. When the severity of a logger is set to one of these
  291. values, it will only log messages of that severity, and
  292. the severities above it. The severity may also be set to
  293. NONE, in which case all messages from that logger are
  294. inhibited.
  295. <!-- TODO: worded wrong? If I set to INFO, why would it show DEBUG which is literally below in that list? -->
  296. </para>
  297. </section>
  298. <section>
  299. <title>output_options (list)</title>
  300. <para>
  301. Each logger can have zero or more
  302. <option>output_options</option>. These specify where log
  303. messages are sent. These are explained in detail below.
  304. </para>
  305. <para>
  306. The other options for a logger are:
  307. </para>
  308. </section>
  309. <section>
  310. <title>debuglevel (integer)</title>
  311. <para>
  312. When a logger's severity is set to DEBUG, this value
  313. specifies what debug messages should be printed. It ranges
  314. from 0 (least verbose) to 99 (most verbose).
  315. </para>
  316. <!-- TODO: complete this sentence:
  317. The general classification of debug message types is
  318. TODO; there's a ticket to determine these levels, see #1074
  319. -->
  320. <para>
  321. If severity for the logger is not DEBUG, this value is ignored.
  322. </para>
  323. </section>
  324. </section>
  325. <section>
  326. <title>Output Options</title>
  327. <para>
  328. The main settings for an output option are the
  329. <option>destination</option> and a value called
  330. <option>output</option>, the meaning of which depends on
  331. the destination that is set.
  332. </para>
  333. <section>
  334. <title>destination (string)</title>
  335. <para>
  336. The destination is the type of output. It can be one of:
  337. </para>
  338. <itemizedlist>
  339. <listitem>
  340. <simpara> console </simpara>
  341. </listitem>
  342. <listitem>
  343. <simpara> file </simpara>
  344. </listitem>
  345. <listitem>
  346. <simpara> syslog </simpara>
  347. </listitem>
  348. </itemizedlist>
  349. </section>
  350. <section>
  351. <title>output (string)</title>
  352. <para>
  353. This value determines the type of output. There are several
  354. special values allowed here: <command>stdout</command> (messages
  355. are printed on standard output), <command>stderr</command>
  356. (messages are printed on stderr), <command>syslog</command> (messages
  357. are logged to syslog using default name, <command>syslog:name</command>
  358. (messages are logged to syslog using specified name). Any other
  359. value is interpreted as a filename that the logs should be written to.
  360. </para>
  361. <para>
  362. The other options for <option>output_options</option> are:
  363. </para>
  364. <!-- configuration of flush is not supported yet.
  365. <section>
  366. <title>flush (true of false)</title>
  367. <para>
  368. Flush buffers after each log message. Doing this will
  369. reduce performance but will ensure that if the program
  370. terminates abnormally, all messages up to the point of
  371. termination are output.
  372. </para>
  373. </section> -->
  374. <section>
  375. <title>maxsize (integer)</title>
  376. <para>
  377. Only relevant when destination is file, this is maximum
  378. file size of output files in bytes. When the maximum
  379. size is reached, the file is renamed and a new file opened.
  380. (For example, a ".1" is appended to the name &mdash;
  381. if a ".1" file exists, it is renamed ".2",
  382. etc.)
  383. </para>
  384. <para>
  385. If this is 0, no maximum file size is used.
  386. </para>
  387. <note>
  388. <simpara>
  389. Due to a limitation of the underlying logging library
  390. (log4cplus), rolling over the log files (from ".1" to
  391. ".2", etc) may show odd results: There can be
  392. multiple small files at the timing of roll over. This
  393. can happen when multiple processes try to roll
  394. over the files simultaneously.
  395. Version 1.1.0 of log4cplus solved this problem, so if
  396. this or higher version of log4cplus is used to build
  397. Kea, it shouldn't happen. Even for older versions
  398. it is normally expected to happen rarely unless the log
  399. messages are produced very frequently by multiple
  400. different processes.
  401. </simpara>
  402. </note>
  403. </section>
  404. <section>
  405. <title>maxver (integer)</title>
  406. <para>
  407. Maximum number of old log files to keep around when
  408. rolling the output file. Only relevant when
  409. <option>output</option> is <quote>file</quote>.
  410. </para>
  411. </section>
  412. </section>
  413. </section>
  414. <section>
  415. <title>Example Logger Configurations</title>
  416. <para>
  417. In this example we want to set the global logging to
  418. write to the console using standard output.
  419. </para>
  420. <screen><userinput>
  421. "Logging": {
  422. "loggers": [
  423. {
  424. "name": "kea-dhcp4",
  425. "output_options": [
  426. {
  427. "output": "stdout"
  428. }
  429. ],
  430. "severity": "WARN"
  431. }
  432. ]
  433. }
  434. </userinput>
  435. </screen>
  436. <para>In this second example, we want to store debug log messages
  437. in a file that is at most 2MB and keep up to 8 copies of old logfiles.
  438. Once the logfile grows to 2MB, it will be renamed and a new file
  439. file be created.</para>
  440. <screen><userinput>
  441. "Logging": {
  442. "loggers": [
  443. {
  444. "name": "kea-dhcp6",
  445. "output_options": [
  446. {
  447. "output": "/var/log/kea-debug.log",
  448. "maxver": 8,
  449. "maxsize": 204800,
  450. "destination": "file"
  451. }
  452. ],
  453. "severity": "DEBUG",
  454. "debuglevel": 99
  455. }
  456. ]
  457. }</userinput></screen>
  458. </section>
  459. </section>
  460. <section id="logging-message-format">
  461. <title>Logging Message Format</title>
  462. <para>
  463. Each message written to the configured logging
  464. destinations comprises a number of components that identify
  465. the origin of the message and, if the message indicates
  466. a problem, information about the problem that may be
  467. useful in fixing it.
  468. </para>
  469. <para>
  470. Consider the message below logged to a file:
  471. <screen>2014-04-11 12:58:01.005 INFO [kea-dhcp4.dhcpsrv/27456]
  472. DHCPSRV_MEMFILE_DB opening memory file lease database: type=memfile universe=4</screen>
  473. </para>
  474. <para>
  475. Note: the layout of messages written to the system logging
  476. file (syslog) may be slightly different. This message has
  477. been split across two lines here for display reasons; in the
  478. logging file, it will appear on one line.
  479. </para>
  480. <para>
  481. The log message comprises a number of components:
  482. <variablelist>
  483. <varlistentry>
  484. <term>2014-04-11 12:58:01.005</term>
  485. <!-- TODO: timestamp repeated even if using syslog? -->
  486. <listitem><para>
  487. The date and time at which the message was generated.
  488. </para></listitem>
  489. </varlistentry>
  490. <varlistentry>
  491. <term>INFO</term>
  492. <listitem><para>
  493. The severity of the message.
  494. </para></listitem>
  495. </varlistentry>
  496. <varlistentry>
  497. <term>[kea-dhcp4.dhcpsrv/27456]</term>
  498. <listitem><para>
  499. The source of the message. This comprises two elements:
  500. the Kea process generating the message (in this
  501. case, <command>kea-dhcp4</command>) and the component
  502. within the program from which the message originated
  503. (which is the name of the common library used by DHCP server
  504. implementations). The number after the slash is a process id
  505. (pid).
  506. </para></listitem>
  507. </varlistentry>
  508. <varlistentry>
  509. <term>DHCPSRV_MEMFILE_DB</term>
  510. <listitem><para>
  511. The message identification. Every message in Kea
  512. has a unique identification, which can be used as an
  513. index into the <ulink
  514. url="kea-messages.html"><citetitle>Kea Messages
  515. Manual</citetitle></ulink> (<ulink
  516. url="http://kea.isc.org/docs/kea-messages.html"
  517. />) from which more information can be obtained.
  518. </para></listitem>
  519. </varlistentry>
  520. <varlistentry>
  521. <term>opening memory file lease database: type=memfile universe=4</term>
  522. <listitem><para>
  523. A brief description.
  524. Within this text, information relating to the condition
  525. that caused the message to be logged will be included.
  526. In this example, the information is logged that the in-memory
  527. lease database backend will be used to store DHCP leases.
  528. </para></listitem>
  529. </varlistentry>
  530. </variablelist>
  531. </para>
  532. </section>
  533. <section>
  534. <title>Logging During Kea Startup</title>
  535. <para>
  536. The logging configuration is specified in the configuration file.
  537. However, when Kea starts, the file is not read until some way into the
  538. initialization process. Prior to that, the logging settings are
  539. set to default values, although it is possible to modify some
  540. aspects of the settings by means of environment variables. Note
  541. that in the absence of any logging configuration in the configuration
  542. file, the settings of (possibly modified) default configuration will
  543. persist while the program is running.
  544. </para>
  545. <para>
  546. The following environment variables can be used to control the
  547. behavio of logging during startup:
  548. </para>
  549. <variablelist>
  550. <varlistentry>
  551. <term>KEA_LOCKFILE_DIR</term>
  552. <listitem><para>
  553. Specifies a directory where the logging system should create its
  554. lock file. If not specified, it is
  555. <replaceable>prefix</replaceable>/var/run/kea, where
  556. <replaceable>prefix</replaceable> defaults to /usr/local.
  557. This variable must not end
  558. with a slash. There is one special value: "none", which
  559. instructs Kea to not create lock file at all. This may cause
  560. issues if several processes log to the same file.
  561. </para></listitem>
  562. </varlistentry>
  563. <varlistentry>
  564. <term>KEA_LOGGER_DESTINATION</term>
  565. <listitem><para>
  566. Specifies logging output. There are several special values.
  567. <variablelist>
  568. <varlistentry>
  569. <term>stdout</term>
  570. <listitem><para>
  571. Log to standard output.
  572. </para></listitem>
  573. </varlistentry>
  574. <varlistentry>
  575. <term>stderr</term>
  576. <listitem><para>
  577. Log to standard error.
  578. </para></listitem>
  579. </varlistentry>
  580. <varlistentry>
  581. <term>syslog<optional>:<replaceable>fac</replaceable></optional></term>
  582. <listitem><para>
  583. Log via syslog. The optional
  584. <replaceable>fac</replaceable> (which is
  585. separated from the word "syslog" by a colon)
  586. specifies the
  587. facility to be used for the log messages. Unless
  588. specified, messages will be logged using the
  589. facility "local0".
  590. </para></listitem>
  591. </varlistentry>
  592. </variablelist>
  593. Any other value is treated as a name
  594. of the output file. If not specified otherwise, Kea will log to
  595. standard output.
  596. </para></listitem>
  597. </varlistentry>
  598. </variablelist>
  599. </section>
  600. </chapter>