mirror of
				https://github.com/brmlab/wekan-mailer.git
				synced 2025-10-30 23:14:01 +01:00 
			
		
		
		
	Enhance logging with use of lombok
This commit is contained in:
		
							parent
							
								
									28bbf0815e
								
							
						
					
					
						commit
						1bff1b0f6e
					
				
					 6 changed files with 43 additions and 21 deletions
				
			
		|  | @ -2,21 +2,23 @@ package cz.brmlab.wm; | ||||||
| 
 | 
 | ||||||
| import cz.brmlab.wm.utils.Exceptions.BrmException; | import cz.brmlab.wm.utils.Exceptions.BrmException; | ||||||
| import cz.brmlab.wm.wekan.WekanConfiguration; | import cz.brmlab.wm.wekan.WekanConfiguration; | ||||||
| import cz.brmlab.wm.wekan.pojo.card.CardRequest; |  | ||||||
| import cz.brmlab.wm.wekan.rest.CardPost; | import cz.brmlab.wm.wekan.rest.CardPost; | ||||||
| import cz.brmlab.wm.wekan.rest.LoginPost; | import cz.brmlab.wm.wekan.rest.LoginPost; | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||||
| import org.springframework.boot.CommandLineRunner; | import org.springframework.boot.CommandLineRunner; | ||||||
| import org.springframework.boot.SpringApplication; | import org.springframework.boot.SpringApplication; | ||||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||||
| 
 | 
 | ||||||
|  | @Slf4j | ||||||
| @SpringBootApplication | @SpringBootApplication | ||||||
| public class Application implements CommandLineRunner { | public class Application implements CommandLineRunner { | ||||||
| 
 | 
 | ||||||
|     private static final Logger LOG = LoggerFactory.getLogger(Application.class); |     private static final Logger LOG = LoggerFactory.getLogger(Application.class); | ||||||
| 
 | 
 | ||||||
|     public static void main(String[] args) { |     public static void main(String[] args) { | ||||||
|  |         log.trace("Starting wekan-mailer app..."); | ||||||
|         SpringApplication.run(Application.class, args); |         SpringApplication.run(Application.class, args); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -33,6 +35,7 @@ public class Application implements CommandLineRunner { | ||||||
|             cardPost.postCard("Test from spring", "Test card from awesome spring app.\nAnd next line"); |             cardPost.postCard("Test from spring", "Test card from awesome spring app.\nAnd next line"); | ||||||
| 
 | 
 | ||||||
|         } catch (BrmException ex) { |         } catch (BrmException ex) { | ||||||
|  |             log.error("Error {} encountered, shutting down!", ex.getExitCode()); | ||||||
|             System.exit(ex.getExitCode().getCode()); |             System.exit(ex.getExitCode().getCode()); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
							
								
								
									
										17
									
								
								src/main/java/cz/brmlab/wm/utils/LogMarker/LogMarker.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								src/main/java/cz/brmlab/wm/utils/LogMarker/LogMarker.java
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | ||||||
|  | package cz.brmlab.wm.utils.LogMarker; | ||||||
|  | 
 | ||||||
|  | import lombok.Getter; | ||||||
|  | import org.slf4j.Marker; | ||||||
|  | import org.slf4j.MarkerFactory; | ||||||
|  | 
 | ||||||
|  | public enum LogMarker { | ||||||
|  | 
 | ||||||
|  |     SECRET("SECRET"); | ||||||
|  | 
 | ||||||
|  |     @Getter | ||||||
|  |     private Marker marker; | ||||||
|  | 
 | ||||||
|  |     LogMarker(String markerText) { | ||||||
|  |         this.marker = MarkerFactory.getMarker(markerText); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -3,20 +3,15 @@ package cz.brmlab.wm.wekan; | ||||||
| import cz.brmlab.wm.utils.Exceptions.BrmException; | import cz.brmlab.wm.utils.Exceptions.BrmException; | ||||||
| import cz.brmlab.wm.utils.Exceptions.ExitCode; | import cz.brmlab.wm.utils.Exceptions.ExitCode; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
| import org.slf4j.Logger; | import lombok.extern.slf4j.Slf4j; | ||||||
| import org.slf4j.LoggerFactory; |  | ||||||
| 
 | 
 | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| import java.util.Arrays; | import java.util.Arrays; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
|  | @Slf4j | ||||||
| public class WekanConfiguration { | public class WekanConfiguration { | ||||||
| 
 | 
 | ||||||
|     /** |  | ||||||
|      * Class logger |  | ||||||
|      */ |  | ||||||
|     private static final Logger LOG = LoggerFactory.getLogger(WekanConfiguration.class); |  | ||||||
| 
 |  | ||||||
|     //ENV variables for wekan |     //ENV variables for wekan | ||||||
|     private static final String WEKAN_URL = "WEKAN_URL"; |     private static final String WEKAN_URL = "WEKAN_URL"; | ||||||
|     private static final String WEKAN_USER = "WEKAN_USER"; |     private static final String WEKAN_USER = "WEKAN_USER"; | ||||||
|  | @ -33,7 +28,7 @@ public class WekanConfiguration { | ||||||
|      * @throws BrmException if some of the properties is missing in ENV variables. |      * @throws BrmException if some of the properties is missing in ENV variables. | ||||||
|      */ |      */ | ||||||
|     public WekanConfiguration() throws BrmException { |     public WekanConfiguration() throws BrmException { | ||||||
|         LOG.trace("{}() - start.", this.getClass().getSimpleName()); |         log.trace("{}() - start.", this.getClass().getSimpleName()); | ||||||
| 
 | 
 | ||||||
|         for (String prop : properties) { |         for (String prop : properties) { | ||||||
|             checkProp(prop); |             checkProp(prop); | ||||||
|  | @ -44,7 +39,7 @@ public class WekanConfiguration { | ||||||
|         this.wekanBoard = System.getenv(WEKAN_TARGET_BOARD); |         this.wekanBoard = System.getenv(WEKAN_TARGET_BOARD); | ||||||
|         this.wekanList = System.getenv(WEKAN_TARGET_LIST); |         this.wekanList = System.getenv(WEKAN_TARGET_LIST); | ||||||
| 
 | 
 | ||||||
|         LOG.info("Wekan config loaded successfully."); |         log.info("Wekan config loaded successfully."); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     @Getter |     @Getter | ||||||
|  | @ -63,11 +58,11 @@ public class WekanConfiguration { | ||||||
|     private String wekanList; |     private String wekanList; | ||||||
| 
 | 
 | ||||||
|     private void checkProp(String prop) throws BrmException { |     private void checkProp(String prop) throws BrmException { | ||||||
|         LOG.trace("checkProp({}) - start.", prop); |         log.trace("checkProp({}) - start.", prop); | ||||||
| 
 | 
 | ||||||
|         if (System.getenv(prop) == null) { |         if (System.getenv(prop) == null) { | ||||||
|             String message = ExitCode.CONFIGURATION_MISSING.getReason() + prop; |             String message = ExitCode.CONFIGURATION_MISSING.getReason() + prop; | ||||||
|             LOG.error(message, ExitCode.CONFIGURATION_MISSING); |             log.error(message, ExitCode.CONFIGURATION_MISSING); | ||||||
|             throw new BrmException(message, ExitCode.CONFIGURATION_MISSING); |             throw new BrmException(message, ExitCode.CONFIGURATION_MISSING); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -1,7 +1,5 @@ | ||||||
| package cz.brmlab.wm.wekan.pojo.card; | package cz.brmlab.wm.wekan.pojo.card; | ||||||
| 
 | 
 | ||||||
| import cz.brmlab.wm.wekan.WekanConfiguration; |  | ||||||
| import cz.brmlab.wm.wekan.pojo.login.LoginToken; |  | ||||||
| import lombok.Data; | import lombok.Data; | ||||||
| 
 | 
 | ||||||
| @Data | @Data | ||||||
|  |  | ||||||
|  | @ -4,23 +4,24 @@ import cz.brmlab.wm.wekan.WekanConfiguration; | ||||||
| import cz.brmlab.wm.wekan.pojo.card.CardRequest; | import cz.brmlab.wm.wekan.pojo.card.CardRequest; | ||||||
| import cz.brmlab.wm.wekan.pojo.card.CardResponse; | import cz.brmlab.wm.wekan.pojo.card.CardResponse; | ||||||
| import cz.brmlab.wm.wekan.pojo.login.LoginToken; | import cz.brmlab.wm.wekan.pojo.login.LoginToken; | ||||||
| import org.slf4j.Logger; | import lombok.extern.slf4j.Slf4j; | ||||||
| import org.slf4j.LoggerFactory; |  | ||||||
| import org.springframework.web.client.RestTemplate; | import org.springframework.web.client.RestTemplate; | ||||||
| 
 | 
 | ||||||
|  | @Slf4j | ||||||
| public class CardPost { | public class CardPost { | ||||||
| 
 | 
 | ||||||
|     private static final Logger LOG = LoggerFactory.getLogger(CardPost.class); |  | ||||||
| 
 |  | ||||||
|     private final LoginToken token; |     private final LoginToken token; | ||||||
|     private final WekanConfiguration configuration; |     private final WekanConfiguration configuration; | ||||||
| 
 | 
 | ||||||
|     public CardPost(LoginToken token, WekanConfiguration configuration) { |     public CardPost(LoginToken token, WekanConfiguration configuration) { | ||||||
|  |         log.trace("{}() - start.", this.getClass().getSimpleName()); | ||||||
|         this.token = token; |         this.token = token; | ||||||
|         this.configuration = configuration; |         this.configuration = configuration; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     public CardResponse postCard(String title, String description) { |     public CardResponse postCard(String title, String description) { | ||||||
|  |         log.trace("postCard({}, {}) - start.", title, description); | ||||||
|  | 
 | ||||||
|         CardRequest cardRequest = new CardRequest(); |         CardRequest cardRequest = new CardRequest(); | ||||||
|         cardRequest.setAuthorId(token.getId()); |         cardRequest.setAuthorId(token.getId()); | ||||||
|         cardRequest.setTitle(title); |         cardRequest.setTitle(title); | ||||||
|  | @ -33,9 +34,11 @@ public class CardPost { | ||||||
|                 + configuration.getWekanList() + "cards"; |                 + configuration.getWekanList() + "cards"; | ||||||
| 
 | 
 | ||||||
|         RestTemplate restTemplate = new RestTemplate(); |         RestTemplate restTemplate = new RestTemplate(); | ||||||
|         LOG.debug("Sending card: {}", cardRequest); |         log.debug("Sending card: {}", cardRequest); | ||||||
|         CardResponse cardResponse = restTemplate.postForObject(cardUrl, cardRequest, CardResponse.class); |         CardResponse cardResponse = restTemplate.postForObject(cardUrl, cardRequest, CardResponse.class); | ||||||
| 
 | 
 | ||||||
|  |         log.info("Card {} successfully sent - cardId: {}", title, cardResponse.getId()); | ||||||
|  |         return cardResponse; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1,11 +1,14 @@ | ||||||
| package cz.brmlab.wm.wekan.rest; | package cz.brmlab.wm.wekan.rest; | ||||||
| 
 | 
 | ||||||
|  | import cz.brmlab.wm.utils.LogMarker.LogMarker; | ||||||
| import cz.brmlab.wm.wekan.WekanConfiguration; | import cz.brmlab.wm.wekan.WekanConfiguration; | ||||||
| import cz.brmlab.wm.wekan.pojo.login.LoginRequest; | import cz.brmlab.wm.wekan.pojo.login.LoginRequest; | ||||||
| import cz.brmlab.wm.wekan.pojo.login.LoginToken; | import cz.brmlab.wm.wekan.pojo.login.LoginToken; | ||||||
| import lombok.Getter; | import lombok.Getter; | ||||||
|  | import lombok.extern.slf4j.Slf4j; | ||||||
| import org.springframework.web.client.RestTemplate; | import org.springframework.web.client.RestTemplate; | ||||||
| 
 | 
 | ||||||
|  | @Slf4j | ||||||
| public class LoginPost { | public class LoginPost { | ||||||
| 
 | 
 | ||||||
|     private final WekanConfiguration configuration; |     private final WekanConfiguration configuration; | ||||||
|  | @ -19,16 +22,19 @@ public class LoginPost { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|     public void login() { |     public void login() { | ||||||
|  |         log.trace("login() - start."); | ||||||
| 
 | 
 | ||||||
|         String loginUrl = configuration.getWekanUrl() + "/users/login"; |         String loginUrl = configuration.getWekanUrl() + "/users/login"; | ||||||
|  |         log.debug("Wekan login endpoint: {}", loginUrl); | ||||||
| 
 | 
 | ||||||
|         LoginRequest loginRequest = new LoginRequest(); |         LoginRequest loginRequest = new LoginRequest(); | ||||||
|         loginRequest.setUsername(configuration.getWekanUser()); |         loginRequest.setUsername(configuration.getWekanUser()); | ||||||
|         loginRequest.setPassword(configuration.getWekanPassword()); |         loginRequest.setPassword(configuration.getWekanPassword()); | ||||||
| 
 | 
 | ||||||
|  |         log.info("Sending login request..."); | ||||||
|         RestTemplate restTemplate = new RestTemplate(); |         RestTemplate restTemplate = new RestTemplate(); | ||||||
|         token = restTemplate.postForObject(loginUrl, loginRequest, LoginToken.class); |         token = restTemplate.postForObject(loginUrl, loginRequest, LoginToken.class); | ||||||
| 
 |         log.info("Login successful, token obtained."); | ||||||
|         System.out.println(token); |         log.debug(LogMarker.SECRET.getMarker(), "Token: {}", token.toString()); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Malanius
						Malanius