Compare commits
5 Commits
682d801836
...
45a98daae0
Author | SHA1 | Date | |
---|---|---|---|
45a98daae0 | |||
6445278e9f | |||
8c39c1955e | |||
a846547d38 | |||
2d0e676a77 |
@ -1,6 +1,10 @@
|
||||
SPRING_PROFILES_ACTIVE=dev
|
||||
|
||||
DB_NAME=EXAMPLE_DB
|
||||
DB_USER=EXAMPLE
|
||||
DB_PASSWORD=SECRET
|
||||
DB_HOST=127.0.0.1
|
||||
DB_PORT=5432
|
||||
SPRING_PROFILES_ACTIVE=dev
|
||||
|
||||
GMAIL_OAUTH_CLIENT_ID=11111111111-1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a.apps.googleusercontent.com
|
||||
GMAIL_OAUTH_CLIENT_SECRET=AAAAAA-1a1a1a1a1a1a1_A1a1_A1A1A1A1A
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,6 +3,7 @@
|
||||
*.db
|
||||
target
|
||||
logs
|
||||
tokens
|
||||
.env
|
||||
|
||||
Icon?
|
@ -6,5 +6,8 @@ RUN mvn clean package -DskipTests
|
||||
FROM openjdk:21-jdk
|
||||
WORKDIR /app
|
||||
COPY --from=build /app/bootstrap/target/*.jar app.jar
|
||||
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["java","-jar","app.jar"]
|
||||
EXPOSE 5005
|
||||
|
||||
ENTRYPOINT ["java", "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005", "-jar", "app.jar"]
|
@ -16,5 +16,12 @@
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.13</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
@ -5,20 +5,47 @@ import com.pablotj.restemailbridge.application.port.EmailConfigurationPort;
|
||||
import com.pablotj.restemailbridge.domain.model.Email;
|
||||
import com.pablotj.restemailbridge.domain.repository.EmailRepository;
|
||||
import com.pablotj.restemailbridge.domain.service.EmailService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Use case for sending emails.
|
||||
* <p>
|
||||
* Retrieves the default recipient from EmailConfigurationPort, sends the email using EmailService,
|
||||
* and persists it via EmailRepository.
|
||||
*/
|
||||
public class SendEmailUseCase {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(SendEmailUseCase.class);
|
||||
|
||||
private final EmailConfigurationPort emailConfigurationPort;
|
||||
private final EmailService emailService;
|
||||
private final EmailRepository emailRepository;
|
||||
|
||||
public SendEmailUseCase(EmailConfigurationPort emailConfigurationPort, EmailService emailService, EmailRepository emailRepository) {
|
||||
/**
|
||||
* Constructor injecting required ports.
|
||||
*
|
||||
* @param emailConfigurationPort Port to retrieve configuration
|
||||
* @param emailService Service to send emails
|
||||
* @param emailRepository Repository to persist emails
|
||||
*/
|
||||
public SendEmailUseCase(EmailConfigurationPort emailConfigurationPort,
|
||||
EmailService emailService,
|
||||
EmailRepository emailRepository) {
|
||||
this.emailConfigurationPort = emailConfigurationPort;
|
||||
this.emailService = emailService;
|
||||
this.emailRepository = emailRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles sending an email based on the provided DTO.
|
||||
*
|
||||
* @param emailDTO DTO containing from, subject, and body
|
||||
*/
|
||||
public void handle(EmailDTO emailDTO) {
|
||||
String to = emailConfigurationPort.getDefaultRecipient();
|
||||
log.info("Sending email from {} to {}", emailDTO.from(), to);
|
||||
|
||||
Email email = emailService.sendEmail(
|
||||
Email.builder()
|
||||
.from(emailDTO.from())
|
||||
@ -27,6 +54,8 @@ public class SendEmailUseCase {
|
||||
.body(emailDTO.body())
|
||||
.build()
|
||||
);
|
||||
emailRepository.save(email);
|
||||
|
||||
emailRepository.save(email); // Persist the sent email
|
||||
log.info("Email successfully sent and persisted to repository for recipient {}", to);
|
||||
}
|
||||
}
|
@ -33,10 +33,22 @@
|
||||
<version>${springdoc.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.13</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Actuator -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
|
@ -33,6 +33,12 @@ server:
|
||||
context-path: /api
|
||||
forward-headers-strategy: framework
|
||||
|
||||
gmail:
|
||||
oauth2:
|
||||
clientId: ${GMAIL_OAUTH_CLIENT_ID}
|
||||
clientSecret: ${GMAIL_OAUTH_CLIENT_SECRET}
|
||||
redirectUri: http://localhost:8888/Callback
|
||||
|
||||
---
|
||||
|
||||
spring:
|
||||
|
@ -3,6 +3,8 @@ services:
|
||||
build: .
|
||||
ports:
|
||||
- "8080:8080"
|
||||
- "5005:5005"
|
||||
- "8888:8888"
|
||||
depends_on:
|
||||
- db
|
||||
environment:
|
||||
@ -11,8 +13,13 @@ services:
|
||||
DB_PORT: ${DB_PORT}
|
||||
DB_USER: ${DB_USER}
|
||||
DB_PASSWORD: ${DB_PASSWORD}
|
||||
GMAIL_OAUTH_CLIENT_ID: ${GMAIL_OAUTH_CLIENT_ID}
|
||||
GMAIL_OAUTH_CLIENT_SECRET: ${GMAIL_OAUTH_CLIENT_SECRET}
|
||||
networks:
|
||||
- network
|
||||
volumes:
|
||||
- ./tokens:/app/tokens
|
||||
- ./logs:/app/logs
|
||||
db:
|
||||
image: postgres:15
|
||||
ports:
|
||||
|
@ -16,5 +16,10 @@
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>2.0.13</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -23,6 +23,22 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-mail</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@ -39,6 +55,80 @@
|
||||
<version>0.10.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.http-client</groupId>
|
||||
<artifactId>google-http-client-jackson2</artifactId>
|
||||
<version>1.43.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.google.api-client/google-api-client -->
|
||||
<dependency>
|
||||
<groupId>com.google.api-client</groupId>
|
||||
<artifactId>google-api-client</artifactId>
|
||||
<version>1.35.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.oauth-client</groupId>
|
||||
<artifactId>google-oauth-client-jetty</artifactId>
|
||||
<version>1.39.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.apis</groupId>
|
||||
<artifactId>google-api-services-gmail</artifactId>
|
||||
<version>v1-rev110-1.25.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>javax.mail-api</artifactId>
|
||||
<version>1.6.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.mail</groupId>
|
||||
<artifactId>jakarta.mail</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun.activation</groupId>
|
||||
<artifactId>jakarta.activation</artifactId>
|
||||
<version>2.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.24.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j2-impl</artifactId>
|
||||
<version>2.24.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.24.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- MapStruct -->
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
@ -52,4 +142,11 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>maven_central</id>
|
||||
<name>Maven Central</name>
|
||||
<url>https://repo.maven.apache.org/maven2/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
</project>
|
@ -1,4 +1,4 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.config.spring;
|
||||
package com.pablotj.restemailbridge.infrastructure.config;
|
||||
|
||||
import com.pablotj.restemailbridge.application.port.EmailConfigurationPort;
|
||||
import com.pablotj.restemailbridge.application.usecase.SendEmailUseCase;
|
@ -0,0 +1,13 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
public class GmailConfigurationException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public GmailConfigurationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
public class GmailInitializationException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public GmailInitializationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.exception;
|
||||
|
||||
import java.io.Serial;
|
||||
|
||||
public class GmailSendErrorException extends RuntimeException {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public GmailSendErrorException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.config;
|
||||
package com.pablotj.restemailbridge.infrastructure.mail;
|
||||
|
||||
import com.pablotj.restemailbridge.application.port.EmailConfigurationPort;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -7,6 +7,6 @@ import org.springframework.stereotype.Component;
|
||||
public class EmailConfigurationAdapter implements EmailConfigurationPort {
|
||||
@Override
|
||||
public String getDefaultRecipient() {
|
||||
return "1234@1234.com";
|
||||
return "pablodelatorree@gmail.com";
|
||||
}
|
||||
}
|
@ -1,15 +1,182 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.mail;
|
||||
|
||||
import com.google.api.client.auth.oauth2.Credential;
|
||||
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
||||
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
|
||||
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.json.gson.GsonFactory;
|
||||
import com.google.api.client.util.store.FileDataStoreFactory;
|
||||
import com.google.api.services.gmail.Gmail;
|
||||
import com.google.api.services.gmail.GmailScopes;
|
||||
import com.google.api.services.gmail.model.Message;
|
||||
import com.pablotj.restemailbridge.domain.model.Email;
|
||||
import com.pablotj.restemailbridge.domain.service.EmailService;
|
||||
import com.pablotj.restemailbridge.infrastructure.exception.GmailConfigurationException;
|
||||
import com.pablotj.restemailbridge.infrastructure.exception.GmailInitializationException;
|
||||
import com.pablotj.restemailbridge.infrastructure.exception.GmailSendErrorException;
|
||||
import com.pablotj.restemailbridge.infrastructure.mail.config.GmailOAuth2Properties;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.mail.MessagingException;
|
||||
import jakarta.mail.Session;
|
||||
import jakarta.mail.internet.InternetAddress;
|
||||
import jakarta.mail.internet.MimeMessage;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Gmail implementation of the EmailService using OAuth2 authentication.
|
||||
* <p>
|
||||
* Handles sending emails via Gmail API and manages credentials stored in a local token folder.
|
||||
*/
|
||||
@Component
|
||||
public class GmailOAuth2MailService implements EmailService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GmailOAuth2MailService.class);
|
||||
private static final String APPLICATION_NAME = "MailServiceApi";
|
||||
private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
|
||||
private static final List<String> SCOPES = Collections.singletonList(GmailScopes.GMAIL_SEND);
|
||||
private static final String TOKENS_DIRECTORY_PATH = "/app/tokens";
|
||||
|
||||
private final GmailOAuth2Properties properties;
|
||||
private Gmail service;
|
||||
|
||||
/**
|
||||
* Constructor injecting Gmail OAuth2 properties.
|
||||
*
|
||||
* @param properties OAuth2 configuration for Gmail
|
||||
*/
|
||||
public GmailOAuth2MailService(GmailOAuth2Properties properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the Gmail client with OAuth2 credentials.
|
||||
* <p>
|
||||
* Loads the token from the token folder, sets up the OAuth2 flow,
|
||||
* and initializes the Gmail API client.
|
||||
*
|
||||
* @throws GmailConfigurationException if token folder or credentials are missing
|
||||
* @throws GmailInitializationException if any other initialization error occurs
|
||||
*/
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
try {
|
||||
log.info("Initializing Gmail OAuth2 client...");
|
||||
|
||||
GoogleClientSecrets clientSecrets = new GoogleClientSecrets()
|
||||
.setInstalled(
|
||||
new GoogleClientSecrets.Details()
|
||||
.setClientId(properties.clientId())
|
||||
.setClientSecret(properties.clientSecret())
|
||||
.setRedirectUris(Collections.singletonList(properties.redirectUri()))
|
||||
);
|
||||
|
||||
File tokenFolder = new File(TOKENS_DIRECTORY_PATH);
|
||||
if (!tokenFolder.exists() || !tokenFolder.isDirectory()) {
|
||||
log.error("Token folder not found: {}", TOKENS_DIRECTORY_PATH);
|
||||
throw new GmailConfigurationException("Token folder missing: " + TOKENS_DIRECTORY_PATH);
|
||||
}
|
||||
|
||||
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
|
||||
GoogleNetHttpTransport.newTrustedTransport(),
|
||||
JSON_FACTORY,
|
||||
clientSecrets,
|
||||
SCOPES)
|
||||
.setDataStoreFactory(new FileDataStoreFactory(tokenFolder))
|
||||
.setAccessType("offline")
|
||||
.build();
|
||||
|
||||
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
|
||||
Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
|
||||
if (credential == null) {
|
||||
log.error("No stored credentials found. Generate tokens first.");
|
||||
throw new GmailConfigurationException("No stored credentials found. Generate tokens first.");
|
||||
}
|
||||
|
||||
service = new Gmail.Builder(GoogleNetHttpTransport.newTrustedTransport(), JSON_FACTORY, credential)
|
||||
.setApplicationName(APPLICATION_NAME)
|
||||
.build();
|
||||
|
||||
log.info("Gmail OAuth2 client initialized successfully.");
|
||||
|
||||
} catch (Exception e) {
|
||||
if (e instanceof GmailConfigurationException configEx) {
|
||||
throw configEx;
|
||||
}
|
||||
log.error("Failed to initialize Gmail client");
|
||||
throw new GmailInitializationException("Failed to initialize Gmail client", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an email using the Gmail API.
|
||||
*
|
||||
* @param email Email object containing recipient, sender, subject, and body
|
||||
* @return The same Email object after sending
|
||||
* @throws GmailSendErrorException if sending fails
|
||||
*/
|
||||
@Override
|
||||
public Email sendEmail(Email email) {
|
||||
System.out.println("Sending email " + email.getSubject() + " to " + email.getTo());
|
||||
try {
|
||||
log.info("Sending email to {}", email.getTo());
|
||||
MimeMessage message = createEmail(email.getTo(), email.getFrom(), email.getSubject(), email.getBody());
|
||||
sendMessage(service, message);
|
||||
log.info("Email sent successfully to {}", email.getTo());
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to send email to {}", email.getTo());
|
||||
throw new GmailSendErrorException("Failed to send email", e);
|
||||
}
|
||||
return email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a MimeMessage from the given parameters.
|
||||
*
|
||||
* @param to Recipient email
|
||||
* @param from Sender email
|
||||
* @param subject Email subject
|
||||
* @param bodyText Email body
|
||||
* @return MimeMessage ready to be sent
|
||||
* @throws MessagingException if creation fails
|
||||
*/
|
||||
private static MimeMessage createEmail(String to, String from, String subject, String bodyText) throws MessagingException {
|
||||
Properties props = new Properties();
|
||||
Session session = Session.getDefaultInstance(props, null);
|
||||
MimeMessage email = new MimeMessage(session);
|
||||
email.setReplyTo(new jakarta.mail.Address[]{new InternetAddress(from)});
|
||||
email.setFrom(new InternetAddress(from));
|
||||
email.addRecipient(jakarta.mail.Message.RecipientType.TO, new InternetAddress(to));
|
||||
email.setSubject(subject);
|
||||
email.setText(bodyText);
|
||||
return email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends the MimeMessage using the Gmail API.
|
||||
*
|
||||
* @param service Gmail client
|
||||
* @param email MimeMessage to send
|
||||
* @throws MessagingException if message creation fails
|
||||
* @throws IOException if API call fails
|
||||
*/
|
||||
private static void sendMessage(Gmail service, MimeMessage email) throws MessagingException, IOException {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
email.writeTo(buffer);
|
||||
String encodedEmail = Base64.getUrlEncoder().encodeToString(buffer.toByteArray());
|
||||
Message message = new Message();
|
||||
message.setRaw(encodedEmail);
|
||||
service.users().messages().send("me", message).execute();
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.mail.config;
|
||||
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(GmailOAuth2Properties.class)
|
||||
public class GmailConfig {
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.pablotj.restemailbridge.infrastructure.mail.config;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@ConfigurationProperties(prefix = "gmail.oauth2")
|
||||
public record GmailOAuth2Properties(
|
||||
String clientId,
|
||||
String clientSecret,
|
||||
String redirectUri
|
||||
) {}
|
99
infrastructure/src/main/resources/log4j2.properties
Normal file
99
infrastructure/src/main/resources/log4j2.properties
Normal file
@ -0,0 +1,99 @@
|
||||
# ========== Log4j2 Properties Configuration ==========
|
||||
status = error
|
||||
name = PropertiesConfig
|
||||
|
||||
property.basePath = logs
|
||||
|
||||
# ========== Appenders ==========
|
||||
|
||||
# Console
|
||||
appender.console.type = Console
|
||||
appender.console.name = ConsoleAppender
|
||||
appender.console.layout.type = PatternLayout
|
||||
appender.console.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] [%t] %-5level %logger{36} - %msg%n
|
||||
|
||||
# Rolling File INFO+ (DEBUG e INFO)
|
||||
appender.info.type = RollingFile
|
||||
appender.info.name = InfoFileAppender
|
||||
appender.info.fileName = ${basePath}/info.log
|
||||
appender.info.filePattern = ${basePath}/info-%d{yyyy-MM-dd}-%i.log.gz
|
||||
appender.info.layout.type = PatternLayout
|
||||
appender.info.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] [%t] %-5level %logger{36} - %msg%n
|
||||
appender.info.policies.type = Policies
|
||||
appender.info.policies.time.type = TimeBasedTriggeringPolicy
|
||||
appender.info.policies.time.interval = 1
|
||||
appender.info.policies.size.type = SizeBasedTriggeringPolicy
|
||||
appender.info.policies.size.size = 10MB
|
||||
appender.info.filter.threshold.type = ThresholdFilter
|
||||
appender.info.filter.threshold.level = debug
|
||||
appender.info.filter.threshold.onMatch = ACCEPT
|
||||
appender.info.filter.threshold.onMismatch = DENY
|
||||
|
||||
# Rolling File ERROR+ (ERROR y FATAL)
|
||||
appender.error.type = RollingFile
|
||||
appender.error.name = ErrorFileAppender
|
||||
appender.error.fileName = ${basePath}/error.log
|
||||
appender.error.filePattern = ${basePath}/error-%d{yyyy-MM-dd}-%i.log.gz
|
||||
appender.error.layout.type = PatternLayout
|
||||
appender.error.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] [%t] %-5level %logger{36} - %msg%n
|
||||
appender.error.policies.type = Policies
|
||||
appender.error.policies.time.type = TimeBasedTriggeringPolicy
|
||||
appender.error.policies.time.interval = 1
|
||||
appender.error.policies.size.type = SizeBasedTriggeringPolicy
|
||||
appender.error.policies.size.size = 10MB
|
||||
appender.error.filter.threshold.type = ThresholdFilter
|
||||
appender.error.filter.threshold.level = error
|
||||
appender.error.filter.threshold.onMatch = ACCEPT
|
||||
appender.error.filter.threshold.onMismatch = DENY
|
||||
|
||||
# Rolling File for Database logs (Hibernate / JDBC)
|
||||
appender.db.type = RollingFile
|
||||
appender.db.name = DBFileAppender
|
||||
appender.db.fileName = ${basePath}/db.log
|
||||
appender.db.filePattern = ${basePath}/db-%d{yyyy-MM-dd}-%i.log.gz
|
||||
appender.db.layout.type = PatternLayout
|
||||
appender.db.layout.pattern = [%d{yyyy-MM-dd HH:mm:ss}] [%t] %-5level %logger{36} - %msg%n
|
||||
appender.db.policies.type = Policies
|
||||
appender.db.policies.time.type = TimeBasedTriggeringPolicy
|
||||
appender.db.policies.time.interval = 1
|
||||
appender.db.policies.size.type = SizeBasedTriggeringPolicy
|
||||
appender.db.policies.size.size = 10MB
|
||||
|
||||
# ========== Loggers ==========
|
||||
|
||||
# App logs
|
||||
logger.app.name = com.pablotj
|
||||
logger.app.level = debug
|
||||
logger.app.additivity = false
|
||||
logger.app.appenderRefs = console, info, error
|
||||
logger.app.appenderRef.console.ref = ConsoleAppender
|
||||
logger.app.appenderRef.info.ref = InfoFileAppender
|
||||
logger.app.appenderRef.error.ref = ErrorFileAppender
|
||||
|
||||
# Hibernate SQL
|
||||
logger.hibernate.name = org.hibernate.SQL
|
||||
logger.hibernate.level = debug
|
||||
logger.hibernate.additivity = false
|
||||
logger.hibernate.appenderRefs = db
|
||||
logger.hibernate.appenderRef.db.ref = DBFileAppender
|
||||
|
||||
# Hibernate parameter binding
|
||||
#logger.hibernate.type.name = org.hibernate.type.descriptor.sql.BasicBinder
|
||||
#logger.hibernate.type.level = trace
|
||||
#logger.hibernate.type.additivity = false
|
||||
#logger.hibernate.type.appenderRefs = db
|
||||
#logger.hibernate.type.appenderRef.db.ref = DBFileAppender
|
||||
|
||||
# Spring JDBC Template logs
|
||||
#logger.spring.sql.name = org.springframework.jdbc.core.JdbcTemplate
|
||||
#logger.spring.sql.level = debug
|
||||
#logger.spring.sql.additivity = false
|
||||
#logger.spring.sql.appenderRefs = db
|
||||
#logger.spring.sql.appenderRef.db.ref = DBFileAppender
|
||||
|
||||
# ========== Root Logger ==========
|
||||
rootLogger.level = info
|
||||
rootLogger.appenderRefs = console, info, error
|
||||
rootLogger.appenderRef.console.ref = ConsoleAppender
|
||||
rootLogger.appenderRef.info.ref = InfoFileAppender
|
||||
rootLogger.appenderRef.error.ref = ErrorFileAppender
|
Loading…
x
Reference in New Issue
Block a user