apache-ignite
157 строк · 6.3 Кб
1// Licensed to the Apache Software Foundation (ASF) under one or more
2// contributor license agreements. See the NOTICE file distributed with
3// this work for additional information regarding copyright ownership.
4// The ASF licenses this file to You under the Apache License, Version 2.0
5// (the "License"); you may not use this file except in compliance with
6// the License. You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15= Configuring Logging
16
17== Overview
18
19Ignite supports a number of logging libraries and frameworks:
20
21- JUL (default),
22- Log4j2,
23- JCL,
24- SLF4J.
25
26This section shows you how to set up the logger.
27
28When a node starts, it outputs start-up information to the console, including the information about the configured logging library. Each logging library has its own configuration parameters and should be set up according to its official documentation. Besides library-specific configuration, there is a number of system properties that allow you to tune logging. These properties are presented in the following table.
29
30
31[cols="1,3,1",opts="stretch,header"]
32|===
33| System Property | Description | Default Value
34| `IGNITE_LOG_INSTANCE_NAME` | If the property is set, Ignite includes its instance name in log messages. | Not set
35| `IGNITE_QUIET` | Set to `false` to disable the quiet mode and enable the verbose mode.
36In the verbose mode, the node logs a lot more information. | `true`
37| `IGNITE_LOG_DIR` | The directory where Ignite writes log files. | `$IGNITE_HOME/
38work/log`
39| `IGNITE_DUMP_THREADS_ON_FAILURE` | Set to `true` to output thread dumps to the log when a critical error is caught. | `true`
40|===
41
42
43== Default Logging
44By default, Ignite uses the java.util.logging (JUL) framework.
45If you start Ignite using the `ignite.sh|bat` script from the distribution package, Ignite uses `$IGNITE_HOME/config/java.util.logging.properties` as the default logging configuration file and outputs all messages to log files in the `$IGNITE_HOME/work/log` directory.
46You can override the default logging directory by specifying the `IGNITE_LOG_DIR` system property.
47
48If you use Ignite as a library in your application, the default logging configuration includes only console handler at INFO level.
49You can provide a custom configuration file via the `java.util.logging.config.file` system property.
50
51== Using Log4j2
52NOTE: Before using Log4j2, enable the link:setup#enabling-modules[ignite-log4j2] module.
53
54To enable Log4j2 logger, set the `gridLogger` property of `IgniteConfiguration`, as shown below:
55
56[tabs]
57--
58tab:XML[]
59[source,xml]
60----
61include::code-snippets/xml/log4j2.xml[tags=log4j2;!discovery, indent=0]
62----
63
64tab:Java[]
65[source,java]
66----
67include::{javaFile}[tag=log4j2, indent=0]
68----
69
70tab:.NET[unsupported]
71
72
73tab:C++[unsupported]
74--
75
76In the above example, the path to `log4j2-config.xml` can be either an absolute path, a local path relative to META-INF in classpath or to `IGNITE_HOME`. An example log4j2 configuration file can be found in the distribution package (`$IGNITE_HOME/config/ignite-log4j.xml`).
77
78NOTE: Log4j2 supports runtime reconfiguration, i.e. changes in the configuration file is applied without the need to restart the application.
79
80NOTE: `log4j2-config.xml` enables colorization of console output by default. This feature works out of the box on many operating systems, except for Windows. If you want to enable this feature on Windows, please follow the https://logging.apache.org/log4j/2.x/manual/layouts.html#ANSI_Styling_on_Windows[official log4j2 instructions].
81
82== Using JCL
83NOTE: Before using JCL, enable the link:setup#enabling-modules[ignite-jcl] module.
84
85NOTE: Note that JCL simply forwards logging messages to an underlying logging system, which needs to be properly configured. Refer to the link:https://commons.apache.org/proper/commons-logging/guide.html#Configuration[JCL official documentation] for more information. For example, if you want to use Log4j2, make sure you add the required libraries to your classpath.
86
87To enable Log4j2 logger, set the `gridLogger` property of `IgniteConfiguration`, as shown below:
88
89[tabs]
90--
91
92tab:XML[]
93[source,xml]
94----
95include::code-snippets/xml/jcl.xml[tags=jcl;!discovery, indent=0]
96----
97
98tab:Java[]
99[source,java]
100----
101include::{javaFile}[tag=jcl, indent=0]
102----
103
104tab:.NET[unsupported]
105tab:C++[unsupported]
106--
107
108== Using SLF4J
109
110NOTE: Before using SLF4J, enable the link:setup#enabling-modules[ignite-slf4j] module.
111
112To enable the SLF4J logger, set the `gridLogger` property of `IgniteConfiguration`, as shown below:
113
114[tabs]
115--
116tab:XML[]
117[source,xml]
118----
119include::code-snippets/xml/slf4j.xml[tags=slf4j;!discovery, indent=0]
120----
121
122tab:Java[]
123[source,java]
124----
125include::{javaFile}[tag=slf4j, indent=0]
126----
127
128tab:.NET[unsupported]
129
130tab:C++[unsupported]
131--
132
133Refer to the link:https://www.slf4j.org/docs.html[SLF4J user manual] for more information.
134
135== Suppressing Sensitive Information
136
137Logs can include the content of cache entries, system properties, startup options, etc.
138In some cases, those can contain sensitive information.
139You can prevent such information from being written to the log by setting the `IGNITE_TO_STRING_INCLUDE_SENSITIVE` system property to `false`.
140
141[source, shell]
142----
143./ignite.sh -J-DIGNITE_TO_STRING_INCLUDE_SENSITIVE=false
144----
145
146See link:starting-nodes#setting-jvm-options[Setting JVM Options] to learn about different ways to set system properties.
147
148== Logging Configuration Example
149
150The following steps guide you through the process of configuring logging. This should be suitable for most cases.
151
152. To enable Log4j2, follow the instructions provided in the corresponding section above.
153. If you use the default configuration file (`ignite-log4j.xml`), uncomment the CONSOLE appender.
154. In the log4j2 configuration file, set the path to the log file. The default location is `${IGNITE_HOME}/work/log/ignite.log`.
155. Start the nodes in verbose mode:
156- If you use `ignite.sh` to start nodes, specify the `-v` option.
157- If you start nodes from Java code, use the `IGNITE_QUIET=false` system variable.
158
159
160