This README provides an overview of a Java Spring service for managing API logs. This service is designed to create a single log file for each day and schedule a cron job to upload that log file to Azure Blob Storage after 24 hours. You can configure the service using the application.yml
file and adjust the scheduling interval in the SchaduleTask.java
class. ๐
- Prerequisites โ๏ธ
- Configuration ๐ ๏ธ
- Logging Format ๐
- Running the Service
โถ๏ธ
Before setting up and running the service, make sure you have the following prerequisites:
- Java Development Kit (JDK) installed (version 8 or higher).
- Maven installed to build the project.
- Azure Blob Storage account with a container.
- Azure Storage Connection String.
You can configure the service by editing the application.yml
file. Replace <YOUR_CONTAINER_NAME>
and <YOUR_CONNECTION_STRING>
with your Azure Blob Storage container name and connection string, respectively. ๐งฉ
azure:
storage:
container:
name: <YOUR_CONTAINER_NAME>
connection:
string: <YOUR_CONNECTION_STRING>
The log files generated by this service will have the following format:
[Date Time] [Client IP] [Client Port] [Server IP] [Server Port] [Protocol] [Method] [URL] [Protocol] [Server IP] [Server Port] [Status Code] [Status Message]
For example:
2023-10-07 21:35:29 127.0.0.1 4035 127.0.0.1 8080 HTTP/1.1 GET /log HTTP/1.1 127.0.0.1 400 log file upload Failed
- Clone this repository to your local machine. ๐งฌ
git clone https://github.com/your/repository.git
cd repository-directory
-
Open the project in your preferred Java IDE. ๐
-
Configure the
application.yml
file with your Azure Blob Storage information. ๐งพ -
In the
SchaduleTask.java
class, adjust the scheduling interval by changing the@Scheduled
annotation'sfixedRate
value according to your desired schedule. ๐
@Scheduled(fixedRate = 86400000) // Change this value to your desired interval in milliseconds (24 hours by default).
public void uploadLogFileToAzureStorage() {
// ...
}
- Build the project using Maven. ๐๏ธ
mvn clean install
- Run the Spring Boot application.
โถ๏ธ
mvn spring-boot:run
The service will start, and it will create a new log file for each day in the specified format. After 24 hours, the cron job will trigger the upload of the log file to Azure Blob Storage.
You have successfully set up and configured the Java Spring service for managing API logs with Azure Blob Storage integration. ๐๐ฆ