多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php框架 > 框架設計 > Spring Boot 2.0.0參考手冊_中英文對照_Part IV_26

Spring Boot 2.0.0參考手冊_中英文對照_Part IV_26

來源:程序員人生   發布時間:2017-03-04 08:52:40 閱讀次數:5860次

文章作者:Tyan
博客:noahsnail.com  |  CSDN  |  簡書

26. Logging

Spring Boot uses Commons Logging for all internal logging, but leaves the underlying log implementation open. Default configurations are provided for Java Util Logging, Log4J2 and Logback. In each case loggers are pre-configured to use console output with optional file output also available.

Spring Boot所有的內部日志都采取Commons Logging,但開放了底層的日志實現。提供了對Java Util Logging,Log4J2和Logback的默許實現。在每一個logger中都預先配置使用控制臺作為輸出,同時也可用可選的文件輸出。

By default, If you use the ‘Starters’, Logback will be used for logging. Appropriate Logback routing is also included to ensure that dependent libraries that use Java Util Logging, Commons Logging, Log4J or SLF4J will all work correctly.

默許情況下,如果使用Starters,Logback將作為日志。也要包括恰當的Logback規則來保證依賴庫使用Java Util Logging,Commons Logging,Log4J或SLF4J都能正確工作。

There are a lot of logging frameworks available for Java. Don’t worry if the above list seems confusing. Generally you won’t need to change your logging dependencies and the Spring Boot defaults will work just fine.

 

在Java中有許多日志框架可用。沒必要擔心上面的列表看起來有點混亂。通常情況下你不需要改變你的日志依賴,Spring Boot默許情況下能很好的工作。

26.1 Log format

The default log output from Spring Boot looks like this:

Spring Boot默許的日志輸出看起來以下:

2014-03-05 10:57:51.112  INFO 45469 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/7.0.52
2014-03-05 10:57:51.253  INFO 45469 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2014-03-05 10:57:51.253  INFO 45469 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1358 ms
2014-03-05 10:57:51.698  INFO 45469 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean        : Mapping servlet: 'dispatcherServlet' to [/]
2014-03-05 10:57:51.702  INFO 45469 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean  : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]

The following items are output:

  • Date and Time?—?Millisecond precision and easily sortable.

  • Log Level?—?ERROR, WARN, INFO, DEBUG or TRACE.

  • Process ID.

  • A --- separator to distinguish the start of actual log messages.

  • Thread name?—?Enclosed in square brackets (may be truncated for console output).

  • Logger name?—?This is usually the source class name (often abbreviated).

  • The log message.

下面的是輸出項:

  • Date and Time?—?精確到毫秒且容易排序。

  • Log級別?—?ERROR,WARN,INFO,DEBUG或TRACE。

  • 進程ID。

  • ---分隔符來辨別真實的日志信息的開始。

  • 線程名稱?—?用方括號包裹(在控制臺輸出中常常是縮減的)。

  • Logger名稱?—?源類名(常常是簡寫)。

  • 日志信息。

Logback does not have a FATAL level (it is mapped to ERROR)

 

Logback沒有FATAL級別(它映照到ERROR)。

26.2 Console output

The default log configuration will echo messages to the console as they are written. By default ERROR, WARN and INFO level messages are logged. You can also enable a “debug” mode by starting your application with a --debug flag.

默許的日志配置會將信息輸出到控制臺。默許情況下會輸出ERROR,WARNINFO級別的信息。你也能夠通過--debug來啟動你的利用,從而啟用“debug”模式。

$ java -jar myapp.jar --debug

you can also specify debug=true in your application.properties.

 

你也能夠在application.properties指定debug=true

When the debug mode is enabled, a selection of core loggers (embedded container, Hibernate and Spring Boot) are configured to output more information. Enabling the debug mode does not configure your application to log all messages with DEBUG level.

當啟用調試模式時,配置選擇的核心logger(嵌入式容器,Hibernate和Spring Boot)來輸出更多的信息。啟動調試模式不會將你的利用配置成輸出所有DEBUG級別的信息。

Alternatively, you can enable a “trace” mode by starting your application with a --trace flag (or trace=true in your application.properties). This will enable trace logging for a selection of core loggers (embedded container, Hibernate schema generation and the whole Spring portfolio).

或,你可以用--trace標記(或在application.properties中添加trace=true)啟動你的利用,從而啟用“trace”模式。這將在選擇的核心logger中(嵌入式容器,Hibernate模式生成和全部Spring文件夾)啟用trace日志。

26.2.1 Color-coded output

If your terminal supports ANSI, color output will be used to aid readability. You can set spring.output.ansi.enabled to a supported value to override the auto detection.

如果你的終端支持ANSI,色彩輸出可以用來輔助瀏覽。你可以為spring.output.ansi.enabled設置1個支持值來覆蓋自動檢測。

Color coding is configured using the %clr conversion word. In its simplest form the converter will color the output according to the log level, for example:

色彩編碼用%clr轉換詞來配置。最簡單的情勢是根據日志級別進行色彩輸出,例如:

%clr(%5p)

The mapping of log level to a color is as follows:

日志級別與色彩的映照以下:

Level Color
FATAL Red
ERROR Red
WARN Yellow
INFO Green
DEBUG Green
TRACE Green

Alternatively, you can specify the color or style that should be used by providing it as an option to the conversion. For example, to make the text yellow:

或,你可以通過在轉換器中提供選項來指定應當試用的色彩或風格。例如,為了使文本顯示黃色:

%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){yellow}

The following colors and styles are supported:

支持下面的色彩和風格:

  • blue
  • cyan
  • faint
  • green
  • magenta
  • red
  • yellow

26.3 File output

By default, Spring Boot will only log to the console and will not write log files. If you want to write log files in addition to the console output you need to set a logging.file or logging.path property (for example in your application.properties).

默許情況下,Spring Boot只能輸出日志到控制臺,不會寫入日志文件。如果你想除控制臺以外還想寫日志文件,你需要設置logging.filelogging.path屬性(例如,在你的application.properties)。

The following table shows how the logging.* properties can be used together:

下表顯示了logging.*屬性怎樣在1起使用:

Table 26.1. Logging properties

logging.file logging.path Example Description
(none (none) Console only logging.
Specific file (none) my.log Writes to the specified log file. Names can be an exact location or relative to the current directory.
(none) Specific directory /var/log Writes spring.log to the specified directory. Names can be an exact location or relative to the current directory.

表 26.1. Logging屬性

logging.file logging.path Example Description
(none (none) 只輸出到控制臺
指定文件 (none) my.log 寫入指定的日志文件。名字可以是1個絕對位置或相對當前目錄。
(none) Specific directory /var/log spring.log到1個指定的目錄。名字可以是1個絕對位置或相對當前目錄。

Log files will rotate when they reach 10 MB and as with console output, ERROR, WARN and INFO level messages are logged by default.

當日志文件到達10M光陰志文件將循環,至于控制臺輸出,默許情況下只輸出ERROR,WARNINFO級別的信息。

The logging system is initialized early in the application lifecycle and as such logging properties will not be found in property files loaded via @PropertySource annotations.

 

日志系統在利用程序的生命周期初期進行初始化,一樣地,通過@PropertySource注解加載的屬性文件中將不會發現日志屬性。

 

Logging properties are independent of the actual logging infrastructure. As a result, specific configuration keys (such as logback.configurationFile for Logback) are not managed by spring Boot.

 

日志屬性獨立于真實的日志基礎架構以外。因此,Spring Boot不管理特定的配置主鍵(例如Logback的logback.configurationFile)。

26.4 Log Levels

All the supported logging systems can have the logger levels set in the Spring Environment (so for example in application.properties) using ‘logging.level.*=LEVEL’ where ‘LEVEL’ is one of TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF. The root logger can be configured using logging.level.root. Example application.properties:

Spring支持的所有日志系統都可以在Spring的Environment中設置日志級別(例如在application.properties設置),使用logging.level.*=LEVEL進行設置,LEVEL是TRACE,DEBUG,INFO,WARN,ERROR,FATAL,OFF中的1個。root日志器可以用logging.level.root來配置。例如在application.properties中:

logging.level.root=WARN
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR

By default Spring Boot remaps Thymeleaf INFO messages so that they are logged at DEBUG level. This helps to reduce noise in the standard log output. See LevelRemappingAppender for details of how you can apply remapping in your own configuration.

 

默許情況下Spring Boot重新映照Thymeleaf的INFO信息,為了它們能在DEBUG級別進行輸出。這能幫助減少標準日志輸出中的噪聲。關于怎樣在你自己的配置中使用重新映照的更多細節請看LevelRemappingAppender。

26.5 Custom log configuration

The various logging systems can be activated by including the appropriate libraries on the classpath, and further customized by providing a suitable configuration file in the root of the classpath, or in a location specified by the Spring Environment property logging.config.

在類路徑中通過包括恰當的庫可以激活各種日志系統,在類路徑的根目錄中提供1個適合的配置文件可以對日志系統進行更進1步的定制,或將配置文件放在Spring Environmentlogging.config屬性中指定的位置。

You can force Spring Boot to use a particular logging system using the org.springframework.boot.logging.LoggingSystem system property. The value should be the fully-qualified class name of a LoggingSystem implementation. You can also disable Spring Boot’s logging configuration entirely by using a value of none.

你可使用系統屬性org.springframework.boot.logging.LoggingSystem來強迫Spring Boot使用1個特定的日志系統。它的值應當是全限定類名的LoggingSystem實現。你也能夠通過使用值none來完全禁用Spring Boot的日志配置。

Since logging is initialized before the ApplicationContext is created, it isn’t possible to control logging from @PropertySources in Spring @Configuration files. System properties and the conventional Spring Boot external configuration files work just fine.

 

由于日志是在ApplicationContext創建之前初始化,因此不可能從Spring @Configuration文件中的@PropertySources來控制日志。系統屬性和傳統的Spring Boot外部配置文件可以工作的很好。

Depending on your logging system, the following files will be loaded:

根據你的日志系統,將會加載下面的文件:

Logging System Customization
Logback logback-spring.xml, logback-spring.groovy, logback.xml or logback.groovy
Log4j2 log4j2-spring.xml or log4j2.xml
JDK (Java Util Logging) logging.properties

When possible we recommend that you use the -spring variants for your logging configuration (for example logback-spring.xml rather than logback.xml). If you use standard configuration locations, Spring cannot completely control log initialization.

 

我們建議你盡量的使用-spring變種來進行日志配置(例如,logback-spring.xml而不是logback.xml)。如果你在使用標準的配置路徑,Spring不能完全控制日志的初始化。

 

There are known classloading issues with Java Util Logging that cause problems when running from an ‘executable jar’. We recommend that you avoid it if at all possible.

 

在Java Java Util Logging中存在類加載問題,當從executable jar運行時會引發問題。我們建議你盡量的避免它。

To help with the customization some other properties are transferred from the Spring Environment to System properties:

為了幫助定制1些其它屬性,從Spring Environment中轉移到系統屬性中:

Spring Environment System Property Comments
logging.exception-conversion-word LOG_EXCEPTION_CONVERSION_WORD The conversion word that’s used when logging exceptions.
logging.file LOG_FILE Used in default log configuration if defined.
logging.path LOG_PATH Used in default log configuration if defined.
logging.pattern.console CONSOLE_LOG_PATTERN The log pattern to use on the console (stdout). (Only supported with the default logback setup.)
logging.pattern.file FILE_LOG_PATTERN The log pattern to use in a file (if LOG_FILE enabled). (Only supported with the default logback setup.)
logging.pattern.level LOG_LEVEL_PATTERN The format to use to render the log level (default %5p). (Only supported with the default logback setup.)
PID PID The current process ID (discovered if possible and when not already defined as an OS environment variable).
Spring Environment System Property Comments
logging.exception-conversion-word LOG_EXCEPTION_CONVERSION_WORD 當日志出現異常時會用到這個轉換詞。
logging.file LOG_FILE 如果定義了,會在默許的日志配置中使用。
logging.path LOG_PATH 如果定義了,會在默許的日志配置中使用。
logging.pattern.console CONSOLE_LOG_PATTERN 用在控制臺中的日志模式(stdout)。(只支持默許的Logback設置。)
logging.pattern.file FILE_LOG_PATTERN 用在文件中的日志模式 (如果啟用LOG_FILE)。(只支持默許的Logback設置。)
logging.pattern.level LOG_LEVEL_PATTERN 這類模式用來實行日志級別(默許%5p)。 (只支持默許的Logback設置。)
PID PID 當前的進程ID

All the logging systems supported can consult System properties when parsing their configuration files. See the default configurations in spring-boot.jar for examples.

當轉換配置文件時,所有的日志系統都支持查詢系統屬性。例如spring-boot.jar的默許配置。

If you want to use a placeholder in a logging property, you should use Spring Boot’s syntax and not the syntax of the underlying framework. Notably, if you’re using Logback, you should use : as the delimiter between a property name and its default value and not :-.

 

如果你在日志屬性中想使用占位符,你應當試用Spring Boot的語法而不是底層框架的語法。特別是,如果你在使用Logback,你應當使用:作為屬性名和默許值之間的分隔符,而不是:-

 

You can add MDC and other ad-hoc content to log lines by overriding only the LOG_LEVEL_PATTERN (or logging.pattern.level with Logback). For example, if you use logging.pattern.level=user:%X{user} %5p then the default log format will contain an MDC entry for “user” if it exists, e.g.

2015-09⑶0 12:30:04.031 user:juergen INFO 22174 --- [  nio⑻080-exec-0] demo.Controller
Handling authenticated request

 

你可以通太重寫LOG_LEVEL_PATTERN(或Logback中的logging.pattern.level)來添加MDC和其它的專門內容來日志行中。例如,你可使用logging.pattern.level=user:%X{user} %5p,默許的日志情勢將包括MDC輸入,如果它存在的話,例如:

2015-09⑶0 12:30:04.031 user:juergen INFO 22174 --- [  nio⑻080-exec-0] demo.Controller
Handling authenticated request

26.6 Logback extensions

Spring Boot includes a number of extensions to Logback which can help with advanced configuration. You can use these extensions in your logback-spring.xml configuration file.

Spring Boot包括許多Logback的擴大,這有助于進行更高級的配置。你可以在你的logback-spring.xml配置文件中使用這些擴大。

You cannot use extensions in the standard logback.xml configuration file since it’s loaded too early. You need to either use logback-spring.xml or define a logging.config property.

 

你不能在標準的logback.xml配置文件中使用擴大,由于它加載的太早了。你需要使用logback-spring.xml或定義logging.config屬性。

26.6.1 Profile-specific configuration

The <springProfile> tag allows you to optionally include or exclude sections of configuration based on the active Spring profiles. Profile sections are supported anywhere within the <configuration> element. Use the name attribute to specify which profile accepts the configuration. Multiple profiles can be specified using a comma-separated list.

<springProfile>標簽允許你自由的包括或排除基于激活的Spring profiles的配置的1部份。在<configuration>元素的任何地方都支持Profile部份。使用name屬性來指定哪個profile接受配置。多個profiles可以用1個逗號分隔的列表來指定。

<springProfile name="staging">
    <!-- configuration to be enabled when the "staging" profile is active -->
</springProfile>

<springProfile name="dev, staging">
    <!-- configuration to be enabled when the "dev" or "staging" profiles are active -->
</springProfile>

<springProfile name="!production">
    <!-- configuration to be enabled when the "production" profile is not active -->
</springProfile>

26.6.2 Environment properties

The <springProperty> tag allows you to surface properties from the Spring Environment for use within Logback. This can be useful if you want to access values from your application.properties file in your logback configuration. The tag works in a similar way to Logback’s standard <property> tag, but rather than specifying a direct value you specify the source of the property (from the Environment). You can use the scope attribute if you need to store the property somewhere other than in local scope. If you need a fallback value in case the property is not set in the Environment, you can use the defaultValue attribute.

<springProperty>標簽允許你在Logback使用從Spring Environment取得的屬性。如果你想在你的Logback配置中訪問application.properties文件中的屬性,這是非常有用的。這個標簽與Logback的標準<property>標簽的作用方式類似,但不是為你指定的source屬性(從Environment中)指定1個直接的value。如果你需要在某個地方而不是在local作用域中存儲屬性,你可使用scope屬性。如果你需要1個備用值以防屬性沒有在Environment中設置,你可使用defaultValue屬性。

<springProperty scope="context" name="fluentHost" source="myapp.fluentd.host"
        defaultValue="localhost"/>
<appender name="FLUENT" class="ch.qos.logback.more.appenders.DataFluentAppender">
    <remoteHost>${fluentHost}</remoteHost>
    ...
</appender>

The RelaxedPropertyResolver is used to access Environment properties. If specify the source in dashed notation (my-property-name) all the relaxed variations will be tried (myPropertyName, MY_PROPERTY_NAME etc).

 

RelaxedPropertyResolver是用來訪問Environment屬性。如果在破折號符號中指定了source,則會嘗試所有的不嚴格的變種(myPropertyName,MY_PROPERTY_NAME等)。

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 久久视频精品36线视频在线观看 | 久久伊人免费视频 | 精品成人一区二区三区免费视频 | 亚洲国产天堂久久综合 | 色婷婷伊人 | 亚州男人天堂 | 欧美一区二区三区精品 | 五月婷婷视频在线 | 亚洲图片 自拍偷拍 | 噜噜噜私人影院 | 正在播放国产露脸做91 | 五月天在线播放视频在线 | 欧美日本激情 | 顶级欧美做受xxx000 | 欧美一级毛片久久精品 | 国产精品成人不卡在线观看 | 亚洲精品网站在线观看不卡无广告 | 老司机免费福利视频 | 亚洲一区二区在线成人 | 91九色精品国产 | 最近的免费中文字幕视频 | 国产福利在线播放 | 久久精品亚洲精品国产欧美 | 欧美另类xxxx图片 | 国产午夜人做人免费视频中文 | 自拍三区播 | 最近高清中文在线观看国语字幕7 | 国产欧美日本在线 | 国产精品jizz在线观看免费 | 看一级黄色毛片 | 国产 福利 在线 | 最近中文字幕3 | 久久国产亚洲欧美日韩精品 | 精品1州区2区3区4区产品乱码 | 伊人院| 欧美在线aa | 国产成人+综合亚洲+天堂 | 中文字幕最新 | 全亚洲最大的免费影院 | 国内精品视频成人一区二区 | 男女小视频在线观看 |