Commit dcae1cbb5d1f42ff505d5d27790d6c33be0c3e15
1 parent
ffece3dd
Exists in
master
utillog add some func
Showing
2 changed files
with
48 additions
and
23 deletions
Show diff stats
build.gradle
| @@ -62,7 +62,7 @@ uploadArchives { | @@ -62,7 +62,7 @@ uploadArchives { | ||
| 62 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) | 62 | authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD) |
| 63 | } | 63 | } |
| 64 | pom.project { | 64 | pom.project { |
| 65 | - version '1.1.118' | 65 | + version '1.1.120' |
| 66 | artifactId ARTIFACT_Id | 66 | artifactId ARTIFACT_Id |
| 67 | groupId GROUP_ID | 67 | groupId GROUP_ID |
| 68 | packaging TYPE | 68 | packaging TYPE |
src/main/java/com/taover/util/UtilLog.java
| @@ -18,16 +18,7 @@ public class UtilLog { | @@ -18,16 +18,7 @@ public class UtilLog { | ||
| 18 | * @param infoClass | 18 | * @param infoClass |
| 19 | */ | 19 | */ |
| 20 | public static void infoForMessage(String message, Class infoClass){ | 20 | public static void infoForMessage(String message, Class infoClass){ |
| 21 | - String className = infoClass.getName(); | ||
| 22 | - Logger log = logByClassName.get(infoClass.getName()); | ||
| 23 | - if(log == null){ | ||
| 24 | - log = LoggerFactory.getLogger(infoClass); | ||
| 25 | - if(log == null){ | ||
| 26 | - return; | ||
| 27 | - } | ||
| 28 | - logByClassName.put(className, log); | ||
| 29 | - } | ||
| 30 | - log.info(message); | 21 | + info(message, null, infoClass); |
| 31 | } | 22 | } |
| 32 | 23 | ||
| 33 | /** | 24 | /** |
| @@ -38,7 +29,7 @@ public class UtilLog { | @@ -38,7 +29,7 @@ public class UtilLog { | ||
| 38 | public static String infoForException(Exception e, Class infoClass){ | 29 | public static String infoForException(Exception e, Class infoClass){ |
| 39 | StringWriter sw = new StringWriter(); | 30 | StringWriter sw = new StringWriter(); |
| 40 | e.printStackTrace(new PrintWriter(sw)); | 31 | e.printStackTrace(new PrintWriter(sw)); |
| 41 | - UtilLog.infoForMessage(sw.toString(), infoClass); | 32 | + info(sw.toString(), null, infoClass); |
| 42 | return sw.toString(); | 33 | return sw.toString(); |
| 43 | } | 34 | } |
| 44 | 35 | ||
| @@ -48,16 +39,7 @@ public class UtilLog { | @@ -48,16 +39,7 @@ public class UtilLog { | ||
| 48 | * @param infoClass | 39 | * @param infoClass |
| 49 | */ | 40 | */ |
| 50 | public static void errorForMessage(String message, Class infoClass){ | 41 | public static void errorForMessage(String message, Class infoClass){ |
| 51 | - String className = infoClass.getName(); | ||
| 52 | - Logger log = logByClassName.get(infoClass.getName()); | ||
| 53 | - if(log == null){ | ||
| 54 | - log = LoggerFactory.getLogger(infoClass); | ||
| 55 | - if(log == null){ | ||
| 56 | - return; | ||
| 57 | - } | ||
| 58 | - logByClassName.put(className, log); | ||
| 59 | - } | ||
| 60 | - log.error(message); | 42 | + error(message, null, infoClass); |
| 61 | } | 43 | } |
| 62 | 44 | ||
| 63 | /** | 45 | /** |
| @@ -68,7 +50,50 @@ public class UtilLog { | @@ -68,7 +50,50 @@ public class UtilLog { | ||
| 68 | public static String errorForException(Exception e, Class infoClass){ | 50 | public static String errorForException(Exception e, Class infoClass){ |
| 69 | StringWriter sw = new StringWriter(); | 51 | StringWriter sw = new StringWriter(); |
| 70 | e.printStackTrace(new PrintWriter(sw)); | 52 | e.printStackTrace(new PrintWriter(sw)); |
| 71 | - UtilLog.errorForMessage(sw.toString(), infoClass); | 53 | + error(null, e, infoClass); |
| 72 | return sw.toString(); | 54 | return sw.toString(); |
| 73 | } | 55 | } |
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * 综合信息 | ||
| 59 | + * @param message | ||
| 60 | + * @param e | ||
| 61 | + * @param infoClass | ||
| 62 | + */ | ||
| 63 | + public static void error(String message, Exception e, Class infoClass){ | ||
| 64 | + //获取logger | ||
| 65 | + Logger log = LoggerFactory.getLogger(infoClass); | ||
| 66 | + | ||
| 67 | + //Exception 信息 | ||
| 68 | + StringWriter sw = new StringWriter(); | ||
| 69 | + if(e != null) { | ||
| 70 | + e.printStackTrace(new PrintWriter(sw)); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + log.error("<h3>MESSAGE</h3>"+message+"<br/><h3>EXCEPTION</h3>"+sw.toString()); | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + /** | ||
| 77 | + * 综合信息 | ||
| 78 | + * @param message | ||
| 79 | + * @param e | ||
| 80 | + * @param infoClass | ||
| 81 | + */ | ||
| 82 | + public static void info(String message, Exception e, Class infoClass){ | ||
| 83 | + //获取logger | ||
| 84 | + Logger log = LoggerFactory.getLogger(infoClass); | ||
| 85 | + | ||
| 86 | + //Message 信息 | ||
| 87 | + if(message == null) { | ||
| 88 | + message = ""; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + //Exception 信息 | ||
| 92 | + StringWriter sw = new StringWriter(); | ||
| 93 | + if(e != null) { | ||
| 94 | + e.printStackTrace(new PrintWriter(sw)); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + log.info("<h3>MESSAGE</h3>"+message+"<h3>EXCEPTION</h3>"+sw.toString()); | ||
| 98 | + } | ||
| 74 | } | 99 | } |