logging.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. .. _logging:
  2. Advanced log configuration
  3. ==========================
  4. GeoServer uses the Log4J framework for logging, which is configured by selecting a logging profile (in the :ref:`global settings <config_globalsettings_log_location>`).
  5. The GeoServer logging profiles assign logging levels to specific server operations:
  6. * GeoServer loggers record server function and the activity of individual services.
  7. * GeoWebCache loggers record the activity of the tile protocol library used by GeoServer.
  8. * GeoTools loggers record the activity of the data access and rendering library used by GeoServer.
  9. * The appender ``stdout`` is setup as a Console appender sending information to standard output, based on :guilabel:`Log to Stdout` :ref:`global settings <config_globalsettings_log_stdout>`.
  10. * The appender ``geoserverlogfile`` is setup as a FileAppender or RollingFile appender sending information to the :guilabel:`Log location` :ref:`global settings <config_globalsettings_log_location>`.
  11. * Logging levels range from:
  12. * Failure (``FATAL``, ``ERROR``, ``WARN``) levels
  13. * Operational (``INFO``, ``CONFIG``) levels
  14. * Verbose (``DEBUG``, ``TRACE``, ``FINEST``) levels
  15. In addition to the built-in profiles you may setup a custom logging profile, or override the logging configuration completely (even to use another logging library altogether).
  16. Built-in logging profiles
  17. -------------------------
  18. GeoServer includes several built-in logging profiles:
  19. * :download:`DEFAULT_LOGGING </../../../../src/main/src/main/resources/DEFAULT_LOGGING.xml>`
  20. * :download:`GEOSERVER_DEVELOPER_LOGGING </../../../../src/main/src/main/resources/GEOSERVER_DEVELOPER_LOGGING.xml>`
  21. * :download:`GEOTOOLS_DEVELOPER_LOGGING </../../../../src/main/src/main/resources/GEOTOOLS_DEVELOPER_LOGGING.xml>`
  22. * :download:`PRODUCTION_LOGGING </../../../../src/main/src/main/resources/PRODUCTION_LOGGING.xml>`
  23. * :download:`QUIET_LOGGING </../../../../src/main/src/main/resources/QUIET_LOGGING.xml>`
  24. * :download:`VERBOSE_LOGGING </../../../../src/main/src/main/resources/VERBOSE_LOGGING.xml>`
  25. The built-in logging profiles are installed into your data directory the first time the application is run. If you have customized (see the next section) these files and wish to restore the original contents:
  26. * Use the startup parameter ``-DUPDATE_BUILT_IN_LOGGING_PROFILES=true``, the built-in logging profiles will be checked and updated if required; or
  27. * Delete the file and restart GeoServer, the missing file will be restored; or
  28. * Copy the contents from the download links above
  29. For a description of these logging profiles see :ref:`config_globalsettings_log_profile`. Additional built-in logging profiles are supplied by installed extensions (example :download:`IMPORTER_LOGGING </../../../../src/extension/importer/core/src/main/resources/IMPORTER_LOGGING.xml>` profile is built into the importer extension).
  30. Custom logging profiles
  31. -----------------------
  32. Anyone can write a new logging profile by adding a Log4J configuration file to the list of files already available in the ``$GEOSERVER_DATA_DIR/logs`` folder.
  33. Profiles in this folder that match :file:`*_LOGGING.*` will be listed on the global settings page as available for use. The name of the file, excluding the extension, will be presented as the profile name.
  34. Here is an example, taken from the :download:`DEFAULT_LOGGING.xml </../../../../src/main/src/main/resources/DEFAULT_LOGGING.xml>` configuration, which enables additional GeoServer log messages to be included in the logs:
  35. .. literalinclude:: /../../../../src/main/src/main/resources/DEFAULT_LOGGING.xml
  36. :language: xml
  37. Any custom configuration can be setup to enable specific packages to emit logs at the desired logging level.
  38. There are however a few rules to follow:
  39. * Custom levels are available for ``CONFIG`` and ``FINEST`` levels.
  40. * Appenders are used to output logging information, with GeoServer providing external configuration for appenders named ``geoserverlogfile`` and ``stdout``.
  41. * Always include a ``geoserverlogfile`` ``FileAppender`` or ``RollingFile`` appender that GeoServer will configure to work against the location configured in the :ref:`global settings <config_globalsettings_log_location>`.
  42. Care is taken to preserve your file extension when updating ``<filename>`` location, so if you wish to log to :file:`access_logs.txt` you may do so, and the :file:`txt` extension will be preserved.
  43. * When setting ``geoserverlogfile`` appender as ``RollingFile`` appender, care is taken to preserve your ``<filePattern>`` extensions, which must align with the roll over strategies configured.
  44. As an example ``-%i`` is used with DefaultRolloverStrategy to produce a maximum of ``3`` backup files.
  45. .. literalinclude:: /../../../../src/main/src/main/resources/DEFAULT_LOGGING.xml
  46. :language: xml
  47. :start-at: <RollingFile
  48. :end-at: </RollingFile>
  49. :dedent: 8
  50. * a ``Console`` appender writing to the standard output should be called ``stdout`` and again GeoServer will enable/disable it according to the configuration set in the :ref:`global settings <config_globalsettings_log_stdout>`
  51. .. literalinclude:: /../../../../src/main/src/main/resources/DEFAULT_LOGGING.xml
  52. :language: xml
  53. :start-at: <Console
  54. :end-at: </Console>
  55. :dedent: 8
  56. * Loggers are used to collect messages from geoserver components, and individual libraries used.
  57. * GeoServer Logger names match up with the package names in the project javadocs overview (available for download).
  58. As an example package ``org.geoserver.wms`` is listed, allowing level of WMS service logging to be controlled:
  59. .. code-block:: xml
  60. <Logger name="org.geoserver.wms" level="debug" additivity="false">
  61. <AppenderRef ref="stdout"/>
  62. <AppenderRef ref="geoserverlogfile"/>
  63. </Logger>
  64. * GeoTools Logger names match up with the package names in the `project javadocs overview <https://docs.geotools.org/latest/javadocs/overview-summary.html>`__.
  65. As an example package ``org.geotools.data.shapefile`` is listed, allowing level of shapefile logging to be controlled:
  66. .. code-block:: xml
  67. <Logger name="org.geotools.data.shapefile" level="debug" additivity="false">
  68. <AppenderRef ref="stdout"/>
  69. <AppenderRef ref="geoserverlogfile"/>
  70. </Logger>
  71. * Assign a level to each logger indicating the level of detail you wish to record:
  72. ======= ===========
  73. Level Description
  74. ======= ===========
  75. OFF Turn off all logging
  76. FATAL A serious problem has occurred, application may be crashing or in need of restart
  77. ERROR Problem has occurred, application unable to perform requested operation
  78. WARN Potential problem, application will try and continue
  79. INFO Normal function indicating what application is doing.
  80. CONFIG Normal application function during application startup and configuration
  81. DEBUG Internal messages intended for debugging
  82. TRACE Metod by method tracing of execution
  83. FINEST Really detailed troubleshooting of an algorithm
  84. ALL Turn on all logging
  85. ======= ===========
  86. The more verbose logging levels potentially include a stack-trace showing where the message occurred.
  87. * Use ``additivity="false"`` to prevent a message collected from one logger from being passed to the next.
  88. If you end up with double log messages chances check for this common misconfiguration.
  89. * The ``Root`` logger is last in the list and should collect everything.
  90. Example of console only logging
  91. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  92. Copy built-in logging profile and customize:
  93. 1. Copy an example such as :download:`QUIET_LOGGING.xml </../../../../src/main/src/main/resources/QUIET_LOGGING.xml>` to :file:`CONSOLE_LOGGING.xml`:
  94. 2. Update the initial part of :file:`CONSOLE_LOGGING.xml` with the new name:
  95. .. code-block:: xml
  96. <?xml version="1.0" encoding="UTF-8"?>
  97. <Configuration name="CONSOLE_LOGGING" status="fatal" dest="out">
  98. 3. Double check the Console appender configuration:
  99. .. code-block:: xml
  100. <Appenders>
  101. <Console name="stdout" target="SYSTEM_OUT">
  102. <PatternLayout pattern="%date{dd mmm HH:mm:ss} %-6level [%logger{2}] - %msg%n%"/>
  103. </Console>
  104. </Appenders>
  105. 3. Add appenders for geoserver (and any others you wish to track):
  106. .. code-block:: xml
  107. <Logger name="org.geoserver" level="ERROR" additivity="false">
  108. <AppenderRef ref="stdout"/>
  109. </Logger>
  110. <Logger name="org.vfny.geoserver" level="ERROR" additivity="false">
  111. <AppenderRef ref="stdout"/>
  112. </Logger>
  113. 4. Double check the root logger:
  114. .. code-block:: xml
  115. <Root level="FATAL">
  116. <AppenderRef ref="stdout"/>
  117. </Root>
  118. 5. This result provides minimal feedback to the console, only reporting when GeoServer encounters an error.
  119. .. _logging_location:
  120. Overriding the log location setup in the GeoServer configuration
  121. ----------------------------------------------------------------
  122. When setting up a cluster of GeoServer machines it is common to share a single data directory among all the cluster nodes.
  123. There is however a gotcha, all nodes would end up writing the logs in the same file, which would cause various kinds of troubles depending on the operating system file locking rules (a single server might be able to write, or all together in an uncontrolled manner resulting in an unreadable log file).
  124. A common choice could be to use the machine name as a distinction, setting values such as ``logs/geoserver_node1.log``, ``logs/geoserver_node2.log`` and so on: in this case all the log files would still be contained in the data directory and properly rotated, but each server would have its own separate log file to write on.
  125. In this case it is convenient to set a separate log location for each GeoServer node:
  126. * The ``GEOSERVER_LOG_LOCATION`` parameter can be set as system property, environment variables, or servlet context parameters::
  127. GEOSERVER_LOG_LOCATION=<the location of the file>
  128. This setting overrides global setting, and is applied to ``geoserverlogfile`` appender as a template for filename and filePattern.
  129. * This same effect may be obtained using Log4J `property substitution <https://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution>`__, where a wide range of `property lookups <https://logging.apache.org/log4j/2.x/manual/lookups.html>`__ are available.
  130. .. code-block:: xml
  131. <RollingFile name="geoserverlogfile">
  132. <filename>logs/geoserver-${hostName}.log</filename>
  133. <filePattern>logs/geoserver-${hostName}-%d{yyyy-MM-dd-HH}-%i.zip</filePattern>
  134. <PatternLayout pattern="%date{dd mmm HH:mm:ss} %-6level [%logger{2}] - %msg%n"/>
  135. <Policies>
  136. <OnStartupTriggeringPolicy />
  137. <SizeBasedTriggeringPolicy size="20 MB" />
  138. <TimeBasedTriggeringPolicy />
  139. </Policies>
  140. <DefaultRolloverStrategy max="9" fileIndex="min"/>
  141. </RollingFile>
  142. Where ``${hostName}`` is the current system host name or ip address.
  143. Forcing GeoServer to relinquish Log4J control
  144. ---------------------------------------------
  145. GeoServer internally overrides the Log4J configuration by using the current logging configuration as a template and applying the log location and standard output settings configured by the administrator.
  146. If you wish GeoServer not to override the normal Log4J behavior you can set the following parameter among the JVM system variables, environment variables, or servlet context parameters::
  147. RELINQUISH_LOG4J_CONTROL=true
  148. This can be combined with ``log4j2.configurationFile`` system property to `configure Log4J externally <https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration>`__ ::
  149. -DRELINQUISH_LOG4J_CONTROL=true -Dlog4j2.configurationFile=logging_configuration.xml
  150. Forcing GeoServer to use an alternate logging redirection
  151. ---------------------------------------------------------
  152. GeoServer uses the GeoTools logging framework, which in turn is based on Java Logging, but allowing to redirect all messages to an alternate framework of the user's choice.
  153. By default GeoServer setups a Log4J redirection, but it is possible to configure GeoServer to use plain Java Logging, or Commons Logging instead (support for other loggers is also possible by using some extra programming).
  154. If you wish to force GeoServer to use a different logging mechanism set the following parameters among the JVM system variables, environment variables, or servlet context parameters::
  155. GT2_LOGGING_REDIRECTION=[CommonsLogging,JavaLogging,Log4J,Log4J2,LogBack]
  156. RELINQUISH_LOG4J_CONTROL=true
  157. As noted in the example you'll also have to demand that GeoServer does not exert control over the Log4J configuration.
  158. Force java logging example
  159. ^^^^^^^^^^^^^^^^^^^^^^^^^^
  160. As an example to configure java logging::
  161. -DRELINQUISH_LOG4J_CONTROL=true -DGT2_LOGGING_REDIRECTION=JavaLogging -Djava.util.logging.config.file=logging.properties
  162. With java util logging configuration provided by :file:`logging.properties`:
  163. .. code-block:: properties
  164. handlers=java.util.logging.ConsoleHandler
  165. java.util.logging.ConsoleHandler.level = ALL
  166. java.util.logging.ConsoleHandler.formatter = org.geotools.util.logging.MonolineFormatter
  167. org.geotools.util.logging.MonolineFormatter.source = class:short
  168. .level= ALL
  169. org.geoserver.level = CONFIG
  170. org.vfny.geoserver.level = WARN
  171. org.geotools.level = WARN
  172. org.geotools.factory.level = WARN