https://github.com/pennix/logback-cloudwatch-appender
  
  
    Logback appender for aws cloudwatch logs using java 11 java.net.http 
    https://github.com/pennix/logback-cloudwatch-appender
  
        Last synced: 15 days ago 
        JSON representation
    
Logback appender for aws cloudwatch logs using java 11 java.net.http
- Host: GitHub
- URL: https://github.com/pennix/logback-cloudwatch-appender
- Owner: Pennix
- License: mit
- Created: 2021-06-23T11:59:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-04T11:16:58.000Z (over 4 years ago)
- Last Synced: 2025-01-26T05:24:44.223Z (9 months ago)
- Language: Java
- Size: 27.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
- 
            Metadata Files:
            - Readme: README.md
- License: LICENSE
 
Awesome Lists containing this project
README
          Logback appender for AWS CloudWatch logs
=========================================
# Background
This package provides a logback appender that writes log events to Cloudwatch logs.
There're many projects out there but I created this because I don't want to include aws sdk and that lots of dependencies just for logging.
* That said, the only dependency of this project is **JSR 374** json processing
* but it is using **java.net.http** to do http request, so you need at least java 11.
# Maven Configuration
``` xml
	
		net.pennix
		logback-cloudwatch-appender
		
		1.0.3
		runtime
	
```
## Dependencies
The only dependency besides logback is **JSR 374** json processing, you don't have to include this manually.
``` xml
	org.glassfish
	javax.json
	${javax.jsonp.version}
	runtime
```
# logback.xml Configuration
Minimal logback appender configuration:
**NOTE: DO NOT use the same log stream in multiple appenders or multiple application instances, this is a limit by aws**
``` xml
	
	1024
	
	1000
	
	false
	
		${your.aws.access.key.id}
		${your.aws.secret.access.key}
		${target.region.of.cloudwatch.service}
		${your.log.group.name}
		${your.log.stream.name}
		
		500
		
		3000
		
			%1.-1level [%thread] %logger - %msg%n
		
	
```
See the example [logback-test.xml file](src/main/resources/logback-test.xml).
# IAM Permissions
``` json
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogGroup",
                "logs:CreateLogStream",
                "logs:DescribeLogStreams",
                "logs:PutLogEvents"
            ],
            "Resource": [
                "*"
            ]
        }
    ]
}
```
You should probably limit **Resource** to specific region/account/logGroup.
# ChangeLog Release Notes
## v1.0.3
* auto correct *nextToken* on *InvalidSequenceTokenException*
## v1.0.2
* add config **httpTimeout**
* catch **Throwable** to prevent worker thread exiting unexpectedly
## v1.0.1
* allow to enable/disable **prepareForDeferredProcessing**
* sleep between puts to reduce cpu usage
* removed some *addInfo* to improve performance