Repository: logging-log4php Updated Branches: refs/heads/develop 41adb9984 -> af810f134
Added documentation for LoggerLayoutGelf Signed-off-by: Ivan Habunek <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/logging-log4php/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4php/commit/2373ac0a Tree: http://git-wip-us.apache.org/repos/asf/logging-log4php/tree/2373ac0a Diff: http://git-wip-us.apache.org/repos/asf/logging-log4php/diff/2373ac0a Branch: refs/heads/develop Commit: 2373ac0a35066b1d0a1c704652d719e76c3a64fd Parents: e250c51 Author: Dmitriy Ulyanov <[email protected]> Authored: Sat Apr 19 21:53:13 2014 +0400 Committer: Ivan Habunek <[email protected]> Committed: Sat May 10 15:29:49 2014 +0200 ---------------------------------------------------------------------- docs/layouts/gelf.rst | 90 +++++++++++++ src/examples/php/layout_gelf.php | 23 ++++ src/examples/resources/layout_gelf.properties | 20 +++ src/site/site.xml | 1 + src/site/xdoc/docs/layouts/gelf.xml | 147 +++++++++++++++++++++ 5 files changed, 281 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/2373ac0a/docs/layouts/gelf.rst ---------------------------------------------------------------------- diff --git a/docs/layouts/gelf.rst b/docs/layouts/gelf.rst new file mode 100644 index 0000000..dedac69 --- /dev/null +++ b/docs/layouts/gelf.rst @@ -0,0 +1,90 @@ +================ +LoggerLayoutGelf +================ + +LoggerLayoutGelf formats the log as JSON string according to GELF specification. + +Parameters +---------- + +The following parameters are available: + ++--------------------+---------+----------+---------------+----------------------------------------+ +| Parameter | Type | Required | Default | Description | ++====================+=========+==========+===============+========================================+ +| locationInfo | boolean | No | false | If set to true, adds the file name and | +| | | | | line number at which the log statement | +| | | | | originated. | ++--------------------+---------+----------+---------------+----------------------------------------+ +| host | string | No | Result | Name of server on which logs are | +| | | | of | collected | +| | | | gethostname() | | ++--------------------+---------+----------+---------------+----------------------------------------+ +| shortMessageLength | integer | No | 255 | Maximum length of "short_message" | +| | | | | attribute. | ++--------------------+---------+----------+---------------+----------------------------------------+ + +Examples +-------- + +.. container:: tabs + + .. rubric:: XML format +.. code-block:: xml + + <configuration xmlns="http://logging.apache.org/log4php/"> + <appender name="default" class="LoggerAppenderEcho"> + <layout class="LoggerLayoutGelf"> + <param name="locationInfo" value="true" /> + <param name="host" value="example.com" /> + <param name="shortMessageLength" value="100" /> + </layout> + </appender> + <root> + <appender_ref ref="default" /> + </root> + </configuration> + + .. rubric:: PHP format +.. code-block:: php + + array( + 'appenders' => array( + 'default' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutGelf', + ) + ) + ), + 'rootLogger' => array( + 'appenders' => array('default') + ), + ) + +Running the following code: + +.. code-block:: php + + Logger::configure("config.xml"); + $logger = Logger::getLogger('myLogger'); + $logger->info("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + +Produces the following output: + +.. code-block:: bash + + { + "version":"1.1", + "host":"some-backend.host", + "short_message":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.", + "full_message":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.", + "timestamp":1397928743.1809, + "level":6, + "_facility":"myLogger", + "_thread":"8064", + "_file":"NA", + "_line":"NA", + "_class":"YourClassName", + "_method":"YourMethodName", + } http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/2373ac0a/src/examples/php/layout_gelf.php ---------------------------------------------------------------------- diff --git a/src/examples/php/layout_gelf.php b/src/examples/php/layout_gelf.php new file mode 100644 index 0000000..6f2711b --- /dev/null +++ b/src/examples/php/layout_gelf.php @@ -0,0 +1,23 @@ +<?php +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +// START SNIPPET: doxia +require_once dirname(__FILE__).'/../../main/php/Logger.php'; + +Logger::configure(dirname(__FILE__).'/../resources/layout_gelf.properties'); +$logger = Logger::getRootLogger(); +$logger->info("Hello World!"); http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/2373ac0a/src/examples/resources/layout_gelf.properties ---------------------------------------------------------------------- diff --git a/src/examples/resources/layout_gelf.properties b/src/examples/resources/layout_gelf.properties new file mode 100644 index 0000000..63d3568 --- /dev/null +++ b/src/examples/resources/layout_gelf.properties @@ -0,0 +1,20 @@ +; +; Licensed to the Apache Software Foundation (ASF) under one or more +; contributor license agreements. See the NOTICE file distributed with +; this work for additional information regarding copyright ownership. +; The ASF licenses this file to You under the Apache License, Version 2.0 +; (the "License"); you may not use this file except in compliance with +; the License. You may obtain a copy of the License at +; +; http://www.apache.org/licenses/LICENSE-2.0 +; +; Unless required by applicable law or agreed to in writing, software +; distributed under the License is distributed on an "AS IS" BASIS, +; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +; See the License for the specific language governing permissions and +; limitations under the License. +; +; START SNIPPET: doxia +log4php.appender.default = LoggerAppenderEcho +log4php.appender.default.layout = LoggerLayoutGelf +log4php.rootLogger = DEBUG, default http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/2373ac0a/src/site/site.xml ---------------------------------------------------------------------- diff --git a/src/site/site.xml b/src/site/site.xml index 55662e4..cd829ba 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -61,6 +61,7 @@ <item name="LoggerAppenderSyslog" href="/docs/appenders/syslog.html" /> </item> <item name="Layouts" href="/docs/layouts.html" collapse="true"> + <item name="LoggerLayoutGelf" href="/docs/layouts/gelf.html" /> <item name="LoggerLayoutHtml" href="/docs/layouts/html.html" /> <item name="LoggerLayoutPattern" href="/docs/layouts/pattern.html" /> <item name="LoggerLayoutSerialized" href="/docs/layouts/serialized.html" /> http://git-wip-us.apache.org/repos/asf/logging-log4php/blob/2373ac0a/src/site/xdoc/docs/layouts/gelf.xml ---------------------------------------------------------------------- diff --git a/src/site/xdoc/docs/layouts/gelf.xml b/src/site/xdoc/docs/layouts/gelf.xml new file mode 100644 index 0000000..188fc3e --- /dev/null +++ b/src/site/xdoc/docs/layouts/gelf.xml @@ -0,0 +1,147 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<document xmlns="http://maven.apache.org/XDOC/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd"> + + <properties> + <title>LoggerLayoutGelf</title> + </properties> + + <body> + <section name="LoggerLayoutGelf" id="LoggerLayoutGelf"> + + <p>LoggerLayoutGelf formats the log as JSON string according to GELF specification.</p> + + <subsection name="Parameters"> + <p>The following parameters are available:</p> + + <table> + <thead> + <tr> + <th>Parameter</th> + <th>Type</th> + <th>Required</th> + <th>Default</th> + <th>Description</th> + </tr> + </thead> + <tbody> + <tr> + <td>locationInfo</td> + <td>boolean</td> + <td>No</td> + <td>false</td> + <td>If set to true, adds the file name and line number at which the log statement originated.</td> + </tr> + <tr> + <td>host</td> + <td>string</td> + <td>No</td> + <td>Result of gethostname()</td> + <td>Name of server on which logs are collected</td> + </tr> + <tr> + <td>shortMessageLength</td> + <td>integer</td> + <td>No</td> + <td>255</td> + <td>Maximum length of "short_message" attribute</td> + </tr> + </tbody> + </table> + + </subsection> + + <subsection name="Examples"> + + <p>Configuration:</p> + + <div class="auto-tabs"> + <ul> + <li>XML</li> + <li>PHP</li> + </ul> + + <div class="tab-content" > + <div class="tab-pane"> + <pre class="prettyprint linenums"><![CDATA[ +<configuration xmlns="http://logging.apache.org/log4php/"> + <appender name="default" class="LoggerAppenderEcho"> + <layout class="LoggerLayoutGelf"> + <param name="locationInfo" value="true" /> + <param name="host" value="example.com" /> + <param name="shortMessageLength" value="100" /> + </layout> + </appender> + <root> + <appender_ref ref="default" /> + </root> +</configuration> +]]></pre> + </div> + <div class="tab-pane"> + <pre class="prettyprint linenums"><![CDATA[ +array( + 'appenders' => array( + 'default' => array( + 'class' => 'LoggerAppenderEcho', + 'layout' => array( + 'class' => 'LoggerLayoutGelf', + ) + ) + ), + 'rootLogger' => array( + 'appenders' => array('default') + ), +) +]]></pre> + </div> + </div> + </div> + + <p>Running the following code:</p> + + <pre class="prettyprint linenums"> + Logger::configure("config.xml"); + $logger = Logger::getLogger('myLogger'); + $logger->info("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + </pre> + + <p>Produces the following output:</p> + +<pre> +{ + "version":"1.1", + "host":"some-backend.host", + "short_message":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.", + "full_message":"Lorem ipsum dolor sit amet, consectetur adipiscing elit.", + "timestamp":1397928743.1809, + "level":6, + "_facility":"myLogger", + "_thread":"8064", + "_file":"NA", + "_line":"NA", + "_class":"YourClassName", + "_method":"YourMethodName", +} +</pre> + + </subsection> + </section> + </body> +</document>
