YAML based log rolling in spring 2.6.7 not triggering - spring

First, I referenced this thread and this documentation, and various articles like this one, but I'm obviously missing something.
I have tried various combinations. What I currently have is
logging:
level.root: trace
file:
name: ${PWD}/logs/spring.log
max-size : 1MB
max-history : 3
total-size-cap : 2MB
pattern:
file : "%d{yyyy-MM-dd HH:mm:ss} %-5level [%thread] [%class{36}] - %msg%n"
console : ${logging.pattern.file}
rolling-file-name : ${PWD}/logs/archive.%i.log
also tried
logging.logback.rollingpolicy:
file-name-pattern : ${PWD}/logs/${spring.application.name}.%i.log
max-file-size : 2MB
With root log level set to TRACE the logs go over 2MB almost immediately.
It works fine when we use a separate XML file to configure logback, but we're trying to remove the need.

This is the best yaml logback configuration that's working for me with lot of difficulties:
logging:
file:
path: /Volumes/Local Disk/logs
name: spring.log
logback:
rollingpolicy:
total-size-cap: 1MB
max-history: 3
max-file-size: 1MB
file-name-pattern: /Volumes/Local Disk/logs/spring.%d{yyyy-MM-dd}.%d{HH:mm:ss.SSS}.%i.log.gz
level:
root: trace
Screenshot:

Related

Spring Boot multiple log4j appenders in application.yml file

I need 2 different logging patterns in my SpringBoot application.
let's say:
first_pattern -- for root logger (INFO level)
second_pattern -- for packages com.stackoverflow.engine.core (DEBUG level)
Both packages must log to stdout.
Is it possible to configure that in application.yml ?
(not in XML or property files but in YML)
Many Thanks!
No, you can't obtain such a configuration using Spring configuration alone. Spring Boot supports only a couple of configuration options common to all logging frameworks (cf. documentation).
If you want a more complex configuration, you need to use the native configuration format of the specific logging framework you are using.
If you are using Log4j 2.x, you can extend the default Spring configuration and save it as log4j2-spring.yml in your classpath:
Configuration:
packages: org.springframework.boot.logging.log4j2
properties:
property:
- name: LOG_EXCEPTION_CONVERSION_WORD
value: "%xwEx"
- name: LOG_LEVEL_PATTERN
value: "%5p"
- name: LOG_DATEFORMAT_PATTERN
value: "yyyy-MM-dd HH:mm:ss.SSS"
- name: CONSOLE_LOG_PATTERN
value: "%clr{%d{${sys:LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${sys:LOG_LEVEL_PATTERN}} %clr{%pid}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}"
- name: FILE_LOG_PATTERN
value: "%d{${LOG_DATEFORMAT_PATTERN}} ${LOG_LEVEL_PATTERN} %pid --- [%t] %-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}"
appenders:
appender:
- name: Console
type: Console
PatternLayout:
pattern: "${sys:CONSOLE_LOG_PATTERN}"
- name: Console2
type: Console
PatternLayout:
pattern: "Pattern2 %d %p %c{1.} [%t] %m%n"
loggers:
logger:
- name: com.stackoverflow.engine.core
level: DEBUG
additivity: false
AppenderRef:
- ref: Console2
root:
level: INFO
AppenderRef:
- ref: Console
Remark: to use the YAML format, you need to add jackson-datatype-yaml to your dependencies. If you use Maven add:
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<!-- version managed by Spring Boot -->
</dependency>
The spring property logging.config could be quite useful in your case. By using this property you could easily provide different configurations depending on the profile or the environment.
You still need to define the patterns by using log4j2 configuration files as allready said by Piotr P. Karwasz but you can easily switch between different setups.

Filebeat index is getting created but with 0 documents

I am trying to index my custom log file using filebeat. I am successfully running filebeat with pre-built modules like mysql, nginx etc. But when I actually try to use it with my application specific log file, index is created with 0 documents.
I could not find anywhere in the filebeats document if there are any specific steps need to be taken to ensure indexing takes place for the custom log files.
I did not get any error when I setup filebeats or run filebeats post setup.
Below is the filebeat.yml:
filebeat.inputs:
- type: log
enabled: true
paths:
- /Applications/MAMP/htdocs/247around-adminp-aws/application/logs/log-2020-12-21.log
include_lines: ['^INFO', '^ERROR']
fields:
app_id: crm
filebeat.config.modules:
setup.template.settings:
index.number_of_shards: 1
path: ${path.config}/modules.d/*.yml
setup.kibana:
output.elasticsearch:
hosts: ["localhost:9200"]
processors:
As can be seen, it is majorly default .yml file with very minor changes.
My custom log file log-2020-12-21.php is:
INFO - 2020-12-21 15:10:26 --> index Logging details have been captured for employee. Details are : Array
INFO - 2020-12-21 15:10:36 --> editpartner partner_id:1
INFO - 2020-12-21 15:10:36 --> SELECT DISTINCT service_id, brand, active
ERROR - 2020-12-21 15:10:36 --> Query error: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'boloaaka.collateral.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
INFO - 2020-12-21 15:10:36 --> Database Error: A Database Error Occurred<br/>Array
ERROR - 2020-12-21 15:10:54 --> Query error: Expression #5 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'boloaaka.service_centres.district' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
INFO - 2020-12-21 15:10:54 --> Database Error: A Database Error Occurred<br/>Array
INFO - 2020-12-21 23:53:21 --> Loginindex
INFO - 2020-12-21 23:54:50 --> Loginindex
INFO - 2020-12-21 23:55:42 --> Loginindex
INFO - 2020-12-21 23:56:24 --> Loginindex
Index file is getting created with 0 documents:
Log file showing logs for filebeats setup and filebeats running:
https://pastebin.com/TK6uYXuq
Please help:
Why there are no error messages if something is wrong because of which documents are not getting indexed? I should be getting some error if things are not right.
How should I index my log file?
Where should I add pattern for my log file like key-value pair which would help me in searching the documents for relevant values later on?
Thanks for your help.
In your filebeat configuration, are you sure you are referring to the exact file where your logs are stored? Your 'paths' in filebeat.yml is referring to a .log file extension while the custom log file you've pasted is log-2020-12-21.php Try changing your paths to match this .php extension instead.
If filebeat correctly picks this file up, you could see something like the code below in your filebeat logs
INFO log/harvester.go:287 Harvester started for file: /Applications/MAMP/htdocs/247around-adminp-aws/application/logs/log-2020-12-21.php

Spring boot logging file name

🐞 Bug report ??
image
logging:
level:
com.zaxxer.hikari: DEBUG
org.springframework: INFO
org.kafka.test: TRACE
file: "logs/%d{yyyy-MM-dd HH_mm_ss} pid-${PID}.log"
pattern.console: "%d{HH:mm:ss} - %msg%n"
Hello.
please help with the file name.
The time format does not work well.
I expected to see 1 file named "2020-02-07 10_38_40 pid-17996.log"
I got 2 files and the file names are bad.
Please do not advise using logback-spring.xml
I configure logs through .yml

Spring Boot: Log to multiple files. All DEBUGs to debug.log, all INFOs to info.log

I'm using logging provided by Spring Boot in an application.yml like this:
logging:
file: log/info.log
level.com.mycompany.app: INFO
What I actually want is:
1) Log every DEBUG message from our application (com.mycompany.app) to debug.log,
(optional: every INFO message from the whole app / ROOT to debug.log, too)
2) log every INFO message from the whole app / ROOT to info.log
So in pseudo code, it should look like this:
logging:
level: DEBUG
file: debug.log
com.mycompany.app: DEBUG
level:
ROOT: INFO
file: debug.log
level:
ROOT: INFO
file: info.log
How can I achieve this? Please note, we're using SLF4j, not logback (I've read in other threads about logback for writing to multiple files).
Regards,
Bernhard

I am trying to set maxFileSize but it is not honored

I am developing an application utilizing JHipster. I have added the following to my application-dev.yml file:
spring:
profiles:
active: dev
multipart:
maxFileSize: -1
But I am still getting an error when I try to try to upload a file > 1MB:
Caused by: org.apache.tomcat.util.http.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (20663006) exceeds the configured maximum (10485760)
What am I missing? It seems this should be pretty straight forward.
Update 1
I un-nested it from spring config as suggested by Andy, but still got the error. Updated yml file:
server:
port: 8080
multipart:
maxFileSize: -1
spring:
profiles:
active: dev
datasource: ...
Update 2
Ran into this issue again on newer version of Sprint Boot and had to change to this:
spring:
http:
multipart:
max-file-size: 30MB
max-request-size: 30MB
In addition to configuring max file size, you may also need to configure max request size if you have a single file that's greater than 10MB or you want to upload multiple files in the same request with sizes that total more than 10MB.
The exact properties that need to be used depend on the version of Spring Boot that you are using as they changed in 1.4:
Spring Boot 1.3.x and earlier
multipart.maxFileSize
multipart.maxRequestSize
Spring Boot 1.4.x and 1.5.x
spring.http.multipart.maxFileSize
spring.http.multipart.maxRequestSize
Spring Boot 2.x
spring.servlet.multipart.maxFileSize
spring.servlet.multipart.maxRequestSize
for spring-boot 2.x, file: src/main/resources/application.yaml
spring:
servlet:
multipart:
max-file-size: -1
max-request-size: -1
Like Emilio Garcia mentioned, it has to be placed under spring.http.multipart and not multipart alone. I have recently upgraded a project from Spring Boot 1.3.5 to 1.4.1 and ran into the issue that multipart.maxFileSize is no longer honored .. it appears to have changed.
As stated here, you need to use these properties:
spring.http.multipart.max-file-size=128KB
spring.http.multipart.max-request-size=128KB
Grails 3’s default file size is 128000.
If You Want to increase the size go to application.yml of your project ,as i want to increase the size to 25 megabyte. the file size is set in bytes , as we see above max size is 128000 bytes. so i have to convert 25 mb into bytes.
25 mb * 1024 kb * 1024 b = 26.214.400 bytes
Now goo
/grails-app/conf/application.yml
and write down these lines properly
grails:
controllers:
upload:
maxFileSize: 26214400
maxRequestSize: 26214400
Now clean the application and run again , it will work wonders. Thanks
Adding below to configuration worked for me:
ribbon:
ReadTimeout: 20000
ConnectTimeout: 20000
Read Timeout on Request
For configuring CommonsMultipartResolver with external tomcat
Define a bean with bean name as MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME
As the default spring boot's default MultipartFilter looks for resolver with default bean name.
#Bean(name = MultipartFilter.DEFAULT_MULTIPART_RESOLVER_BEAN_NAME)
protected MultipartResolver getMultipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(20971520);//size in bytes
multipartResolver.setMaxInMemorySize(20971520);//size in bytes
return multipartResolver;
}

Resources