logging.xml 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  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.dhcp4</command> - this is the logger
  140. used solely by the DHCPv4 server deamon. This logger does not
  141. specify logging settings for libraries used by the deamon.</simpara>
  142. </listitem>
  143. <listitem>
  144. <simpara><command>kea-dhcp4.dhcpsrv</command> - this logger is used
  145. by the libdhcpsrv library. This covers mostly DHCP engine (the lease
  146. allocation and renewal process), database operations and
  147. configuration.</simpara>
  148. </listitem>
  149. <listitem>
  150. <simpara><command>kea-dhcp4.hooks</command> - this logger is used
  151. during DHCPv4 hooks operation, i.e. anything related to user
  152. libraries will be logged using this logger.</simpara>
  153. </listitem>
  154. <listitem>
  155. <simpara><command>kea-dhcp6</command> - this is the root logger for
  156. the DHCPv6 server. All components used by the DHCPv6 server inherit
  157. the settings from this logger if there is no specialized logger
  158. provided.</simpara>
  159. </listitem>
  160. <listitem>
  161. <simpara><command>kea-dhcp6.dhcp6</command> - this is the logger
  162. used solely by the DHCPv6 server deamon. This logger does not
  163. specify logging settings for libraries used by the daemon.</simpara>
  164. </listitem>
  165. <listitem>
  166. <simpara><command>kea-dhcp6.dhcpsrv</command> - this logger is used
  167. by the libdhcpsrv library. This covers mostly DHCP engine (the lease
  168. allocation and renewal process), database operations and
  169. configuration.</simpara>
  170. </listitem>
  171. <listitem>
  172. <simpara><command>kea-dhcp6.hooks</command> - this logger is used
  173. during DHCPv6 hooks operation, i.e. anything related to user
  174. libraries will be logged using this logger.</simpara>
  175. </listitem>
  176. <listitem>
  177. <simpara><command>kea-dhcp-ddns</command> - this is the root logger for
  178. the kea-dhcp-ddns deamon. All components used by this deamon inherit
  179. the settings from this logger if there is no specialized logger
  180. provided.</simpara>
  181. </listitem>
  182. <listitem>
  183. <simpara><command>kea-dhcp-ddns.dhcpddns</command> - this is the logger
  184. used solely by the kea-dhcp-ddns deamon. This logger does not
  185. specify logging settings for libraries used by the deamon.</simpara>
  186. </listitem>
  187. </itemizedlist>
  188. <para>Additional loggers may be defined in the future. The easiest
  189. way to find out the logger name is to configure all logging to go
  190. to a single destination and look for specific logger names. See
  191. <xref linkend="logging-message-format"/> for details.</para>
  192. </section>
  193. <section>
  194. <title>severity (string)</title>
  195. <para>
  196. This specifies the category of messages logged.
  197. Each message is logged with an associated severity which
  198. may be one of the following (in descending order of
  199. severity):
  200. </para>
  201. <itemizedlist>
  202. <listitem>
  203. <simpara> FATAL </simpara>
  204. </listitem>
  205. <listitem>
  206. <simpara> ERROR </simpara>
  207. </listitem>
  208. <listitem>
  209. <simpara> WARN </simpara>
  210. </listitem>
  211. <listitem>
  212. <simpara> INFO </simpara>
  213. </listitem>
  214. <listitem>
  215. <simpara> DEBUG </simpara>
  216. </listitem>
  217. </itemizedlist>
  218. <para>
  219. When the severity of a logger is set to one of these
  220. values, it will only log messages of that severity, and
  221. the severities above it. The severity may also be set to
  222. NONE, in which case all messages from that logger are
  223. inhibited.
  224. <!-- TODO: worded wrong? If I set to INFO, why would it show DEBUG which is literally below in that list? -->
  225. </para>
  226. </section>
  227. <section>
  228. <title>output_options (list)</title>
  229. <para>
  230. Each logger can have zero or more
  231. <option>output_options</option>. These specify where log
  232. messages are sent. These are explained in detail below.
  233. </para>
  234. <para>
  235. The other options for a logger are:
  236. </para>
  237. </section>
  238. <section>
  239. <title>debuglevel (integer)</title>
  240. <para>
  241. When a logger's severity is set to DEBUG, this value
  242. specifies what debug messages should be printed. It ranges
  243. from 0 (least verbose) to 99 (most verbose).
  244. </para>
  245. <!-- TODO: complete this sentence:
  246. The general classification of debug message types is
  247. TODO; there's a ticket to determine these levels, see #1074
  248. -->
  249. <para>
  250. If severity for the logger is not DEBUG, this value is ignored.
  251. </para>
  252. </section>
  253. </section>
  254. <section>
  255. <title>Output Options</title>
  256. <para>
  257. The main settings for an output option are the
  258. <option>destination</option> and a value called
  259. <option>output</option>, the meaning of which depends on
  260. the destination that is set.
  261. </para>
  262. <section>
  263. <title>destination (string)</title>
  264. <para>
  265. The destination is the type of output. It can be one of:
  266. </para>
  267. <itemizedlist>
  268. <listitem>
  269. <simpara> console </simpara>
  270. </listitem>
  271. <listitem>
  272. <simpara> file </simpara>
  273. </listitem>
  274. <listitem>
  275. <simpara> syslog </simpara>
  276. </listitem>
  277. </itemizedlist>
  278. </section>
  279. <section>
  280. <title>output (string)</title>
  281. <para>
  282. This value determines the type of output. There are several
  283. special values allowed here: <command>stdout</command> (messages
  284. are printed on standard output), <command>stderr</command>
  285. (messages are printed on stderr), <command>syslog</command> (messages
  286. are logged to syslog using default name, <command>syslog:name</command>
  287. (messages are logged to syslog using specified name). Any other
  288. value is interpreted as a filename that the logs should be written to.
  289. </para>
  290. <para>
  291. The other options for <option>output_options</option> are:
  292. </para>
  293. <!-- configuration of flush is not supported yet.
  294. <section>
  295. <title>flush (true of false)</title>
  296. <para>
  297. Flush buffers after each log message. Doing this will
  298. reduce performance but will ensure that if the program
  299. terminates abnormally, all messages up to the point of
  300. termination are output.
  301. </para>
  302. </section> -->
  303. <section>
  304. <title>maxsize (integer)</title>
  305. <para>
  306. Only relevant when destination is file, this is maximum
  307. file size of output files in bytes. When the maximum
  308. size is reached, the file is renamed and a new file opened.
  309. (For example, a ".1" is appended to the name &mdash;
  310. if a ".1" file exists, it is renamed ".2",
  311. etc.)
  312. </para>
  313. <para>
  314. If this is 0, no maximum file size is used.
  315. </para>
  316. <note>
  317. <simpara>
  318. Due to a limitation of the underlying logging library
  319. (log4cplus), rolling over the log files (from ".1" to
  320. ".2", etc) may show odd results: There can be
  321. multiple small files at the timing of roll over. This
  322. can happen when multiple processes try to roll
  323. over the files simultaneously.
  324. Version 1.1.0 of log4cplus solved this problem, so if
  325. this or higher version of log4cplus is used to build
  326. Kea, it shouldn't happen. Even for older versions
  327. it is normally expected to happen rarely unless the log
  328. messages are produced very frequently by multiple
  329. different processes.
  330. </simpara>
  331. </note>
  332. </section>
  333. <section>
  334. <title>maxver (integer)</title>
  335. <para>
  336. Maximum number of old log files to keep around when
  337. rolling the output file. Only relevant when
  338. <option>output</option> is <quote>file</quote>.
  339. </para>
  340. </section>
  341. </section>
  342. </section>
  343. <section>
  344. <title>Example Logger Configurations</title>
  345. <para>
  346. In this example we want to set the global logging to
  347. write to the console using standard output.
  348. </para>
  349. <screen><userinput>
  350. "Logging": {
  351. "loggers": [
  352. {
  353. "name": "kea-dhcp4",
  354. "output_options": [
  355. {
  356. "output": "stdout"
  357. }
  358. ],
  359. "severity": "WARN"
  360. }
  361. ]
  362. }
  363. </userinput>
  364. </screen>
  365. <para>In this second example, we want to store debug log messages
  366. in a file that is at most 2MB and keep up to 8 copies of old logfiles.
  367. Once the logfile grows to 2MB, it will be renamed and a new file
  368. file be created.</para>
  369. <screen><userinput>
  370. "Logging": {
  371. "loggers": [
  372. {
  373. "name": "kea-dhcp6",
  374. "output_options": [
  375. {
  376. "output": "/var/log/kea-debug.log",
  377. "maxver": 8,
  378. "maxsize": 204800,
  379. "destination": "file"
  380. }
  381. ],
  382. "severity": "DEBUG",
  383. "debuglevel": 99
  384. }
  385. ]
  386. }</userinput></screen>
  387. </section>
  388. </section>
  389. <section id="logging-message-format">
  390. <title>Logging Message Format</title>
  391. <para>
  392. Each message written to the configured logging
  393. destinations comprises a number of components that identify
  394. the origin of the message and, if the message indicates
  395. a problem, information about the problem that may be
  396. useful in fixing it.
  397. </para>
  398. <para>
  399. Consider the message below logged to a file:
  400. <screen>2014-04-11 12:58:01.005 INFO [kea-dhcp4.dhcpsrv/27456]
  401. DHCPSRV_MEMFILE_DB opening memory file lease database: type=memfile universe=4</screen>
  402. </para>
  403. <para>
  404. Note: the layout of messages written to the system logging
  405. file (syslog) may be slightly different. This message has
  406. been split across two lines here for display reasons; in the
  407. logging file, it will appear on one line.
  408. </para>
  409. <para>
  410. The log message comprises a number of components:
  411. <variablelist>
  412. <varlistentry>
  413. <term>2014-04-11 12:58:01.005</term>
  414. <!-- TODO: timestamp repeated even if using syslog? -->
  415. <listitem><para>
  416. The date and time at which the message was generated.
  417. </para></listitem>
  418. </varlistentry>
  419. <varlistentry>
  420. <term>INFO</term>
  421. <listitem><para>
  422. The severity of the message.
  423. </para></listitem>
  424. </varlistentry>
  425. <varlistentry>
  426. <term>[kea-dhcp4.dhcpsrv/27456]</term>
  427. <listitem><para>
  428. The source of the message. This comprises two elements:
  429. the Kea process generating the message (in this
  430. case, <command>kea-dhcp4</command>) and the component
  431. within the program from which the message originated
  432. (which is the name of the common library used by DHCP server
  433. implementations). The number after the slash is a process id
  434. (pid).
  435. </para></listitem>
  436. </varlistentry>
  437. <varlistentry>
  438. <term>DHCPSRV_MEMFILE_DB</term>
  439. <listitem><para>
  440. The message identification. Every message in Kea
  441. has a unique identification, which can be used as an
  442. index into the <ulink
  443. url="kea-messages.html"><citetitle>Kea Messages
  444. Manual</citetitle></ulink> (<ulink
  445. url="http://kea.isc.org/docs/kea-messages.html"
  446. />) from which more information can be obtained.
  447. </para></listitem>
  448. </varlistentry>
  449. <varlistentry>
  450. <term>opening memory file lease database: type=memfile universe=4</term>
  451. <listitem><para>
  452. A brief description.
  453. Within this text, information relating to the condition
  454. that caused the message to be logged will be included.
  455. In this example, the information is logged that the in-memory
  456. lease database backend will be used to store DHCP leases.
  457. </para></listitem>
  458. </varlistentry>
  459. </variablelist>
  460. </para>
  461. </section>
  462. <section>
  463. <title>Logging During Kea Startup</title>
  464. <para>
  465. The logging configuration is specified in the configuration file.
  466. However, when Kea starts, the file is not read until some way into the
  467. initialization process. Prior to that, the logging settings are
  468. set to default values, although it is possible to modify some
  469. aspects of the settings by means of environment variables. Note
  470. that in the absence of any logging configuration in the configuration
  471. file, the settings of (possibly modified) default configuration will
  472. persist while the program is running.
  473. </para>
  474. <para>
  475. The following environment variables can be used to control the
  476. behavio of logging during startup:
  477. </para>
  478. <variablelist>
  479. <varlistentry>
  480. <term>KEA_LOCKFILE_DIR</term>
  481. <listitem><para>
  482. Specifies a directory where the logging system should create its
  483. lock file. If not specified, it is
  484. <replaceable>prefix</replaceable>/var/run/kea, where
  485. <replaceable>prefix</replaceable> defaults to /usr/local.
  486. This variable must not end
  487. with a slash. There is one special value: "none", which
  488. instructs Kea to not create lock file at all. This may cause
  489. issues if several processes log to the same file.
  490. </para></listitem>
  491. </varlistentry>
  492. <varlistentry>
  493. <term>KEA_LOGGER_DESTINATION</term>
  494. <listitem><para>
  495. Specifies logging output. There are several special values.
  496. <variablelist>
  497. <varlistentry>
  498. <term>stdout</term>
  499. <listitem><para>
  500. Log to standard output.
  501. </para></listitem>
  502. </varlistentry>
  503. <varlistentry>
  504. <term>stderr</term>
  505. <listitem><para>
  506. Log to standard error.
  507. </para></listitem>
  508. </varlistentry>
  509. <varlistentry>
  510. <term>syslog<optional>:<replaceable>fac</replaceable></optional></term>
  511. <listitem><para>
  512. Log via syslog. The optional
  513. <replaceable>fac</replaceable> (which is
  514. separated from the word "syslog" by a colon)
  515. specifies the
  516. facility to be used for the log messages. Unless
  517. specified, messages will be logged using the
  518. facility "local0".
  519. </para></listitem>
  520. </varlistentry>
  521. </variablelist>
  522. Any other value is treated as a name
  523. of the output file. If not specified otherwise, Kea will log to
  524. standard output.
  525. </para></listitem>
  526. </varlistentry>
  527. </variablelist>
  528. </section>
  529. </chapter>