├── .github
└── workflows
│ ├── ci-vert.x-4.x.yml
│ ├── ci-vert.x-5.x.yml
│ └── sonar.yml
├── .gitignore
├── CHANGELOG.md
├── ES_README.md
├── LA_README.md
├── LICENSE.txt
├── README.md
├── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
├── main
├── java
│ └── com
│ │ └── romanpierson
│ │ └── vertx
│ │ └── web
│ │ └── accesslogger
│ │ ├── AccessLoggerConstants.java
│ │ ├── AccessLoggerHandler.java
│ │ ├── appender
│ │ ├── Appender.java
│ │ ├── console
│ │ │ └── impl
│ │ │ │ └── ConsoleAppender.java
│ │ ├── elasticsearch
│ │ │ └── impl
│ │ │ │ └── ElasticSearchAppender.java
│ │ ├── eventbus
│ │ │ └── impl
│ │ │ │ └── EventBusAppender.java
│ │ └── logging
│ │ │ └── impl
│ │ │ └── LoggingAppender.java
│ │ ├── configuration
│ │ ├── element
│ │ │ ├── AccessLogElement.java
│ │ │ └── impl
│ │ │ │ ├── BytesSentElement.java
│ │ │ │ ├── CookieElement.java
│ │ │ │ ├── DateTimeElement.java
│ │ │ │ ├── DurationElement.java
│ │ │ │ ├── EnvironmentValueElement.java
│ │ │ │ ├── HeaderElement.java
│ │ │ │ ├── HostElement.java
│ │ │ │ ├── MethodElement.java
│ │ │ │ ├── RequestElement.java
│ │ │ │ ├── StaticValueElement.java
│ │ │ │ ├── StatusElement.java
│ │ │ │ └── VersionElement.java
│ │ └── pattern
│ │ │ ├── ExtractedPosition.java
│ │ │ ├── PatternResolver.java
│ │ │ └── ResolvedPatternResult.java
│ │ ├── exception
│ │ └── AccessLoggerException.java
│ │ ├── impl
│ │ └── AccessLoggerHandlerImpl.java
│ │ ├── util
│ │ ├── FormatUtility.java
│ │ └── VersionUtility.java
│ │ └── verticle
│ │ ├── AccessLoggerProducerVerticle.java
│ │ └── ResolvedLoggerConfiguration.java
└── resources
│ └── META-INF
│ └── services
│ └── com.romanpierson.vertx.web.accesslogger.configuration.element.AccessLogElement
└── test
├── java
└── com
│ └── romanpierson
│ ├── custom
│ └── element
│ │ ├── ShouldNotShowElement.java
│ │ └── ShouldShowElement.java
│ └── vertx
│ ├── test
│ └── verticle
│ │ └── SimpleJsonResponseVerticle.java
│ └── web
│ └── accesslogger
│ ├── AcessLogServerTest.java
│ ├── ConsoleAppenderTest.java
│ ├── ElasticSearchAppenderTest.java
│ ├── EventBusAppenderTest.java
│ ├── LoggingAppenderTest.java
│ ├── appender
│ └── MemoryAppender.java
│ ├── configuration
│ ├── element
│ │ └── impl
│ │ │ ├── AccessLogElementTest.java
│ │ │ ├── InvalidElement.java
│ │ │ ├── InvalidElement2.java
│ │ │ └── ShouldNotShowElement.java
│ └── pattern
│ │ ├── DurationElementCustomTest.java
│ │ ├── PatternResolverTest.java
│ │ └── RequestElementTest.java
│ ├── element
│ └── ElementTest.java
│ └── util
│ ├── FormatUtilityTest.java
│ └── VersionUtilityTest.java
└── resources
├── META-INF
└── services
│ └── com.romanpierson.vertx.web.accesslogger.configuration.element.AccessLogElement
├── accesslog-config-all-valid-console-appender-autocreation-verticle.yaml
├── accesslog-config-all-valid-console-appender.yaml
├── accesslog-config-all-valid-memory-appender.yaml
├── accesslog-config-console-appender-valid.yaml
├── accesslog-config-elasticsearch-appender-invalid-fieldnames.yaml
├── accesslog-config-elasticsearch-appender-invalid-instance.yaml
├── accesslog-config-elasticsearch-appender-valid.yaml
├── accesslog-config-elements-empty-result.yaml
├── accesslog-config-elements-result.yaml
├── accesslog-config-eventbus-appender-existing-address.yaml
├── accesslog-config-eventbus-appender-inexisting-address.yaml
├── accesslog-config-eventbus-appender-invalid-config.yaml
├── accesslog-config-invalid-console-appender.yaml
├── accesslog-config-invalid.yaml
├── accesslog-config-logging-appender-invalid-loggername.yaml
├── accesslog-config-logging-appender-invalid-logpattern.yaml
├── accesslog-config-logging-appender-valid.yaml
└── logback.xml
/.github/workflows/ci-vert.x-4.x.yml:
--------------------------------------------------------------------------------
1 | name: vert.x (4.x)
2 |
3 | on:
4 | push:
5 | branches:
6 | - vert.x-4.x
7 |
8 | jobs:
9 | ci:
10 | name: Any (supported)
11 | strategy:
12 | fail-fast: false
13 | matrix:
14 | os: [ ubuntu-latest ]
15 | java: [ 11 ]
16 | runs-on: ${{ matrix.os }}
17 | steps:
18 | - uses: actions/checkout@v3
19 | - uses: actions/setup-java@v3
20 | with:
21 | java-version: ${{ matrix.java }}
22 | distribution: temurin
23 | - name: Build project
24 | run: ./gradlew clean build
25 |
--------------------------------------------------------------------------------
/.github/workflows/ci-vert.x-5.x.yml:
--------------------------------------------------------------------------------
1 | name: vert.x (5.x)
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 |
8 | jobs:
9 | ci:
10 | name: Any (supported)
11 | strategy:
12 | fail-fast: false
13 | matrix:
14 | os: [ ubuntu-latest ]
15 | java: [ 11 ]
16 | runs-on: ${{ matrix.os }}
17 | steps:
18 | - uses: actions/checkout@v3
19 | - uses: actions/setup-java@v3
20 | with:
21 | java-version: ${{ matrix.java }}
22 | distribution: temurin
23 | - name: Build project
24 | run: ./gradlew clean build
25 |
--------------------------------------------------------------------------------
/.github/workflows/sonar.yml:
--------------------------------------------------------------------------------
1 | name: Sonar
2 |
3 | on:
4 | push:
5 | branches:
6 | - master
7 |
8 | jobs:
9 | sonar:
10 | name: SonarCloud
11 | env:
12 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
13 | SONAR_TOKEN: ${{ secrets.sonarcloud }}
14 | runs-on: ubuntu-latest
15 | steps:
16 | - uses: actions/checkout@v3
17 | - uses: actions/setup-java@v3
18 | with:
19 | java-version: 17
20 | distribution: temurin
21 | - name: Build project
22 | run: ./gradlew clean build sonar -Dsonar.host.url=https://sonarcloud.io -Dsonar.organization=romanpierson -Dsonar.projectKey=romanpierson_vertx-web-accesslog
23 |
24 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /bin/
2 | .classpath
3 | build/tmp/jar/MANIFEST.MF
4 | build/
5 | .gradle/
6 | .project
7 | .settings/org.eclipse.jdt.core.prefs
8 | gradle.properties
9 | .vertx
10 | .metadata
11 | .settings
12 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## Changelog
2 |
3 | ### 2.7.0 (Vert.x 5)
4 |
5 | (2025-05-15)
6 |
7 | * Functional identical version of `1.7.0` for `vert.x 5`
8 |
9 |
10 | ### 1.7.0
11 |
12 | (2024-01-13)
13 |
14 | * Native handling of values
15 | * All Log Elements return now native objects if possible
16 | * String based Appenders have to stringify themselves
17 | * Appenders that understand native objects benefit from this change
18 | * **BREAKING CHANGE**: `Appender.push` signature changed and simplified - only relevant if you have a custom Appender
19 | * Upgrade to Vert.x 4.5.1 -> Ready for Virtual Threads
20 | * Automatic injection of `timestamp` for `ElasticSearchAppender` - no need anymore to define it artifically in logPattern
21 |
22 | ### 1.6.1
23 |
24 | (2023-11-10)
25 |
26 | * Headers case insensitive
27 | * Upgrade to latest versions
28 |
29 | ### 1.6.0
30 |
31 | (2023-04-19)
32 |
33 | * Refactored and simplified PatternResolver and Element code using java functions
34 | * Raised test coverage
35 | * Allow easy overwriting of existing patterns with custom elements
36 | * Upgrade to latest versions
37 |
38 | ### 1.5.0
39 |
40 | (2022-12-30)
41 |
42 | * Moved package `com.mdac` to `com.romanpierson` (for maven central)
43 | * Upgrade to latest versions
44 | * Moved from Travis CI to Github Actions / Gradle Sonarqube Plugin
45 | * Removed slf4j dependency
46 | * Integrated `LoggingAppender` and `ElasticSearchAppender` into core library
47 |
48 | ### 1.4.0
49 |
50 | (2020-12-17)
51 |
52 | * Upgrade to Vertx 4, Junit 5, Gradle, all libraries latest versions
53 | * Added `EnvironmentValueElement`
54 |
55 | ### 1.3.1
56 |
57 | (2019-04-17)
58 |
59 | * Fixed a bug with pattern resolver (https://github.com/romanpierson/vertx-web-accesslog/issues/11)
60 |
61 | ### 1.3.0
62 |
63 | (2019-02-14)
64 |
65 | * Changed configuration from custom Option classes to plain JsonObject
66 | * Added plain timestamp as log element
67 | * Replaced `PrintStreamAppender` with `ConsoleAppender`
68 | * Added `EventBusAppender`
69 | * Fixed a bug with picking up the best log element if multiple ones potentially fit
70 | * Added `StaticValueElement`
71 |
72 | ### 1.2.0
73 |
74 | (2019-01-10)
75 |
76 | * Introduced Appender API and removed all except `PrintStreamAppender` to separate projects
77 | * `AccessLogElerment` is able to claim what data it requires
78 | * General refactoring into Constants
79 | * Raw values are translated into formatted values and only those get passed to appenders
80 | * Appenders do not get passed anymore `AccessLogElement` instances
81 | * Fixed a bug in `DateTimeElement` that caused pattern definition not to work
82 | * Fixed a bug in `findInRawPatternInternal` method of several `AccessLogElement` implementations that handle several element patterns and in the case of having a pattern with those following each other this might have led to the situation of bypassing the earlier one
83 | * Extracting correct hostname for local host (%v)
84 |
--------------------------------------------------------------------------------
/ES_README.md:
--------------------------------------------------------------------------------
1 |
2 | # Usage
3 |
4 | ## Appender configuration
5 |
6 | As configuration is now done by plain JsonObject its very simple to use and inject configuration eg by yaml, see as an example:
7 |
8 | ```yaml
9 | configurations:
10 | - identifier: accesslog-plain
11 | logPattern: "%D cs-uri"
12 | appenders:
13 | - appenderClassName : com.romanpierson.vertx.web.accesslogger.appender.elasticsearch.impl.ElasticSearchAppender
14 | config:
15 | instanceIdentifier: accesslog
16 | fieldNames:
17 | - duration
18 | - uri
19 | ```
20 |
21 | ## Conventions
22 |
23 | By default all log elements configured will be sent to the indexer to be interpreted as message to be indexed. However the timestamp is passed to the indexer as meta data as the indexer potentially requires that raw value eg to determinate the target index name.
24 |
25 | The instance identifier tells the indexer verticle to what ES instance the data should be indexed. All the detailed configuration of this is done directly on the indexer verticle itself (so the appender does not have to know about this).
26 |
27 | ## Timestamp
28 |
29 | The timestamp value is automatically added - there is no need to add this on the logPattern.
30 |
31 | The real fieldname used in the indexer for the ES timestamp field is configured in the indexer verticle itself.
32 |
33 | ## Field Names Definition
34 |
35 | As for each field to be indexed a specific name needs to be used this has to be explicitly set by configuration property `fieldNames`. Be aware that you need to put a name for all fields of your logpattern.
36 |
--------------------------------------------------------------------------------
/LA_README.md:
--------------------------------------------------------------------------------
1 | Generating the access log files is performed in a transparent way by vertx logger. Therefore there is any restriction regarding the logging framework used behind (however logback is recommended and test case is implemented using logback / SLF4J). Main reason for this is to not have a dependency on a specific logging framework and also to ensure that implementation details like for example rollover strategies (size, daily, etc) are dealt with by the logging framework.
2 |
3 |
4 | # Usage
5 |
6 | ## Appender Configuration
7 |
8 | As configuration is now done by plain JsonObject its very simple to use and inject configuration eg by yaml, see as an example:
9 |
10 | ```yaml
11 | configurations:
12 | - identifier: accesslog-formatted
13 | logPattern: '%{}t %D "cs-uri"'
14 | appenders:
15 | - appenderClassName : com.romanpierson.vertx.web.accesslogger.appender.logging.impl.LoggingAppender
16 | config:
17 | loggerName: accesslog
18 | ```
19 |
20 |
21 | ## Configure Logger
22 |
23 | The logger itself in the current solution does not has a built in mechanism to write to the physical access file. Instead this is done by the logging framework used behind.
24 |
25 | ### Logback Configuration
26 |
27 | This shows how eg you define with logback.xml - as you see the loggerName has to match with what is defined in the appender configuration
28 |
29 | ```xml
30 |
31 |
32 |
33 | ${access.location}/access.log
34 |
35 | access.%d{yyyy-MM-dd}.log
36 | 10
37 |
38 |
39 | %msg%n
40 | true
41 |
42 |
43 |
44 |
45 |
46 | 0
47 | 500
48 | 5000
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | %d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | ```
70 |
71 | If you use a dynamic part like the root log folder you have make sure it is set like this when you create the vertx instance byself:
72 |
73 | ```java
74 | System.setProperty("access.location", "/tmp/accesslog ");
75 |
76 | // Start vertx here...
77 |
78 | ```
79 |
80 | If you are using a fatjar it needs to be like this (Be aware that the properties have to go before the jar in order to get picked up):
81 |
82 | ```java
83 | java \
84 | -Daccess.location=/Users/x/y/logs \
85 | -jar myFatJar.jar
86 | ```
87 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright 2016-2025 Roman Pierson
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://github.com/romanpierson/vertx-web-accesslog/actions/workflows/ci-vert.x-5.x.yml)
2 | [](https://github.com/romanpierson/vertx-web-accesslog/actions/workflows/ci-vert.x-4.x.yml)
3 | [](https://sonarcloud.io/dashboard?id=romanpierson_vertx-web-accesslog)
4 | [](https://github.com/vert-x3/vertx-awesome)
5 |
6 | # vertx-web-accesslog
7 |
8 | An access log implementation to be used in vertx web routes.
9 |
10 | Inspired and with intention to be compliant with
11 |
12 | * Apache HTTP Server mod_log_config module (http://httpd.apache.org/docs/2.4/en/mod/mod_log_config.html)
13 |
14 | * W3C Extended Log File Format (http://www.w3.org/TR/WD-logfile.html)
15 |
16 | The main idea is to have an event based logging, with the possibility (but not enforcing you to do so) to directly export a log event natively to a target system, and not having to first write and persist it to a file and then read and parse it again from there like eg ELK is doing it. The drawback that those kind of solutions have is performance but even more issues like recognizing complete stacktraces etc.
17 | The ElasticSearch Appender is the only appender for now that takes advantage of those benefits.
18 | However you are free of course to use a traditional ELK setup style and just write your output to either console or a specific logfile - and let eg logstash take over from there.
19 |
20 | ## Key facts
21 |
22 | * Zero dependencies (apart of vertx-web obviously)
23 | * Easily extensible and customizable
24 | * Small memory footprint
25 |
26 |
27 | ## Technical Usage
28 |
29 | The artefact is published on maven central.
30 |
31 | Just add it as a dependency to your project (gradle example)
32 |
33 | ```xml
34 | dependencies {
35 | compile 'com.romanpierson:vertx-web-accesslog:2.7.0'
36 | }
37 | ```
38 |
39 | ## Compatibility with Vert.x core
40 |
41 | Since introduction of `vert.x 5` due to some architectural changes the master contains `vert.5` compatible version and its `vert.x 4` compatible counterpart continues on branch `vert.x-4.x`.
42 |
43 | Those two versions are functional equivalent and you should just be able to switch to `vert.5` without any code changes. The plan is also to keep the two versions with same functionality.
44 |
45 | Therefore minor version will stay identical but major version will identify if the library is targeted to be used with `vert.x 4` (1) or `vert.x 5` (2)
46 |
47 | Accesslog version 4.x / 5.x | Vertx version
48 | ----|------
49 | 1.7.0 / 2.7.0 | 4.5.1 > / 5.0.0 >
50 | 1.6.0 / - | 4.3.0 > / -
51 | 1.5.0 / - | 4.2.0 > / -
52 | 1.4.0 / - | 4.0.0 - 4.1.x / -
53 | 1.3.1 / - | 3.3.0 - 3.7.0 / -
54 | 1.2.0 / - | 3.3.0 - 3.7.0 / -
55 |
56 | Previous versions are listed for completeness only and not supported anymore.
57 |
58 | ## Access Log Pattern Configuration
59 |
60 | The logger supports mixing of both log formats and is also designed to easily add custom log elements
61 |
62 | ### Define your custom AccessLogElement
63 |
64 | You can easily create your custom implementation of `AccessLogElement` by creating your own element class implementing `AccessLogElement` interface. The available `AccessLogElement` types are discovered by ServiceLoader, so just add to your resources a file like this and inside list your `AccessLogElement` classes
65 |
66 | ```xml
67 | META-INF
68 | services
69 | com.romanpierson.vertx.web.accesslogger.configuration.element.AccessLogElement
70 | ```
71 |
72 | As ServiceLoader SPI is intented to work with objects unfortunately your AccessLogElement implementation requires a parameter less constructor.
73 |
74 | In order that the pattern resolver is able to resolve your new element against a pattern you have to implement your resolving condition by implementing `findInRawPatternInternal(rawPattern)` method.
75 |
76 | To facility this and to avoid boilerplate code there are static helpers in PatternResolver that simplifies that a lot.
77 |
78 | Method | Resolves pattern | Remarks | Examples
79 | ----|------|--|----
80 | extractBestPositionFromFixPatternIfApplicable | `` | Whatever value is matched and resolved | `%b` `cs-uri`
81 | extractBestPositionFromFixPatternsIfApplicable | `` | Like above but you can pass a list of values to be matched | `%b` `cs-uri`
82 | extractBestPositionFromPostfixPatternIfApplicable | `%{}POSTFIX` | Searches for a postfixed pattern and extracts a configuration string that is passed later to your defined function | `%{msec}t`
83 | extractBestPositionFromPostfixPatternAndAdditionalCheckIfApplicable | `%{}POSTFIX` | Like above but let you define an additional function that checks if the found configuration value is valid for your element to be handled | `%{msec}t`
84 |
85 | ### Redefine existing elements with your custom one
86 |
87 | By defining your custom element using same pattern as an existing one shipped with this library it will have preference over the predefined one.
88 |
89 |
90 | ## Appenders
91 |
92 | Appenders are basically a way to send the log data to one (or multiple) backends. This ships with a set of (hopefully) useful appenders but you can create your custom appenders in a very easy way.
93 |
94 | ### Available Appenders
95 |
96 | Appender | Description
97 | ----|------
98 | Console Appender | Embedded - main purpose for testing
99 | EventBus Appender | Embedded - simple way to forward access events to a configurable address on the event bus
100 | [Logging Appender](https://github.com/romanpierson/vertx-web-accesslog/blob/master/LA_README.md) | Embedded - Using common logging functionality (logback, slf4j, etc)
101 | [ElasticSearch Appender](https://github.com/romanpierson/vertx-web-accesslog/blob/master/ES_README.md) | Embedded - Experimental appender that writes data to ElasticSearch (For usage eg in kibana) Requires [Vertx ElasticSearch Indexer](https://github.com/romanpierson/vertx-elasticsearch-indexer)
102 |
103 |
104 |
105 | ### Custom Appenders
106 |
107 | You can easily write your own appender doing
108 |
109 | Write your own CustomAppender class that must
110 | * implement `Appender` Interface
111 | * have a public constructor taking a `JsonObject` instance holding the configuration
112 |
113 | ## AccessLoggerProducerVerticle
114 |
115 | This verticle is responsible for receiving the raw data, formatting it based on the AccessLogElements configured and forwards the resulting data to the registered Appenders (by calling `Appender.push`).
116 |
117 | There is one worker instance of `AccessLoggerProducerVerticle` per vertx context started if you put configuration value `isAutoDeployProducerVerticle` to `true` (by default it is). If you prefer to manage the deployment of that verticle byself set the property to `false`.
118 |
119 | ## Usage
120 |
121 | This describes the basic usage. More specific info eg about the different appenders can be found on the links.
122 |
123 | ### Configure route
124 |
125 | Just put an instance of AccessLogHandler as first route handler.
126 |
127 | ```java
128 | Router router = Router.router(vertx);
129 |
130 | JsonObject config = .... load or create your configuration json
131 |
132 | router.route().handler(AccessLoggerHandler.create(config));
133 |
134 | ```
135 |
136 | As configuration is now done by plain JsonObject its very simple to use and inject configuration eg by yaml, see as an example `ServerSetupStarter`
137 |
138 | ```yaml
139 | configurations:
140 | - identifier: accesslog-formatted
141 | logPattern: '%{}t %D "cs-uri"'
142 | appenders:
143 | - appenderClassName : com.romanpierson.vertx.web.accesslogger.appender.console.impl.ConsoleAppender
144 | - identifier: accesslog-plain
145 | logPattern: "%{msec}t %D cs-uri"
146 | appenders:
147 | - appenderClassName : com.romanpierson.vertx.web.accesslogger.appender.console.impl.ConsoleAppender
148 | ```
149 |
150 | ## Supported log elements
151 |
152 | Currently those elements are supported
153 |
154 | Element | Apache | W3C | Remarks
155 | ----|------|------------| --------
156 | Method | %m | cs-method | |
157 | Status | %s | sc-status | |
158 | Duration s | %T | - | |
159 | Duration ms | %D | - | |
160 | Remote Host | %h | - | |
161 | Local Host | %v | - | |
162 | Local port | %p | - | |
163 | Bytes Written v1 | %B | - | Zero Bytes written as 0 |
164 | Bytes Written v2 | %b | - | Zero Bytes written as - |
165 | First line of request | %r | - | |
166 | URI path only | %U | cs-uri-stem | |
167 | Query only | %q | cs-uri-query | |
168 | URI path incl query | - | cs-uri | |
169 | Version / Protocol | %H | - | |
170 | Datetime Apache | %t | - | Logs by default the request timestamp using format 'EEE, dd MMM yyyy HH:mm:ss zzz', Locale English and Timezone GMT |
171 | Datetime Apache Timeunit | %t{msec} | - | Currently only milliseconds is supported |
172 | | Datetime Apache Configurable v1 | %{PATTERN}t | - | Specify the format pattern, by default it is used Locale English and Timezone GMT |
173 | | Datetime Apache Configurable v2 | %{PATTERN\|TIMEZONE\|LANGUAGE}t | - | Specify format pattern, timezone and language |
174 | Incoming Headers | %{IDENTIFIER}i | - | |
175 | Outgoing Response Headers | %{IDENTIFIER}o | - | |
176 | Cookie | %{IDENTIFIER}C | - | Request cookies only |
177 | Static value | %{IDENTIFIER}static | - | |
178 | Environment Variable value | %{IDENTIFIER}env | - | |
179 |
180 | ### Static values
181 |
182 | For static values you should prefer to use the %{value}static element. In case you have an appender like `ConsoleAppender` or `LoggingAppender` that writes its output via the resolved pattern you can also put such static values directly into the logpattern as it will just stay as non resolved. However for other appenders like `ElasticSearchAppender` one you need to explicitly define the element.
183 |
184 | ### Empty behavior
185 |
186 | The default way for elements where no actual value can be evaluated is to return a `NULL` value. This way the appender is able to translate this into an empty string or eg skip the value if we index towards a solution like ElasticSearch.
187 |
188 | ## Changelog
189 |
190 | Detailed changelog can be found [here](https://github.com/romanpierson/vertx-web-accesslog/blob/master/CHANGELOG.md).
191 |
192 | ## Demo Playground
193 |
194 | A sample project that shows usage of this (and other related features) can be found [here](https://github.com/romanpierson/vertx-logging-playground).
195 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'java'
3 | id 'maven-publish'
4 | id 'jacoco'
5 | id "org.sonarqube" version "6.1.0.5360"
6 | }
7 |
8 | repositories {
9 | mavenCentral()
10 | }
11 |
12 | ext{
13 | vertxVersion = '5.0.0'
14 | jupiterVersion = '5.12.2'
15 | jupiterLauncherVersion = '1.12.1'
16 | slfApiVersion = '2.0.17'
17 | logbackVersion = '1.5.18'
18 | }
19 |
20 | dependencies {
21 |
22 | implementation "io.vertx:vertx-web:${vertxVersion}"
23 |
24 | testImplementation "io.vertx:vertx-config-yaml:${vertxVersion}"
25 | testImplementation "io.vertx:vertx-junit5:${vertxVersion}"
26 | testImplementation "io.vertx:vertx-web-client:${vertxVersion}"
27 |
28 | testImplementation "org.junit.jupiter:junit-jupiter-api:${jupiterVersion}"
29 | testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${jupiterVersion}"
30 | testImplementation "org.junit.platform:junit-platform-launcher:${jupiterLauncherVersion}"
31 |
32 | testRuntimeOnly "org.slf4j:slf4j-api:${slfApiVersion}"
33 | testRuntimeOnly "ch.qos.logback:logback-classic:${logbackVersion}"
34 | }
35 |
36 | test {
37 | environment "envVar1", "envVal1"
38 | useJUnitPlatform()
39 | finalizedBy jacocoTestReport
40 | }
41 |
42 |
43 |
44 | jar.archiveFileName = "vertx-web-accesslog-2.7.0.jar"
45 |
46 | java {
47 | withSourcesJar()
48 | sourceCompatibility='11'
49 | targetCompatibility='11'
50 | }
51 |
52 | publishing {
53 | publications {
54 | mavenJava(MavenPublication) {
55 |
56 | groupId = 'com.romanpierson'
57 | artifactId = 'vertx-web-accesslog'
58 | version = '2.7.0'
59 |
60 | from components.java
61 |
62 | }
63 | }
64 | }
65 |
66 | sonar {
67 | properties {
68 | property "sonar.sources", "src/main"
69 | property "sonar.tests", "src/test"
70 | property "sonar.test.exclusions", "**/src/test/**"
71 | }
72 | }
73 |
74 |
75 | jacocoTestReport {
76 | reports {
77 | xml.required = true
78 | html.required = true
79 | }
80 | }
81 |
82 | wrapper() {
83 | gradleVersion = '8.14'
84 | }
85 |
86 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/romanpierson/vertx-web-accesslog/896807d488a9058022089319fdfc6f99f1be6795/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90 |
91 | # Use the maximum available, or set MAX_FD != -1 to use that value.
92 | MAX_FD=maximum
93 |
94 | warn () {
95 | echo "$*"
96 | } >&2
97 |
98 | die () {
99 | echo
100 | echo "$*"
101 | echo
102 | exit 1
103 | } >&2
104 |
105 | # OS specific support (must be 'true' or 'false').
106 | cygwin=false
107 | msys=false
108 | darwin=false
109 | nonstop=false
110 | case "$( uname )" in #(
111 | CYGWIN* ) cygwin=true ;; #(
112 | Darwin* ) darwin=true ;; #(
113 | MSYS* | MINGW* ) msys=true ;; #(
114 | NONSTOP* ) nonstop=true ;;
115 | esac
116 |
117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
118 |
119 |
120 | # Determine the Java command to use to start the JVM.
121 | if [ -n "$JAVA_HOME" ] ; then
122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
123 | # IBM's JDK on AIX uses strange locations for the executables
124 | JAVACMD=$JAVA_HOME/jre/sh/java
125 | else
126 | JAVACMD=$JAVA_HOME/bin/java
127 | fi
128 | if [ ! -x "$JAVACMD" ] ; then
129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
130 |
131 | Please set the JAVA_HOME variable in your environment to match the
132 | location of your Java installation."
133 | fi
134 | else
135 | JAVACMD=java
136 | if ! command -v java >/dev/null 2>&1
137 | then
138 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
139 |
140 | Please set the JAVA_HOME variable in your environment to match the
141 | location of your Java installation."
142 | fi
143 | fi
144 |
145 | # Increase the maximum file descriptors if we can.
146 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
147 | case $MAX_FD in #(
148 | max*)
149 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
150 | # shellcheck disable=SC2039,SC3045
151 | MAX_FD=$( ulimit -H -n ) ||
152 | warn "Could not query maximum file descriptor limit"
153 | esac
154 | case $MAX_FD in #(
155 | '' | soft) :;; #(
156 | *)
157 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
158 | # shellcheck disable=SC2039,SC3045
159 | ulimit -n "$MAX_FD" ||
160 | warn "Could not set maximum file descriptor limit to $MAX_FD"
161 | esac
162 | fi
163 |
164 | # Collect all arguments for the java command, stacking in reverse order:
165 | # * args from the command line
166 | # * the main class name
167 | # * -classpath
168 | # * -D...appname settings
169 | # * --module-path (only if needed)
170 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
171 |
172 | # For Cygwin or MSYS, switch paths to Windows format before running java
173 | if "$cygwin" || "$msys" ; then
174 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
175 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
176 |
177 | JAVACMD=$( cygpath --unix "$JAVACMD" )
178 |
179 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
180 | for arg do
181 | if
182 | case $arg in #(
183 | -*) false ;; # don't mess with options #(
184 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
185 | [ -e "$t" ] ;; #(
186 | *) false ;;
187 | esac
188 | then
189 | arg=$( cygpath --path --ignore --mixed "$arg" )
190 | fi
191 | # Roll the args list around exactly as many times as the number of
192 | # args, so each arg winds up back in the position where it started, but
193 | # possibly modified.
194 | #
195 | # NB: a `for` loop captures its iteration list before it begins, so
196 | # changing the positional parameters here affects neither the number of
197 | # iterations, nor the values presented in `arg`.
198 | shift # remove old arg
199 | set -- "$@" "$arg" # push replacement arg
200 | done
201 | fi
202 |
203 |
204 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
205 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
206 |
207 | # Collect all arguments for the java command:
208 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
209 | # and any embedded shellness will be escaped.
210 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
211 | # treated as '${Hostname}' itself on the command line.
212 |
213 | set -- \
214 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
215 | -classpath "$CLASSPATH" \
216 | org.gradle.wrapper.GradleWrapperMain \
217 | "$@"
218 |
219 | # Stop when "xargs" is not available.
220 | if ! command -v xargs >/dev/null 2>&1
221 | then
222 | die "xargs is not available"
223 | fi
224 |
225 | # Use "xargs" to parse quoted args.
226 | #
227 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
228 | #
229 | # In Bash we could simply go:
230 | #
231 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
232 | # set -- "${ARGS[@]}" "$@"
233 | #
234 | # but POSIX shell has neither arrays nor command substitution, so instead we
235 | # post-process each arg (as a line of input to sed) to backslash-escape any
236 | # character that might be a shell metacharacter, then use eval to reverse
237 | # that process (while maintaining the separation between arguments), and wrap
238 | # the whole thing up as a single "set" statement.
239 | #
240 | # This will of course break if any of these variables contains a newline or
241 | # an unmatched quote.
242 | #
243 |
244 | eval "set -- $(
245 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
246 | xargs -n1 |
247 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
248 | tr '\n' ' '
249 | )" '"$@"'
250 |
251 | exec "$JAVACMD" "$@"
252 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/src/main/java/com/romanpierson/vertx/web/accesslogger/AccessLoggerConstants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2025 Roman Pierson
3 | * ------------------------------------------------------
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Apache License v2.0
6 | * which accompanies this distribution.
7 | *
8 | * The Apache License v2.0 is available at
9 | * http://www.opensource.org/licenses/apache2.0.php
10 | *
11 | * You may elect to redistribute this code under either of these licenses.
12 | */
13 | package com.romanpierson.vertx.web.accesslogger;
14 |
15 | public class AccessLoggerConstants {
16 |
17 | private AccessLoggerConstants() {}
18 |
19 | public static final String EVENTBUS_RAW_EVENT_NAME = "accesslog.event.raw";
20 | public static final String EVENTBUS_APPENDER_EVENT_NAME = "accesslog.event.appender";
21 | public static final String EVENTBUS_REGISTER_EVENT_NAME = "accesslog.event.register";
22 |
23 | public static final String ZONE_UTC = "UTC";
24 |
25 | public static class HandlerConfiguration{
26 |
27 | private HandlerConfiguration() {}
28 |
29 | public static final String CONFIG_KEY_CONFIGURATIONS = "configurations";
30 | public static final String CONFIG_KEY_IDENTIFIER = "identifier";
31 | public static final String CONFIG_KEY_LOGPATTERN = "logPattern";
32 | public static final String CONFIG_KEY_APPENDERS = "appenders";
33 | public static final String CONFIG_KEY_APPENDER_CLASS_NAME = "appenderClassName";
34 | public static final String CONFIG_KEY_IS_AUTO_DEPLOY_PRODUCER_VERTICLE = "isAutoDeployProducerVerticle";
35 | }
36 |
37 | public static class InternalValues {
38 |
39 | private InternalValues() {}
40 |
41 | public static final String TIMESTAMP = "timestamp";
42 |
43 | }
44 |
45 | public static class Messages {
46 |
47 | private Messages() {}
48 |
49 | public static class Registration {
50 |
51 | private Registration() {}
52 |
53 | public static class Request {
54 |
55 | private Request() {}
56 |
57 | public static final String IDENTIFIER = "identifier";
58 | public static final String LOGPATTERN = "logPattern";
59 | public static final String APPENDERS = "appenders";
60 | public static final String APPENDER_CLASS_NAME = "appenderClassName";
61 | public static final String APPENDER_CONFIG = "config";
62 |
63 | }
64 |
65 | public static class Response {
66 |
67 | private Response() {}
68 |
69 | public static final String REQUIRES_COOKIES = "requiresCookies";
70 | public static final String REQUIRES_INCOMING_HEADERS = "requiresIncomingHeaders";
71 | public static final String REQUIRES_OUTGOING_HEADERS = "requiresOutgoingHeaders";
72 | public static final String RESULT = "result";
73 | public static final String RESULT_OK = "OK";
74 | public static final String RESULT_FAILED = "FAILED";
75 | }
76 | }
77 |
78 | public static class RawEvent {
79 |
80 | private RawEvent() {}
81 |
82 | public static class Request {
83 |
84 | private Request() {}
85 |
86 | public static final String IDENTIFIERS = "identifiers";
87 |
88 | }
89 |
90 | }
91 |
92 | }
93 |
94 | public static final String CONFIG_KEY_RESOLVED_PATTERN = "resolvedPattern";
95 |
96 | public static class Request{
97 |
98 | private Request() {}
99 |
100 | public static class Data{
101 |
102 | private Data() {}
103 |
104 | public enum Type{
105 |
106 | REMOTE_HOST("remoteHost"),
107 | LOCAL_HOST("localHost"),
108 | LOCAL_PORT("localPort"),
109 | START_TS_MILLIS("startTSmillis"),
110 | END_TS_MILLIS("endTSmillis"),
111 | BYTES_SENT("bytesSent"),
112 | URI("uri"),
113 | STATUS("status"),
114 | METHOD("method"),
115 | VERSION("version"),
116 | QUERY("query"),
117 | REQUEST_HEADERS("requestHeaders"),
118 | RESPONSE_HEADERS("responseHeaders"),
119 | COOKIES("cookies");
120 |
121 | private final String fieldName;
122 |
123 | private Type(String fieldName) {
124 | this.fieldName = fieldName;
125 | }
126 |
127 | public String getFieldName() {
128 | return this.fieldName;
129 | }
130 | }
131 |
132 | public static class Fields{
133 |
134 | private Fields() {}
135 |
136 | public static final String COOKIE_NAME = "name";
137 | public static final String COOKIE_VALUE = "value";
138 |
139 | }
140 |
141 | }
142 | }
143 |
144 | public static class ElasticSearchAppenderConfig{
145 |
146 | private ElasticSearchAppenderConfig() {}
147 |
148 | public static final String ELASTICSEARCH_INDEXER_EVENTBUS_EVENT_NAME = "es.indexer.event";
149 |
150 | public static class Field{
151 |
152 | private Field() {}
153 |
154 | public static final String TIMESTAMP = "timestamp";
155 | public static final String INSTANCE_IDENTIFIER = "instance_identifier";
156 | public static final String META = "meta";
157 | public static final String MESSAGE = "message";
158 |
159 | }
160 | }
161 |
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/src/main/java/com/romanpierson/vertx/web/accesslogger/AccessLoggerHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2025 Roman Pierson
3 | * ------------------------------------------------------
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Apache License v2.0
6 | * which accompanies this distribution.
7 | *
8 | * The Apache License v2.0 is available at
9 | * http://www.opensource.org/licenses/apache2.0.php
10 | *
11 | * You may elect to redistribute this code under either of these licenses.
12 | */
13 | package com.romanpierson.vertx.web.accesslogger;
14 |
15 | import com.romanpierson.vertx.web.accesslogger.impl.AccessLoggerHandlerImpl;
16 |
17 | import io.vertx.core.Handler;
18 | import io.vertx.core.json.JsonObject;
19 | import io.vertx.ext.web.RoutingContext;
20 |
21 | /**
22 | *
23 | * A handler that logs access information
24 | *
25 | * @author Roman Pierson
26 | *
27 | */
28 | public interface AccessLoggerHandler extends Handler {
29 |
30 | /**
31 | *
32 | * Creates a logging handler by passing an {@link JsonObject} configuration
33 | *
34 | * @param config The access logger configuration
35 | * @return The logging handler
36 | */
37 | static AccessLoggerHandler create(final JsonObject config){
38 |
39 | return new AccessLoggerHandlerImpl(config);
40 |
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/com/romanpierson/vertx/web/accesslogger/appender/Appender.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2016-2025 Roman Pierson
3 | * ------------------------------------------------------
4 | * All rights reserved. This program and the accompanying materials
5 | * are made available under the terms of the Apache License v2.0
6 | * which accompanies this distribution.
7 | *
8 | * The Apache License v2.0 is available at
9 | * http://www.opensource.org/licenses/apache2.0.php
10 | *
11 | * You may elect to redistribute this code under either of these licenses.
12 | */
13 | package com.romanpierson.vertx.web.accesslogger.appender;
14 |
15 | import java.util.List;
16 | import java.util.Map;
17 |
18 | /**
19 | *
20 | * An IF defining an appender that can handle Access Events
21 | *
22 | * @author Roman Pierson
23 | *
24 | */
25 | public interface Appender {
26 |
27 | /**
28 | *
29 | * Push the access element values to the appender.
30 | *
31 | * Those values can contain native data types and null values
32 | *
33 | * Its the appenders responsibility to implement local storage
34 | *
35 | * @param rawAccessElementValues List of access events the appender should handle - those are no copies
36 | * @param internalValues A list of internal values that are sent independent from the configured access log elements
37 | */
38 | void push(List