TODO unchecked. Code removed. Constant LOG_PREFIX added.
This commit is contained in:
		| @@ -5,8 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; | |||||||
| import com.release11.klaus.model.Event; | import com.release11.klaus.model.Event; | ||||||
| import com.release11.klaus.utilis.BusinessKey; | import com.release11.klaus.utilis.BusinessKey; | ||||||
| import lombok.AllArgsConstructor; | import lombok.AllArgsConstructor; | ||||||
| import org.codehaus.jettison.json.JSONException; |  | ||||||
| import org.codehaus.jettison.json.JSONObject; |  | ||||||
| import org.springframework.stereotype.Repository; | import org.springframework.stereotype.Repository; | ||||||
| import redis.clients.jedis.Jedis; | import redis.clients.jedis.Jedis; | ||||||
| import redis.clients.jedis.JedisPool; | import redis.clients.jedis.JedisPool; | ||||||
| @@ -20,6 +18,8 @@ import java.util.List; | |||||||
| import java.util.Map; | import java.util.Map; | ||||||
| import java.util.stream.Collectors; | import java.util.stream.Collectors; | ||||||
|  |  | ||||||
|  | import static com.release11.klaus.utilis.RedisAppender.LOG_PREFIX; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Builds Event list based on logs created via {@link com.release11.klaus.utilis.TrackingClient} and {@link com.release11.klaus.utilis.RedisAppender} |  * Builds Event list based on logs created via {@link com.release11.klaus.utilis.TrackingClient} and {@link com.release11.klaus.utilis.RedisAppender} | ||||||
|  * @author Rafał Żukowicz |  * @author Rafał Żukowicz | ||||||
| @@ -27,8 +27,6 @@ import java.util.stream.Collectors; | |||||||
| @Repository | @Repository | ||||||
| @AllArgsConstructor | @AllArgsConstructor | ||||||
| public class EventRepositoryImpl implements EventRepository { | public class EventRepositoryImpl implements EventRepository { | ||||||
|     //TODO: create one constant for both Impl and well as RedisAppender |  | ||||||
|     private final String LOG_PREFIX = "logstash_"; |  | ||||||
|     private final JedisPool jedisPool; |     private final JedisPool jedisPool; | ||||||
|     private final ObjectMapper objectMapper; |     private final ObjectMapper objectMapper; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -18,17 +18,13 @@ import redis.clients.jedis.Protocol; | |||||||
| /** | /** | ||||||
|  * Class is used to insert logs directly to Redis. {@link com.release11.klaus.repository.EventRepositoryImpl} is using those logs. |  * Class is used to insert logs directly to Redis. {@link com.release11.klaus.repository.EventRepositoryImpl} is using those logs. | ||||||
|  * @author Rafał Żukowicz |  * @author Rafał Żukowicz | ||||||
|  |  * @author Gabriel Modzelewski | ||||||
|  */ |  */ | ||||||
| public class RedisAppender extends UnsynchronizedAppenderBase<ILoggingEvent> { | public class RedisAppender extends UnsynchronizedAppenderBase<ILoggingEvent> { | ||||||
|  |  | ||||||
|     JedisPool pool; |     JedisPool pool; | ||||||
|  |  | ||||||
|     // keep this for config compatibility for now |  | ||||||
|     JSONEventLayout jsonlayout; |     JSONEventLayout jsonlayout; | ||||||
|  |  | ||||||
|     Layout<ILoggingEvent> layout; |     Layout<ILoggingEvent> layout; | ||||||
|  |  | ||||||
|     // logger configurable options |  | ||||||
|     String host = "localhost"; |     String host = "localhost"; | ||||||
|     int port = Protocol.DEFAULT_PORT; |     int port = Protocol.DEFAULT_PORT; | ||||||
|     String key = null; |     String key = null; | ||||||
| @@ -36,6 +32,9 @@ public class RedisAppender extends UnsynchronizedAppenderBase<ILoggingEvent> { | |||||||
|     String password = null; |     String password = null; | ||||||
|     int database = Protocol.DEFAULT_DATABASE; |     int database = Protocol.DEFAULT_DATABASE; | ||||||
|  |  | ||||||
|  |     public static final String LOG_PREFIX = "logstash_"; | ||||||
|  |  | ||||||
|  |  | ||||||
|     public RedisAppender() { |     public RedisAppender() { | ||||||
|         jsonlayout = new JSONEventLayout(); |         jsonlayout = new JSONEventLayout(); | ||||||
|     } |     } | ||||||
| @@ -49,7 +48,7 @@ public class RedisAppender extends UnsynchronizedAppenderBase<ILoggingEvent> { | |||||||
|         Jedis client = pool.getResource(); |         Jedis client = pool.getResource(); | ||||||
|         try { |         try { | ||||||
|             String json = layout == null ? jsonlayout.doLayout(event) : layout.doLayout(event); |             String json = layout == null ? jsonlayout.doLayout(event) : layout.doLayout(event); | ||||||
|             key = "logstash_" + LocalDate.now(); |             key = LOG_PREFIX + LocalDate.now(); | ||||||
|             client.rpush(key, json); |             client.rpush(key, json); | ||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
|   | |||||||
										
											Binary file not shown.
										
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user