Orientdb 简明教程

OrientDB - Logging

OrientDB 使用了与 Java 虚拟机捆绑的 Java 日志记录框架。OrientDB 的默认日志格式由 OLogFormatter 类进行管理。

OrientDB uses the Java Logging framework bundled with Java Virtual Machine. OrientDB’s default log format is managed by OLogFormatter class.

以下语句是对数记录命令的基本语法。

The following statement is the basic syntax of logging command.

<date> <level> <message> [<requester>]

以下是上文中选项的详细信息。

Following are the details about the options in the above syntax.

<date> − 它以以下格式来表示日期日志:yyyy-MM-dd HH:mm:ss:SSS。

<date> − It is the log date in the following format: yyyy-MM-dd HH:mm:ss:SSS.

<level> − 它是一个 5 个字符形式输出的日志记录级别。

<level> − It is the logging level as 5 chars output.

<message> − 它是日志文本,它可以具有任何大小。

<message> − It is the text of log, it can be of any size.

[<class>] − 它是一个被记录的 Java 类(可选)。

[<class>] − It is the Java class that is logged (optional).

受支持的级别是 JRE 类 java.util.logging.Level 中包含的级别。它们为:

Supported levels are those contained in the JRE class java.util.logging.Level. They are −

  1. SEVERE (highest value)

  2. WARNING

  3. INFO

  4. CONFIG

  5. FINE

  6. FINER

  7. FINEST (lowest value)

默认情况下,安装了两个日志记录器:

By default, two loggers are installed −

  1. Console, as the output of the shell/command prompt that starts the application/server. Can be changed by setting the variable ‘log.console.level’.

  2. File, as the output to the log files. Can be changed by setting the ‘log.file.level’.

Configure Logging

可以使用 Java 之后的日志策略和策略配置一个文件。

The logging strategies and policies can be configured using a file following the Java.

syntax − Java 日志记录配置。

syntax − Java Logging configuration.

Example

orientdb-server-log.properties 文件复制以下内容并将其置于 $ORIENTDB_HOME/config 文件中。

Copy the following content from orientdb-server-log.properties file and put it in the $ORIENTDB_HOME/config file.

# Specify the handlers to create in the root logger
# (all loggers are children of the root logger)
# The following creates two handlers
handlers = java.util.logging.ConsoleHandler, java.util.logging.FileHandler
# Set the default logging level for the root logger
.level = ALL

# Set the default logging level for new ConsoleHandler instances
java.util.logging.ConsoleHandler.level = INFO
# Set the default formatter for new ConsoleHandler instances
java.util.logging.ConsoleHandler.formatter =
   com.orientechnologies.common.log.OLogFormatter

# Set the default logging level for new FileHandler instances
java.util.logging.FileHandler.level = INFO
# Naming style for the output file
java.util.logging.FileHandler.pattern =../log/orient-server.log
# Set the default formatter for new FileHandler instances
java.util.logging.FileHandler.formatter = com.orientechnologies.common.log.OLogFormatter
# Limiting size of output file in bytes:
java.util.logging.FileHandler.limit = 10000000
# Number of output files to cycle through, by appending an
# integer to the base file name:
java.util.logging.FileHandler.count = 10

要告知 JVM 属性文件的位置,您需要设置“ java.util.logging.config.file ”系统属性。例如,使用以下命令 −

To tell the JVM where the properties file is placed, you need to set the "java.util.logging.config.file" system property to it. For example, use the following command −

$ java -Djava.util.logging.config.file=mylog.properties ...

Set the logging level

要更改日志记录级别而不修改日志记录配置,只要将“ log.console.level ”和“ log.file.level ”系统变量设置为请求的级别即可。

To change the logging level without modifying the logging configuration, just set the "log.console.level" and "log.file.level" system variables to the requested levels.

Logging at Startup

以下是通过不同方式在启动级别设置日志记录的步骤。

Following are the procedures to set logging at startup level in different ways.

In the Server Configuration

打开文件 orientdb-server-config.xml ,在 <properties> 部分的文件末尾添加或更新以下行 −

Open the file orientdb-server-config.xml and add or update these lines at the end of the file inside the <properties> section −

<entry value = "fine" name = "log.console.level" />
<entry value = "fine" name = "log.file.level" />

In Server.sh (or .bat) Script

使用 java 的 -D 参数将系统属性“ log.console.level ”和“ log.file.level ”设置为所需的级别。

Set the system property "log.console.level" and "log.file.level" to the levels you want using the -D parameter of java.

$ java -Dlog.console.level = FINE ...

Logging at Run-time

以下是通过不同方式在启动级别设置日志记录的步骤。

Following are the procedures to set logging at startup level in different ways.

By Using Java Code

可以使用 System.setProperty() API 在启动时设置系统变量。以下代码段是使用 Java 代码设置日志记录级别的语法。

The system variable can be set at startup using the System.setProperty() API. The following code snippet is the syntax to set logging level using Java code.

public void main(String[] args){
   System.setProperty("log.console.level", "FINE");
   ...
}

On Remote Server

针对 URL 执行 HTTP POST:/server/log.<type>/<level>,其中 −

Execute a HTTP POST against the URL: /server/log.<type>/<level>, where −

  1. <type> can be "console" or "file"

  2. <level> is one of the supported levels

Example

以下示例使用 cURL 对 OrientDB 服务器执行 HTTP POST 命令。使用了服务器的“root”用户和密码,请替换为自己的密码。

The following example uses cURL to execute a HTTP POST command against OrientDB Server. Server’s "root" user and password were used, replace with your own password.

启用控制台上的精细跟踪级别 −

Enable the finest tracing level to console −

curl -u root:root -X POST http://localhost:2480/server/log.console/FINEST

启用文件上的精细跟踪级别 −

Enable the finest tracing level to file −

curl -u root:root -X POST http://localhost:2480/server/log.file/FINEST