소스 검색

代码优化

MrBird 5 년 전
부모
커밋
e985341832

+ 27 - 23
febs-common/febs-common-redis-starter/src/main/java/cc/mrbird/febs/common/redis/service/RedisService.java

@@ -1,5 +1,7 @@
 package cc.mrbird.febs.common.redis.service;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
 
@@ -17,6 +19,8 @@ import java.util.concurrent.TimeUnit;
 @SuppressWarnings("all")
 public class RedisService {
 
+    private Logger log = LoggerFactory.getLogger(this.getClass());
+
     @Autowired
     private RedisTemplate<String, Object> redisTemplate;
 
@@ -34,7 +38,7 @@ public class RedisService {
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -59,7 +63,7 @@ public class RedisService {
         try {
             return redisTemplate.hasKey(key);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -101,7 +105,7 @@ public class RedisService {
             redisTemplate.opsForValue().set(key, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -123,7 +127,7 @@ public class RedisService {
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -189,7 +193,7 @@ public class RedisService {
             redisTemplate.opsForHash().putAll(key, map);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -210,7 +214,7 @@ public class RedisService {
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -228,7 +232,7 @@ public class RedisService {
             redisTemplate.opsForHash().put(key, item, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -250,7 +254,7 @@ public class RedisService {
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -310,7 +314,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForSet().members(key);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return null;
         }
     }
@@ -326,7 +330,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForSet().isMember(key, value);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -342,7 +346,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForSet().add(key, values);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return 0L;
         }
     }
@@ -363,7 +367,7 @@ public class RedisService {
             }
             return count;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return 0L;
         }
     }
@@ -378,7 +382,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForSet().size(key);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return 0L;
         }
     }
@@ -394,7 +398,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForSet().remove(key, values);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return 0L;
         }
     }
@@ -411,7 +415,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForList().range(key, start, end);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return null;
         }
     }
@@ -426,7 +430,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForList().size(key);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return 0L;
         }
     }
@@ -443,7 +447,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForList().index(key, index);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return null;
         }
     }
@@ -460,7 +464,7 @@ public class RedisService {
             redisTemplate.opsForList().rightPush(key, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -481,7 +485,7 @@ public class RedisService {
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -498,7 +502,7 @@ public class RedisService {
             redisTemplate.opsForList().rightPushAll(key, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -519,7 +523,7 @@ public class RedisService {
             }
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -537,7 +541,7 @@ public class RedisService {
             redisTemplate.opsForList().set(key, index, value);
             return true;
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return false;
         }
     }
@@ -554,7 +558,7 @@ public class RedisService {
         try {
             return redisTemplate.opsForList().remove(key, count, value);
         } catch (Exception e) {
-            e.printStackTrace();
+            log.error(e.getMessage(), e);
             return 0L;
         }
     }

+ 1 - 1
febs-gateway/src/main/java/cc/mrbird/febs/gateway/enhance/utils/AddressUtil.java

@@ -48,7 +48,7 @@ public class AddressUtil {
                 try {
                     searcher.close();
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    log.error("ip2region searcher close error", e);
                 }
             }
         }

+ 1 - 1
febs-server/febs-server-system/src/main/java/cc/mrbird/febs/server/system/utils/AddressUtil.java

@@ -48,7 +48,7 @@ public class AddressUtil {
                 try {
                     searcher.close();
                 } catch (IOException e) {
-                    e.printStackTrace();
+                    log.error("ip2region searcher close error", e);
                 }
             }
         }