Giter Club home page Giter Club logo

tomcat-mongo-access-log's Introduction

Tomcat Mongo Access Log

Tomcat Mongo Access Log can be used to save tomcat access logs to mongodb. Before start you should got a mongodb installed (MongoDB installation guide).

This project is inspired by two articles:

  1. MongoDB is fantastic for logging
  2. MongoDB use case - storing log data

Besides, you can also use Tomcat Mongo Access Log Console to query access logs.

Usage

  1. Have a Apache Tomcat 7.0.54(or above) installed.
  2. Clone and build it with maven. mvn clean package
  3. copy target/tomcat-mongo-access-log-${version}.jar to ${TOMCAT_HOME}/lib.
  4. Configure MongoAccessLogValve in ${tomcat}/conf/server.xml, ${tomcat}/conf/context.xml or in a context file. Example:
<Valve 
    className="me.chanjar.tomcat.valves.MongoAccessLogValve" 
    uri="mongodb://localhost/tomcat"
    pattern="default" />

If you want to develop based on this project, you can add following maven dependency to pom.xml:

<dependency>
  <groupId>me.chanjar</groupId>
  <artifactId>tomcat-mongo-access-log</artifactId>
  <version>1.0.0</version>
</dependency>

Attributes

MongoAccessLogValve supports the following configuration attributes of AccessLogValve :

  1. condition
  2. resolveHosts
  3. conditionIf
  4. excludes
  5. pattern. A little different from AccessLogValve, see below
  6. requestAttributesEnabled

And some attributes differs from AccessLogValve:

Attribute Description
uri MongoDB's uri (See MongoClientURI API)
dbName Which DB to store logs, default is tomcat
collName Which collection to store logs, default is tomcat_access_logs
excludes Default is ".js,.css,jpg,.jpeg,.gif,.png,.bmp,.gif,.html,.htm". Don't log the URI request matches some pattern
rotatable If rotatable is on, MongoDBAccessLogValve will try to create a capped collection with the size of capSize(default is 1024, in megabytes) if the collection is not exist
capSize The size of capped collection, in megabytes
rotateCount Not supported
recordError Default is true. MongoAccessLogValve will store exception stack traces in error key when exception throws

Collection Indexes

While it's hard to determine which fields should be indexed, but MongoAccessLogVavle provide the following indexes when it creates the Collection, so the query performance is not guaranteed. May be it's better to determine how to create index by yourself.

{ sessionId : 1}
{ datetime : -1}
{ user : 1}
{ statusCode : 1}
{ elapsedSeconds : 1}
{ elapsedMilliseconds : 1}
{ bytesSent : 1}
{ url : 1}
{ method : 1}

{ url : 1, datetime : -1}

{ user : 1, statusCode : 1}
{ user : 1, datetime : -1}
{ user : 1, sessionId : 1, statusCode : 1, datetime : -1}
{ user : 1, sessionId : 1, url : 1, statusCode : 1, datetime : -1}

{ sessionId : 1, datetime : -1}
{ sessionId : 1, statusCode : 1}
{ sessionId : 1, statusCode : 1, datetime : -1}
{ sessionId : 1, url : 1, statusCode : 1, datetime : -1}

Patterns

All the pattern of AccessLogValve are supported while MongoAccessLogValve save them in a JSON form.

Pattern Key Description
%a remoteIP See AccessLogValve (doc)
%A localIP See AccessLogValve (doc)
%b bytesSent See AccessLogValve (doc)
%B bytesSent See AccessLogValve (doc)
%h remoteHost See AccessLogValve (doc)
%H protocol See AccessLogValve (doc)
%l user See AccessLogValve (doc)
%m method See AccessLogValve (doc)
%p localPort See AccessLogValve (doc)
%q queryString See AccessLogValve (doc)
%r line1st See AccessLogValve (doc)
%s statusCode See AccessLogValve (doc)
%S sessionId See AccessLogValve (doc)
%t datetime See AccessLogValve (doc)
%t{format} datetime Same effect as %t
%u remoteUser See AccessLogValve (doc)
%U url See AccessLogValve (doc)
%v serverName See AccessLogValve (doc)
%D elapsedMillis See AccessLogValve (doc)
%T elapsedSeconds See AccessLogValve (doc)
%I thread See AccessLogValve (doc)
%P params All the GET and POST parameters, value is in the form of { param1 : value1, param2 : value2, params3 : [value1, value2, value3] }
%{xxx}i requestHeaders Request headers { header1 : value1, header2 : value2}. See AccessLogValve (doc)
%{xxx}o responseHeaders Response headers { header1 : value1, header2 : value2}. See AccessLogValve (doc)
%{xxx}c cookies Cookies { cookie1 : value1, cookie2 : value2}. See AccessLogValve (doc)
%{xxx}r requestAttrs Attributes in the ServletRequest { attr1 : value1, attr2 : value2}. See AccessLogValve (doc)
%{xxx}s sessionAttrs Attributes in the HttpSession { attr1 : value1, attr2 : value2}. See AccessLogValve (doc)
%{xxx}t not supported

Shorthand pattern

The shorthand patterns common and combined are also supported.

And MongoAccessLogValve provides two more shorthand patterns:

  1. default equivalent to %a %b %l %m %s %S %t %U %T %P %{Referer}i %{User-Agent}i
  2. all equivalent to %a %A %b %B %h %H %l %m %p %q %r %s %S %t %u %U %v %D %T %I %P %{Referer}i %{User-Agent}i

tomcat-mongo-access-log's People

Contributors

chanjarster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tomcat-mongo-access-log's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.