All Projects → link-nv → logback-s3-rolling-policy

link-nv / logback-s3-rolling-policy

Licence: Apache-2.0 license
Logback RollingPolicy to store logs in S3

Programming Languages

shell
77523 projects
java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to logback-s3-rolling-policy

Java Library Examples
💪 example of common used libraries and frameworks, programming required, don't fork man.
Stars: ✭ 204 (+684.62%)
Mutual labels:  logback
slack-webhook-appender
Logback appender which posts logs to slack via incoming webhook.
Stars: ✭ 16 (-38.46%)
Mutual labels:  logback
s3cr3t
A supercharged S3 reverse proxy
Stars: ✭ 55 (+111.54%)
Mutual labels:  s3-bucket
logback-gelf-appender
Logback appender that sends GELF messages
Stars: ✭ 38 (+46.15%)
Mutual labels:  logback
terraform-aws-s3
Terraform module to create default S3 bucket with logging and encryption type specific features.
Stars: ✭ 22 (-15.38%)
Mutual labels:  s3-bucket
s3recon
Amazon S3 bucket finder and crawler.
Stars: ✭ 111 (+326.92%)
Mutual labels:  s3-bucket
Tomcat Slf4j Logback
Tomcat, SLF4J and Logback integration Releases
Stars: ✭ 172 (+561.54%)
Mutual labels:  logback
awesome-storage
A curated list of storage open source tools. Backups, redundancy, sharing, distribution, encryption, etc.
Stars: ✭ 324 (+1146.15%)
Mutual labels:  s3-bucket
springboot-tutorials
codehome出品SpringBoot2.x基础教程
Stars: ✭ 77 (+196.15%)
Mutual labels:  logback
mlflow-tracking-server
MLFLow Tracking Server based on Docker and AWS S3
Stars: ✭ 59 (+126.92%)
Mutual labels:  s3-bucket
gatsby-s3-action
Deploy a Gatsby Project to an AWS S3 bucket (optional Cloudfront support)
Stars: ✭ 40 (+53.85%)
Mutual labels:  s3-bucket
image-uploader
JavaScript Image Uploader Library for use with Amazon S3
Stars: ✭ 19 (-26.92%)
Mutual labels:  s3-bucket
S3Scan
Script to spider a website and find publicly open S3 buckets
Stars: ✭ 21 (-19.23%)
Mutual labels:  s3-bucket
smockin
Dynamic API, S3 & Mail mocking for web, mobile & microservice development.
Stars: ✭ 74 (+184.62%)
Mutual labels:  s3-bucket
liquibase-slf4j
Liquibase SLF4J Logger.
Stars: ✭ 42 (+61.54%)
Mutual labels:  logback
Stubbornjava
Unconventional Java code for building web servers / services without a framework. Think dropwizard but as a seed project instead of a framework. If this project had a theme it would be break the rules but be mindful of your decisions.
Stars: ✭ 184 (+607.69%)
Mutual labels:  logback
herald
Log annotation for logging frameworks
Stars: ✭ 71 (+173.08%)
Mutual labels:  logback
BlobHelper
BlobHelper is a common, consistent storage interface for Microsoft Azure, Amazon S3, Komodo, Kvpbase, and local filesystem written in C#.
Stars: ✭ 23 (-11.54%)
Mutual labels:  s3-bucket
logback-mdc-ttl
logback扩展,集成transmittable-thread-local支持跨线程池的mdc跟踪
Stars: ✭ 107 (+311.54%)
Mutual labels:  logback
owasp-security-logging
OWASP Security Logging library for Java
Stars: ✭ 106 (+307.69%)
Mutual labels:  logback

Logback RollingPolicy with S3 upload

logback-s3-rolling-policy automatically uploads rolled log files to S3.

There are 2 rolling policies which can be used:

  • S3FixedWindowRollingPolicy
  • S3TimeBasedRollingPolicy

logback-s3-rolling-policy was forked from logback-s3 (https://github.com/shuwada/logback-s3) but transfered into a new project because changes were getting too big.

Index

Requirements

  • Java 1.7+

Configuration

logback.xml variables

Whether you implement one of any available S3 policies, the following extra variables (on top of Logback's) can be used:

  • s3BucketName The S3 bucket name to upload your log files to (mandatory).
  • awsAccessKey Your AWS access key. If not provided it falls back to the AWS SDK default provider chain.
  • awsSecretKey Your AWS secret key. If not provided it falls back to the AWS SDK default provider chain.
  • s3FolderName The S3 folder name in your S3 bucket to put the log files in. This variable supports dates, just put your pattern between %d{}. Example: %d{yyyy/MM/dd}.
  • shutdownHookType Defines which type of shutdown hook you want to use. This variable is mandatory when you use rolloverOnExit. Defaults to NONE. Possible values are:
    • NONE This will not add a shutdown hook. Please note that your most up to date log file won't be uploaded to S3!
    • JVM_SHUTDOWN_HOOK This will add a runtime shutdown hook. If you're using a webapplication, please use the SERVLET_CONTEXT, as the JVM shutdown hook is not really safe to use here.
    • SERVLET_CONTEXT This will register a shutdown hook to the context destroyed method of RollingPolicyContextListener. Don't forget to actually add the context listener to you web.xml. (see below)
  • rolloverOnExit Whether to rollover when your application is being shut down or not. Boolean value, defaults to false. If this is set to false, and you have defined a shutdownHookType, then the log file will be uploaded as is.
  • prefixTimestamp Whether to prefix the uploaded filename with a timestamp formatted as yyyyMMdd_HHmmss or not. Boolean value, defaults to false.
  • prefixIdentifier Whether to prefix the uploaded filename with an identifier or not. Boolean value, defaults to false. If running on an AWS EC2 instance, the instance ID will be used. If not running on an AWS EC2 instance, the hostname address will be used. If the hostname address can't be used, a UUID will be used.

web.xml

If you're using the shutdown hook SERVLET_CONTEXT as defined above, you'll need to add the context listener class to your web.xml:

<listener>
   <listener-class>ch.qos.logback.core.rolling.shutdown.RollingPolicyContextListener</listener-class>
</listener>

Run-time variables

As of version 1.3 you can set run-time variables. For now you can only add an extra S3 folder.

Just use CustomData.extraS3Folder.set( "extra_folder_name" ); somewhere in your code before the upload occurs. You can always change this value during run-time and it will be picked up on the next upload. set to null to ignore.

logback.xml rolling policy examples

An example logback.xml appender for each available policy using RollingFileAppender.

  • ch.qos.logback.core.rolling.S3FixedWindowRollingPolicy:
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <file>logs/myapp.log</file>
  <encoder>
    <pattern>[%d] %-8relative %22c{0} [%-5level] %msg%xEx{3}%n</pattern>
  </encoder>
  <rollingPolicy class="ch.qos.logback.core.rolling.S3FixedWindowRollingPolicy">
    <fileNamePattern>logs/myapp.%i.log.gz</fileNamePattern>
    <awsAccessKey>ACCESS_KEY</awsAccessKey>
    <awsSecretKey>SECRET_KEY</awsSecretKey>
    <s3BucketName>myapp-logging</s3BucketName>
    <s3FolderName>logs/%d{yyyy/MM/dd}</s3FolderName>
    <rolloverOnExit>true</rolloverOnExit>
    <shutdownHookType>SERVLET_CONTEXT</shutdownHookType>
    <prefixTimestamp>true</prefixTimestamp>
    <prefixIdentifier>true</prefixIdentifier>
  </rollingPolicy>
  <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
    <maxFileSize>10MB</maxFileSize>
  </triggeringPolicy>
</appender>

In this example you'll find the logs at myapp-logging/logs/2015/08/18/.

  • ch.qos.logback.core.rolling.S3TimeBasedRollingPolicy:
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
  <file>logs/myapp.log</file>
  <encoder>
    <pattern>[%d] %-8relative %22c{0} [%-5level] %msg%xEx{3}%n</pattern>
  </encoder>
  <rollingPolicy class="ch.qos.logback.core.rolling.S3TimeBasedRollingPolicy">
    <!-- Rollover every minute -->
    <fileNamePattern>logs/myapp.%d{yyyy-MM-dd_HH-mm}.%i.log.gz</fileNamePattern>
    <awsAccessKey>ACCESS_KEY</awsAccessKey>
    <awsSecretKey>SECRET_KEY</awsSecretKey>
    <s3BucketName>myapp-logging</s3BucketName>
    <s3FolderName>log</s3FolderName>
    <rolloverOnExit>true</rolloverOnExit>
    <shutdownHookType>SERVLET_CONTEXT</shutdownHookType>
    <prefixTimestamp>false</prefixTimestamp>
    <prefixIdentifier>true</prefixIdentifier>
    <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
      <maxFileSize>10MB</maxFileSize>
    </timeBasedFileNamingAndTriggeringPolicy>
  </rollingPolicy>
</appender>

In this example you'll find the logs at myapp-logging/log/.

AWS Credentials

It is a good idea to create an IAM user only allowed to upload S3 object to a specific S3 bucket. It improves the control and reduces the risk of unauthorized access to your S3 bucket.

The following is an example IAM policy.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "s3:PutObject"
      ],
      "Sid": "Stmt1378251801000",
      "Resource": [
        "arn:aws:s3:::myapp-logging/log/*"
      ],
      "Effect": "Allow"
    }
  ]
}

Libraries

This project uses the following libraries:

  • com.amazonaws:aws-java-sdk:1.11.7
  • ch.qos.logback:logback-classic:1.2.3
  • com.google.guava:guava:18.0
  • javax.servlet:servlet-api:2.4 (scope provided)
  • org.jetbrains:annotations:15.0 (scope provided)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].