/hazelcast-documentation/src/main/docbook/manual/content/config/Logging.xml

https://bitbucket.org/gabral6_gmailcom/hazelcast · XML · 137 lines · 116 code · 6 blank · 15 comment · 0 complexity · b9f345f091f967e359584bb55356548c MD5 · raw file

  1. <?xml version='1.0' encoding='UTF-8'?>
  2. <!--
  3. ~ Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  4. ~
  5. ~ Licensed under the Apache License, Version 2.0 (the "License");
  6. ~ you may not use this file except in compliance with the License.
  7. ~ You may obtain a copy of the License at
  8. ~
  9. ~ http://www.apache.org/licenses/LICENSE-2.0
  10. ~
  11. ~ Unless required by applicable law or agreed to in writing, software
  12. ~ distributed under the License is distributed on an "AS IS" BASIS,
  13. ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. ~ See the License for the specific language governing permissions and
  15. ~ limitations under the License.
  16. -->
  17. <sect1 xml:id="Logging" version="5.0" xmlns="http://docbook.org/ns/docbook"
  18. xmlns:xi="http://www.w3.org/2001/XInclude"
  19. xmlns:xlink="http://www.w3.org/1999/xlink"
  20. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  21. xsi:schemaLocation="http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd
  22. http://www.w3.org/1999/xlink http://www.w3.org/1999/xlink.xsd">
  23. <title>Logging Configuration</title>
  24. <para>Hazelcast has a flexible logging configuration and doesn't depend on any logging framework except JDK logging.
  25. It has in-built adaptors for a number of logging frameworks
  26. and also supports custom loggers by providing logging interfaces.
  27. </para>
  28. <para>To use built-in adaptors you should set
  29. <code>hazelcast.logging.type</code>
  30. property to one of
  31. predefined types below.
  32. <itemizedlist>
  33. <listitem>
  34. <para><emphasis role="bold">jdk:</emphasis>JDK logging (default)
  35. </para>
  36. </listitem>
  37. <listitem>
  38. <para><emphasis role="bold">log4j:</emphasis>Log4j
  39. </para>
  40. </listitem>
  41. <listitem>
  42. <para><emphasis role="bold">slf4j:</emphasis>Slf4j
  43. </para>
  44. </listitem>
  45. <listitem>
  46. <para><emphasis role="bold">none:</emphasis>disable logging
  47. </para>
  48. </listitem>
  49. </itemizedlist>
  50. You can set
  51. <code>hazelcast.logging.type</code>
  52. through configuration xml, configuration API or JVM system property.
  53. <itemizedlist>
  54. <listitem>
  55. <para>
  56. <emphasis role="bold">Configuration xml</emphasis>
  57. </para>
  58. <para>
  59. <programlisting language="xml">
  60. &lt;hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config
  61. http://www.hazelcast.com/schema/config/hazelcast-config-2.5.xsd"
  62. xmlns="http://www.hazelcast.com/schema/config"
  63. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
  64. ....
  65. &lt;properties&gt;
  66. &lt;property name="hazelcast.logging.type"&gt;jdk&lt;/property&gt;
  67. ....
  68. &lt;/properties&gt;
  69. &lt;/hazelcast&gt;</programlisting>
  70. </para>
  71. </listitem>
  72. <listitem>
  73. <para>
  74. <emphasis role="bold">Configuration API</emphasis>
  75. </para>
  76. <para>
  77. <programlisting language="java">
  78. Config cfg = new Config() ;
  79. cfg.setProperty("hazelcast.logging.type", "log4j");
  80. </programlisting>
  81. </para>
  82. </listitem>
  83. <listitem>
  84. <para>
  85. <emphasis role="bold">System Property</emphasis>
  86. </para>
  87. <para>
  88. <orderedlist>
  89. <listitem>
  90. <para>Using JVM parameter:
  91. <literal>java -Dhazelcast.logging.type=slf4j</literal>
  92. </para>
  93. </listitem>
  94. <listitem>
  95. <para>Using System class:
  96. <literal>System.setProperty("hazelcast.logging.type", "none");</literal>
  97. </para>
  98. </listitem>
  99. </orderedlist>
  100. </para>
  101. </listitem>
  102. </itemizedlist>
  103. </para>
  104. <para>To use custom logging feature you should implement
  105. <code>com.hazelcast.logging.LoggerFactory</code>
  106. and
  107. <code>com.hazelcast.logging.ILogger</code>
  108. interfaces and set system property
  109. <literal>hazelcast.logging.class</literal>
  110. to
  111. your custom
  112. <code>LoggerFactory</code>
  113. class name.
  114. <programlisting language="java">java -Dhazelcast.logging.class=foo.bar.MyLoggingFactory</programlisting>
  115. </para>
  116. <para>
  117. You can also listen to logging events generated by Hazelcast runtime by registering <literal>LogListener</literal>s to<literal>LoggingService</literal>.
  118. <programlisting language="java">
  119. LogListener listener = new LogListener() {
  120. public void log(LogEvent logEvent) {
  121. // do something
  122. }
  123. }
  124. LoggingService loggingService = Hazelcast.getLoggingService();
  125. loggingService.addLogListener(Level.INFO, listener):
  126. </programlisting>
  127. Through the
  128. <literal>LoggingService</literal>
  129. you can get the current used ILogger implementation and log your own messages too.
  130. </para>
  131. </sect1>