Используйте application.yml для настройки ведения журнала встроенного Tomcat в Spring Boot - PullRequest
0 голосов
/ 07 июня 2019

У меня есть несколько вопросов здесь (и я новичок в Spring Boot).

Существующая кодовая база нашего проекта использует YAML, но нет файла .properties, который я могу видеть где угодно.Мое чтение обычного учебника по Spring Boot использует файл .properties.

(1) Можно ли использовать application.yml вместо application.properties?

(2) Где находится каталог / файл по умолчанию, куда встроенный сервер Tomcat Spring Boot сбрасывает свои журналы?

Мне нужно изменить конфигурацию так, чтобы у нас был пользовательский каталог для дампа встроенного сервера Tomcatжурналы.Согласно здесь , оно должно быть

server.tomcat.basedir=my-tomcat
server.tomcat.accesslog.enabled=true
server.tomcat.accesslog.pattern=%t %a "%r" %s (%D ms)

Вот как это делается при использовании пути application.properties.

(3) Предполагая, что YAML может заменить .properties файл полностью, как я могу сделать вышеупомянутую конфигурацию в YAML?Нужно ли что-то редактировать в исходных файлах Java, чтобы конфигурация в YAML вступила в силу (т. Е. Журналы Tomcat попадают в определенный каталог, который я хочу)?

1 Ответ

1 голос
/ 07 июня 2019
  1. Да. Полностью

  2. Spring boot не входит в файл по умолчанию (насколько я знаю).

Независимо от того, используете ли вы yaml или файл свойств, весенняя загрузка использует эту конфигурацию для начальной загрузки приложения. Ниже здесь

# LOGGING
logging.config= # Location of the logging configuration file. For instance `classpath:logback.xml` for Logback
logging.exception-conversion-word=%wEx # Conversion word used when logging exceptions.
logging.file= # Log file name. For instance `myapp.log`
logging.level.*= # Log levels severity mapping. For instance `logging.level.org.springframework=DEBUG`
logging.path= # Location of the log file. For instance `/var/log`
logging.pattern.console= # Appender pattern for output to the console. Only supported with the default logback setup.
logging.pattern.file= # Appender pattern for output to the file. Only supported with the default logback setup.
logging.pattern.level= # Appender pattern for log level (default %5p). Only supported with the default logback setup.
logging.register-shutdown-hook=false # Register a shutdown hook for the logging system when it is initialized.

server.tomcat.accept-count= # Maximum queue length for incoming connection requests when all possible request processing threads are in use.
server.tomcat.accesslog.buffered=true # Buffer output such that it is only flushed periodically.
server.tomcat.accesslog.directory=logs # Directory in which log files are created. Can be relative to the tomcat base dir or absolute.
server.tomcat.accesslog.enabled=false # Enable access log.
server.tomcat.accesslog.file-date-format=.yyyy-MM-dd # Date format to place in log file name.
server.tomcat.accesslog.pattern=common # Format pattern for access logs.
server.tomcat.accesslog.prefix=access_log # Log file name prefix.
server.tomcat.accesslog.rename-on-rotate=false # Defer inclusion of the date stamp in the file name until rotate time.
server.tomcat.accesslog.request-attributes-enabled=false # Set request attributes for IP address, Hostname, protocol and port used for the request.
server.tomcat.accesslog.rotate=true # Enable access log rotation.
server.tomcat.accesslog.suffix=.log # Log file name suffix.
server.tomcat.additional-tld-skip-patterns= # Comma-separated list of additional patterns that match jars to ignore for TLD scanning.
server.tomcat.background-processor-delay=30 # Delay in seconds between the invocation of backgroundProcess methods.
server.tomcat.basedir= # Tomcat base directory. If not specified a temporary directory will be used.
server.tomcat.internal-proxies=10\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\
        192\\.168\\.\\d{1,3}\\.\\d{1,3}|\\
        169\\.254\\.\\d{1,3}\\.\\d{1,3}|\\
        127\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}|\\
        172\\.1[6-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
        172\\.2[0-9]{1}\\.\\d{1,3}\\.\\d{1,3}|\\
        172\\.3[0-1]{1}\\.\\d{1,3}\\.\\d{1,3} # regular expression matching trusted IP addresses.
server.tomcat.max-connections= # Maximum number of connections that the server will accept and process at any given time.
server.tomcat.max-http-post-size=0 # Maximum size in bytes of the HTTP post content.
server.tomcat.max-threads=0 # Maximum amount of worker threads.
server.tomcat.min-spare-threads=0 # Minimum amount of worker threads.
server.tomcat.port-header=X-Forwarded-Port # Name of the HTTP header used to override the original port value.
server.tomcat.protocol-header= # Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
server.tomcat.protocol-header-https-value=https # Value of the protocol header that indicates that the incoming request uses SSL.
server.tomcat.redirect-context-root= # Whether requests to the context root should be redirected by appending a / to the path.
server.tomcat.remote-ip-header= # Name of the http header from which the remote ip is extracted. For instance `X-FORWARDED-FOR`
server.tomcat.uri-encoding=UTF-8 # Character encoding to use to decode the URI.
  1. Да. Вы можете изменить их на YML. Все, что вам нужно, это заменить файл свойств файлом yml. Вы могли бы даже иметь оба в своем рабочем пространстве (весна смотрит и на application.properties и application.yml) Вы можете сделать преобразование вручную или даже с помощью плагинов .

Простая строка типа

logging.level.netpl.com = DEBUG

изменяется на

logging:
  level:
    netpl.com: DEBUG
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...