Merge ~wesley-wiedenmeier/cloud-init:logging-docs into cloud-init:master

Proposed by Wesley Wiedenmeier on 2016-10-10
Status: Merged
Merged at revision: f6ae1f9cb1495b14623eed60bef5afbdec85f607
Proposed branch: ~wesley-wiedenmeier/cloud-init:logging-docs
Merge into: cloud-init:master
Diff against target: 206 lines (+178/-0)
3 files modified
cloudinit/config/cc_rsyslog.py (+2/-0)
doc/rtd/index.rst (+1/-0)
doc/rtd/topics/logging.rst (+175/-0)
Reviewer Review Type Date Requested Status
Joshua Harlow 2016-10-10 Approve on 2016-10-13
Review via email: mp+308021@code.launchpad.net

Description of the Change

Add documentation for cloud-init's logging features.

To post a comment you must log in.
Joshua Harlow (harlowja) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
2index 48f1862..1c12e56 100644
3--- a/cloudinit/config/cc_rsyslog.py
4+++ b/cloudinit/config/cc_rsyslog.py
5@@ -18,6 +18,8 @@
6 # You should have received a copy of the GNU General Public License
7 # along with this program. If not, see <http://www.gnu.org/licenses/>.
8 """
9+.. _cc_rsyslog:
10+
11 Rsyslog
12 -------
13 **Summary:** configure system loggig via rsyslog
14diff --git a/doc/rtd/index.rst b/doc/rtd/index.rst
15index fe04b1a..f8ff3c9 100644
16--- a/doc/rtd/index.rst
17+++ b/doc/rtd/index.rst
18@@ -23,6 +23,7 @@ Summary
19 topics/dir_layout
20 topics/examples
21 topics/datasources
22+ topics/logging
23 topics/modules
24 topics/merging
25 topics/moreinfo
26diff --git a/doc/rtd/topics/logging.rst b/doc/rtd/topics/logging.rst
27new file mode 100644
28index 0000000..b010aa9
29--- /dev/null
30+++ b/doc/rtd/topics/logging.rst
31@@ -0,0 +1,175 @@
32+=======
33+Logging
34+=======
35+Cloud-init supports both local and remote logging configurable through python's
36+built-in logging configuration and through the cloud-init rsyslog module.
37+
38+Command Output
39+--------------
40+Cloud-init can redirect its stdout and stderr based on config given under the
41+``output`` config key. The output of any commands run by cloud-init and any
42+user or vendor scripts provided will also be included here. The ``output``
43+key accepts a dictionary for configuration. Output files may be specified
44+individually for each stage (``init``, ``config``, and ``final``), or a single
45+key ``all`` may be used to specify output for all stages.
46+
47+The output for each stage may be specified as a dictionary of ``output`` and
48+``error`` keys, for stdout and stderr respectively, as a tuple with stdout
49+first and stderr second, or as a single string to use for both. The strings
50+passed to all of these keys are handled by the system shell, so any form of
51+redirection that can be used in bash is valid, including piping cloud-init's
52+output to ``tee``, or ``logger``. If only a filename is provided, cloud-init
53+will append its output to the file as though ``>>`` was specified.
54+
55+By default, cloud-init loads its output configuration from
56+``/etc/cloud/coud.cfg.d/05_logging.cfg``. The default config directs both
57+stdout and stderr from all cloud-init stages to
58+``/var/log/cloud-init-output.log``. The default config is given as ::
59+
60+ output: { all: "| tee -a /var/log/cloud-init-output.log" }
61+
62+For a more complex example, the following configuration would output the init
63+stage to ``/var/log/cloud-init.out`` and ``/var/log/cloud-init.err``, for
64+stdout and stderr respectively, replacing anything that was previously there.
65+For the config stage, it would pipe both stdout and stderr through
66+``tee -a /var/log/cloud-config.log``. For the final stage it would append the
67+output of stdout and stderr to ``/var/log/cloud-final.out`` and
68+``/var/log/cloud-final.err`` respectively. ::
69+
70+ output:
71+ init:
72+ output: "> /var/log/cloud-init.out"
73+ error: "> /var/log/cloud-init.err"
74+ config: "tee -a /var/log/cloud-config.log"
75+ final:
76+ - ">> /var/log/cloud-final.out"
77+ - "/var/log/cloud-final.err"
78+
79+Python Logging
80+--------------
81+Cloud-init uses the python logging module, and can accept config for this
82+module using the standard python fileConfig format. Cloud-init looks for config
83+for the logging module under the ``logcfg`` key.
84+
85+.. note::
86+ the logging configuration is not yaml, it is python ``fileConfig`` format,
87+ and is passed through directly to the python logging module. please use the
88+ correct syntax for a multi-line string in yaml.
89+
90+By default, cloud-init uses the logging configuration provided in
91+``/etc/cloud/cloud.cfg.d/05_logging.cfg``. The default python logging
92+configuration writes all cloud-init events with a priority of ``WARNING`` or
93+higher to console, and writes all events with a level of ``DEBUG`` or higher
94+to ``/var/log/cloud-init.log`` and via syslog.
95+
96+Python's fileConfig format consists of sections with headings in the format
97+``[title]`` and key value pairs in each section. Configuration for python
98+logging must contain the sections ``[loggers]``, ``[handlers]``, and
99+``[formatters]``, which name the entities of their respective types that will
100+be defined. The section name for each defined logger, handler and formatter
101+will start with its type, followed by an underscore (``_``) and the name of the
102+entity. For example, if a logger was specified with the name ``log01``, config
103+for the logger would be in the section ``[logger_log01]``.
104+
105+Logger config entries contain basic logging set up. They may specify a list of
106+handlers to send logging events to as well as the lowest priority level of
107+events to handle. A logger named ``root`` must be specified and its
108+configuration (under ``[logger_root]``) must contain a level and a list of
109+handlers. A level entry can be any of the following: ``DEBUG``, ``INFO``,
110+``WARNING``, ``ERROR``, ``CRITICAL``, or ``NOTSET``. For the ``root`` logger
111+the ``NOTSET`` option will allow all logging events to be recorded.
112+
113+Each configured handler must specify a class under the python's ``logging``
114+package namespace. A handler may specify a message formatter to use, a priority
115+level, and arguments for the handler class. Common handlers are
116+``StreamHandler``, which handles stream redirects (i.e. logging to stderr),
117+and ``FileHandler`` which outputs to a log file. The logging module also
118+supports logging over net sockets, over http, via smtp, and additional
119+complex configurations. For full details about the handlers available for
120+python logging, please see the documentation for `python logging handlers`_.
121+
122+Log messages are formatted using the ``logging.Formatter`` class, which is
123+configured using ``formatter`` config entities. A default format of
124+``%(message)s`` is given if no formatter configs are specified. Formatter
125+config entities accept a format string which supports variable replacements.
126+These may also accept a ``datefmt`` string which may be used to configure the
127+timestamp used in the log messages. The format variables ``%(asctime)s``,
128+``%(levelname)s`` and ``%(message)s`` are commonly used and represent the
129+timestamp, the priority level of the event and the event message. For
130+additional information on logging formatters see `python logging formatters`_.
131+
132+.. note::
133+ by default the format string used in the logging formatter are in python's
134+ old style ``%s`` form. the ``str.format()`` and ``string.Template`` styles
135+ can also be used by using ``{`` or ``$`` in place of ``%`` by setting the
136+ ``style`` parameter in formatter config.
137+
138+A simple, but functional python logging configuration for cloud-init is below.
139+It will log all messages of priority ``DEBUG`` or higher both stderr and
140+``/tmp/my.log`` using a ``StreamHandler`` and a ``FileHandler``, using
141+the default format string ``%(message)s``::
142+
143+ logcfg: |
144+ [loggers]
145+ keys=root,cloudinit
146+ [handlers]
147+ keys=ch,cf
148+ [formatters]
149+ keys=
150+ [logger_root]
151+ level=DEBUG
152+ handlers=
153+ [logger_cloudinit]
154+ level=DEBUG
155+ qualname=cloudinit
156+ handlers=ch,cf
157+ [handler_ch]
158+ class=StreamHandler
159+ level=DEBUG
160+ args=(sys.stderr,)
161+ [handler_cf]
162+ class=FileHandler
163+ level=DEBUG
164+ args=('/tmp/my.log',)
165+
166+For additional information about configuring python's logging module, please
167+see the documentation for `python logging config`_.
168+
169+Rsyslog Module
170+--------------
171+Cloud-init's ``cc_rsyslog`` module allows for fully customizable rsyslog
172+configuration under the ``rsyslog`` config key. The simplest way to
173+use the rsyslog module is by specifying remote servers under the ``remotes``
174+key in ``rsyslog`` config. The ``remotes`` key takes a dictionary where each
175+key represents the name of an rsyslog server and each value is the
176+configuration for that server. The format for server config is:
177+
178+ - optional filter for log messages (defaults to ``*.*``)
179+ - optional leading ``@`` or ``@@``, indicating udp and tcp respectively
180+ (defaults to ``@``, for udp)
181+ - ipv4 or ipv6 hostname or address. ipv6 addresses must be in ``[::1]``
182+ format, (e.g. ``@[fd00::1]:514``)
183+ - optional port number (defaults to ``514``)
184+
185+For example, to send logging to an rsyslog server named ``log_serv`` with
186+address ``10.0.4.1``, using port number ``514``, over udp, with all log
187+messages enabled one could use either of the following.
188+
189+With all options specified::
190+
191+ rsyslog:
192+ remotes:
193+ log_serv: "*.* @10.0.4.1:514"
194+
195+With defaults used::
196+
197+ rsyslog:
198+ remotes:
199+ log_serv: "10.0.4.1"
200+
201+
202+For more information on rsyslog configuration, see :ref:`cc_rsyslog`.
203+
204+.. _python logging config: https://docs.python.org/3/library/logging.config.html#configuration-file-format
205+.. _python logging handlers: https://docs.python.org/3/library/logging.handlers.html
206+.. _python logging formatters: https://docs.python.org/3/library/logging.html#formatter-objects

Subscribers

People subscribed via source and target branches