001/*******************************************************************************
002The MIT License (MIT)
003
004Copyright (c) 2024 KILLCODING.COM
005
006Permission is hereby granted, free of charge, to any person obtaining a copy
007of this software and associated documentation files (the "Software"), to deal
008in the Software without restriction, including without limitation the rights
009to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
010copies of the Software, and to permit persons to whom the Software is
011furnished to do so, subject to the following conditions:
012
013The above copyright notice and this permission notice shall be included in
014all copies or substantial portions of the Software.
015
016THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
017IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
018FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
019AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
020LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
021OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
022THE SOFTWARE.
023*****************************************************************************/
024package com.killcoding.log;
025
026import java.text.SimpleDateFormat;
027import java.util.Date;
028import java.util.Map;
029import java.util.HashMap;
030import java.io.StringWriter;
031import java.io.PrintWriter;
032import java.util.List;
033import java.util.Arrays;
034import com.killcoding.tool.CommonTools;
035import com.killcoding.tool.ConfigProperties;
036import com.killcoding.tool.CodeEscape;
037import com.killcoding.log.Logger;
038
039/**
040 * This is logger class
041 * Sample,
042 * Logger log = LoggerFactory.getLogger(clazz);
043 * */
044public final class Logger {
045
046        private final static String DEFAULT_MESSAGE_FORMAT = ":level :log_time_format [:log_thread_name-:log_thread_id] :log_class_name.:log_method_name(:log_file_name::log_line_number) **:message** \r\n:stack_trace";
047
048        public final static List<String> LEVEL_LIST = Arrays.asList(new String[] { "DEBUG", "INFO", "WARN", "ERROR" });
049        public final static Integer LEVEL_DEBUG = 0;
050        public final static Integer LEVEL_INFO = 1;
051        public final static Integer LEVEL_WARN = 2;
052        public final static Integer LEVEL_ERROR = 3;
053        public final static Integer LEVEL_MARK = 4;
054
055        private static Integer LEVEL = LEVEL_DEBUG;
056
057        private String clazzName;
058
059        private String hostname;
060
061        private static String classNameEnableRegex = null;
062        private static String classNameDisableRegex = null;
063
064        public Logger(Class clazz) {
065                super();
066                this.clazzName = clazz.getName();
067                hostname = CommonTools.getHostname();
068        }
069
070        public Logger(String clazzName) {
071                super();
072                this.clazzName = clazzName;
073                hostname = CommonTools.getHostname();
074        }
075
076        protected static void setClassNameEnableRegex(String _classNameEnableRegex) {
077                classNameEnableRegex = _classNameEnableRegex;
078        }
079
080        protected static void setClassNameDisableRegex(String _classNameDisableRegex) {
081                classNameDisableRegex = _classNameDisableRegex;
082        }
083
084        protected static boolean checkLevel(String _level) {
085                if (_level == null)
086                        return false;
087
088                return LEVEL_LIST.contains(_level);
089        }
090
091        public static void setLevel(String _level) {
092                if (checkLevel(_level)) {
093                        setLevel(LEVEL_LIST.indexOf(_level.toUpperCase()));
094                }
095        }
096
097        public static void setLevel(Integer level) {
098                LEVEL = (level == null ? LEVEL_DEBUG : level);
099        }
100
101        public boolean isDebugEnabled() {
102                return LEVEL == LEVEL_DEBUG;
103        }
104
105        public boolean isInfoEnabled() {
106                return LEVEL == LEVEL_INFO;
107        }
108
109        public boolean isWarnEnabled() {
110                return LEVEL == LEVEL_WARN;
111        }
112
113        public boolean isErrorEnabled() {
114                return LEVEL == LEVEL_ERROR;
115        }
116        
117        public void debug(Object obj) {
118            try{
119                if (LEVEL <= LEVEL_DEBUG) {
120                        Map<String, Object> map = new HashMap<String, Object>();
121                        map.put("message", obj + "");
122                        log(LEVEL_DEBUG, map);
123                }
124            }catch(Exception e){
125                e.printStackTrace();
126            }
127        }       
128
129        public void debug(String message) {
130            try{
131                if (LEVEL <= LEVEL_DEBUG) {
132                        Map<String, Object> map = new HashMap<String, Object>();
133                        map.put("message", message);
134                        log(LEVEL_DEBUG, map);
135                }
136            }catch(Exception e){
137                e.printStackTrace();
138            }
139        }
140
141        public void debug(String message, Exception exception) {
142            try{
143                if (LEVEL <= LEVEL_DEBUG) {
144                        Map<String, Object> map = new HashMap<String, Object>();
145                        map.put("message", message);
146                        map.put("exception", exception);
147                        log(LEVEL_DEBUG, map);
148                }
149            }catch(Exception e){
150                e.printStackTrace();
151            }
152        }
153
154        public void debug(Exception exception) {
155            try{
156                if (LEVEL <= LEVEL_DEBUG) {
157                        Map<String, Object> map = new HashMap<String, Object>();
158                        map.put("message", exception.getMessage());
159                        map.put("exception", exception);
160                        log(LEVEL_DEBUG, map);
161                }
162            }catch(Exception e){
163                e.printStackTrace();
164            }
165        }
166
167        public void debug(String message, Object... params) {
168            try{
169                if (LEVEL <= LEVEL_DEBUG) {
170                        String msg = (message + "").replaceAll("\\{\\}", "%s");
171                        String _message = String.format(msg, converParams(params));
172                        Map<String, Object> map = new HashMap<String, Object>();
173                        map.put("message", _message);
174                        log(LEVEL_DEBUG, map);
175                }
176            }catch(Exception e){
177                e.printStackTrace();
178            }
179        }
180
181        public void debug(String message, Object obj) {
182            try{
183                if (LEVEL <= LEVEL_DEBUG) {
184                        String msg = (message + "").replaceAll("\\{\\}", "%s");
185                        Object[] params = new Object[]{obj + ""};
186                        String _message = String.format(msg, converParams(params));
187                        Map<String, Object> map = new HashMap<String, Object>();
188                        map.put("message", _message);
189                        log(LEVEL_DEBUG, map);
190                }
191            }catch(Exception e){
192                e.printStackTrace();
193            }
194        }
195        
196        public void info(String message) {
197            try{
198                if (LEVEL <= LEVEL_INFO) {
199                        Map<String, Object> map = new HashMap<String, Object>();
200                        map.put("message", message);
201                        log(LEVEL_INFO, map);
202                }
203            }catch(Exception e){
204                e.printStackTrace();
205            }
206        }
207        
208        public void info(Object obj) {
209            try{
210                if (LEVEL <= LEVEL_INFO) {
211                        Map<String, Object> map = new HashMap<String, Object>();
212                        map.put("message", obj + "");
213                        log(LEVEL_INFO, map);
214                }
215            }catch(Exception e){
216                e.printStackTrace();
217            }
218        }       
219
220        public void info(String message, Exception exception) {
221            try{
222                if (LEVEL <= LEVEL_INFO) {
223                        Map<String, Object> map = new HashMap<String, Object>();
224                        map.put("message", message);
225                        map.put("exception", exception);
226                        log(LEVEL_INFO, map);
227                }
228            }catch(Exception e){
229                e.printStackTrace();
230            }
231        }
232
233        public void info(Exception exception) {
234            try{
235                if (LEVEL <= LEVEL_INFO) {
236                        Map<String, Object> map = new HashMap<String, Object>();
237                        map.put("message", exception.getMessage());
238                        map.put("exception", exception);
239                        log(LEVEL_INFO, map);
240                }
241            }catch(Exception e){
242                e.printStackTrace();
243            }
244        }
245
246        public void info(String message, Object... params) {
247            try{
248                if (LEVEL <= LEVEL_INFO) {
249                        String msg = (message + "").replaceAll("\\{\\}", "%s");
250                        String _message = String.format(msg, converParams(params));
251                        Map<String, Object> map = new HashMap<String, Object>();
252                        map.put("message", _message);
253                        log(LEVEL_INFO, map);
254                }
255            }catch(Exception e){
256                e.printStackTrace();
257            }
258        }
259        
260        public void info(String message, Object obj) {
261            try{
262                if (LEVEL <= LEVEL_INFO) {
263                        String msg = (message + "").replaceAll("\\{\\}", "%s");
264                        Object[] params = new Object[]{obj + ""};
265                        String _message = String.format(msg, converParams(params));
266                        Map<String, Object> map = new HashMap<String, Object>();
267                        map.put("message", _message);
268                        log(LEVEL_INFO, map);
269                }
270            }catch(Exception e){
271                e.printStackTrace();
272            }
273        }       
274
275        public void warn(String message) {
276            try{
277                if (LEVEL <= LEVEL_WARN) {
278                        Map<String, Object> map = new HashMap<String, Object>();
279                        map.put("message", message);
280                        log(LEVEL_WARN, map);
281                }
282            }catch(Exception e){
283                e.printStackTrace();
284            }
285        }
286
287        public void warn(Object obj) {
288            try{
289                if (LEVEL <= LEVEL_WARN) {
290                        Map<String, Object> map = new HashMap<String, Object>();
291                        map.put("message", obj + "");
292                        log(LEVEL_WARN, map);
293                }
294            }catch(Exception e){
295                e.printStackTrace();
296            }
297        }
298        
299        public void warn(String message, Exception exception) {
300            try{
301                if (LEVEL <= LEVEL_WARN) {
302                        Map<String, Object> map = new HashMap<String, Object>();
303                        map.put("message", message);
304                        map.put("exception", exception);
305                        log(LEVEL_WARN, map);
306                }
307            }catch(Exception e){
308                e.printStackTrace();
309            }
310        }
311
312        public void warn(Exception exception) {
313            try{
314                if (LEVEL <= LEVEL_WARN) {
315                        Map<String, Object> map = new HashMap<String, Object>();
316                        map.put("message", exception.getMessage());
317                        map.put("exception", exception);
318                        log(LEVEL_WARN, map);
319                }
320            }catch(Exception e){
321                e.printStackTrace();
322            }
323        }
324
325        public void warn(String message, Object... params) {
326            try{
327                if (LEVEL <= LEVEL_WARN) {
328                        String msg = (message + "").replaceAll("\\{\\}", "%s");
329                        String _message = String.format(msg, converParams(params));
330                        Map<String, Object> map = new HashMap<String, Object>();
331                        map.put("message", _message);
332                        log(LEVEL_WARN, map);
333                }
334            }catch(Exception e){
335                e.printStackTrace();
336            }
337        }
338        
339        public void warn(String message, Object obj) {
340            try{
341                if (LEVEL <= LEVEL_WARN) {
342                        String msg = (message + "").replaceAll("\\{\\}", "%s");
343                        Object[] params = new Object[]{obj + ""};
344                        String _message = String.format(msg, converParams(params));
345                        Map<String, Object> map = new HashMap<String, Object>();
346                        map.put("message", _message);
347                        log(LEVEL_WARN, map);
348                }
349            }catch(Exception e){
350                e.printStackTrace();
351            }
352        }       
353
354        public void error(String message) {
355            try{
356                if (LEVEL <= LEVEL_ERROR) {
357                        Map<String, Object> map = new HashMap<String, Object>();
358                        map.put("message", message);
359                        log(LEVEL_ERROR, map);
360                }
361            }catch(Exception e){
362                e.printStackTrace();
363            }
364        }
365        
366        public void error(Object obj) {
367            try{
368                if (LEVEL <= LEVEL_ERROR) {
369                        Map<String, Object> map = new HashMap<String, Object>();
370                        map.put("message", obj +"");
371                        log(LEVEL_ERROR, map);
372                }
373            }catch(Exception e){
374                e.printStackTrace();
375            }
376        }       
377
378        public void error(String message, Exception exception) {
379            try{
380                if (LEVEL <= LEVEL_ERROR) {
381                        Map<String, Object> map = new HashMap<String, Object>();
382                        map.put("message", message);
383                        map.put("exception", exception);
384                        log(LEVEL_ERROR, map);
385                }
386            }catch(Exception e){
387                e.printStackTrace();
388            }
389        }
390
391        public void error(Exception exception) {
392            try{
393                if (LEVEL <= LEVEL_ERROR) {
394                        Map<String, Object> map = new HashMap<String, Object>();
395                        map.put("message", exception.getMessage());
396                        map.put("exception", exception);
397                        log(LEVEL_ERROR, map);
398                }
399            }catch(Exception e){
400                e.printStackTrace();
401            }
402        }
403
404        public void error(String message, Object... params) {
405            try{
406                if (LEVEL <= LEVEL_ERROR) {
407                        String msg = (message + "").replaceAll("\\{\\}", "%s");
408                        String _message = String.format(msg, converParams(params));
409                        Map<String, Object> map = new HashMap<String, Object>();
410                        map.put("message", _message);
411                        log(LEVEL_ERROR, map);
412                }
413            }catch(Exception e){
414                e.printStackTrace();
415            }
416        }
417        
418        public void error(String message, Object obj) {
419            try{
420                if (LEVEL <= LEVEL_ERROR) {
421                        String msg = (message + "").replaceAll("\\{\\}", "%s");
422                    Object[] params = new Object[]{obj + ""};
423                        String _message = String.format(msg, converParams(params));
424                        Map<String, Object> map = new HashMap<String, Object>();
425                        map.put("message", _message);
426                        log(LEVEL_ERROR, map);
427                }
428            }catch(Exception e){
429                e.printStackTrace();
430            }
431        }       
432
433        public void mark(String message) {
434            try{
435                Map<String, Object> map = new HashMap<String, Object>();
436                map.put("message", message);
437                log(LEVEL_MARK, map);
438            }catch(Exception e){
439                e.printStackTrace();
440            }
441        }
442        
443        public void mark(Object obj) {
444            try{
445                Map<String, Object> map = new HashMap<String, Object>();
446                map.put("message", obj + "");
447                log(LEVEL_MARK, map);
448            }catch(Exception e){
449                e.printStackTrace();
450            }
451        }       
452
453        public void mark(String message, Object... params) {
454            try{
455                String msg = (message + "").replaceAll("\\{\\}", "%s");
456                String _message = String.format(msg, converParams(params));
457                Map<String, Object> map = new HashMap<String, Object>();
458                map.put("message", _message);
459                log(LEVEL_MARK, map);
460            }catch(Exception e){
461                e.printStackTrace();
462            }
463        }
464        
465        public void mark(String message, Object obj) {
466            try{
467                String msg = (message + "").replaceAll("\\{\\}", "%s");
468                Object[] params = new Object[]{obj + ""};
469                String _message = String.format(msg, converParams(params));
470                Map<String, Object> map = new HashMap<String, Object>();
471                map.put("message", _message);
472                log(LEVEL_MARK, map);
473            }catch(Exception e){
474                e.printStackTrace();
475            }
476        }       
477
478        public static void systemError(String clazz, String message) {
479            try{
480                if (LEVEL <= LEVEL_ERROR) {
481                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
482                                Map<String, Object> map = new HashMap<String, Object>();
483                                map.put("message", message);
484                                log("ERROR", clazz, map);
485                    }
486                        if(LoggerFactory.isLoadedConfig()){
487                            LoggerFactory.getLogger(clazz).error(message);
488                        }                       
489                }
490            }catch(Exception e){
491                e.printStackTrace();
492            }
493        }
494        
495        public static void systemError(String clazz, Object obj) {
496            try{
497                if (LEVEL <= LEVEL_ERROR) {
498                    String message = obj + "";
499                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
500                                Map<String, Object> map = new HashMap<String, Object>();
501                                map.put("message", message);
502                                log("ERROR", clazz, map);
503                    }
504                        if(LoggerFactory.isLoadedConfig()){
505                            LoggerFactory.getLogger(clazz).error(message);
506                        }                       
507                }
508            }catch(Exception e){
509                e.printStackTrace();
510            }
511        }       
512        
513        public static void systemError(Class clazz, String message) {
514                if (LEVEL <= LEVEL_ERROR) {
515                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
516                        Map<String, Object> map = new HashMap<String, Object>();
517                        map.put("message", message);
518                        log("ERROR", clazz, map);
519                    }
520                if(LoggerFactory.isLoadedConfig()){
521                    LoggerFactory.getLogger(clazz).error(message);
522                }                       
523                }
524        }
525        
526        public static void systemError(Class clazz, Object obj) {
527                if (LEVEL <= LEVEL_ERROR) {
528                    String message = obj + "";
529                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
530                        Map<String, Object> map = new HashMap<String, Object>();
531                        map.put("message", message);
532                        log("ERROR", clazz, map);
533                    }
534                if(LoggerFactory.isLoadedConfig()){
535                    LoggerFactory.getLogger(clazz).error(message);
536                }                       
537                }
538        }
539
540        public static void systemMark(String clazz, String message, Exception exception) {
541            try{
542            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
543                        Map<String, Object> map = new HashMap<String, Object>();
544                        map.put("message", message);
545                        map.put("exception", exception);
546                        log("MARK", clazz, map);
547            }
548                if(LoggerFactory.isLoadedConfig()){
549                    LoggerFactory.getLogger(clazz).mark(message,exception);
550                }
551            }catch(Exception e){
552                e.printStackTrace();
553            }
554        }
555        
556        public static void systemMark(Class clazz, String message, Exception exception) {
557            try{
558            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
559                        Map<String, Object> map = new HashMap<String, Object>();
560                        map.put("message", message);
561                        map.put("exception", exception);
562                        log("MARK", clazz, map);
563            }
564                if(LoggerFactory.isLoadedConfig()){
565                    LoggerFactory.getLogger(clazz).mark(message,exception);
566                }
567            }catch(Exception e){
568                e.printStackTrace();
569            }
570        }
571
572        public static void systemMark(String clazz, String message, Object... params) {
573            try{
574            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
575                        String msg = (message + "").replaceAll("\\{\\}", "%s");
576                        String _message = String.format(msg, converParams(params));
577                        Map<String, Object> map = new HashMap<String, Object>();
578                        map.put("message", _message);
579                        log("MARK", clazz, map);
580            }
581                if(LoggerFactory.isLoadedConfig()){
582                    LoggerFactory.getLogger(clazz).mark(message,params);
583                }
584            }catch(Exception e){
585                e.printStackTrace();
586            }
587        }
588        
589        public static void systemMark(String clazz, String message, Object obj) {
590            try{
591                Object[] params = new Object[]{obj + ""};
592            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
593                        String msg = (message + "").replaceAll("\\{\\}", "%s");
594                        String _message = String.format(msg, converParams(params));
595                        Map<String, Object> map = new HashMap<String, Object>();
596                        map.put("message", _message);
597                        log("MARK", clazz, map);
598            }
599                if(LoggerFactory.isLoadedConfig()){
600                    LoggerFactory.getLogger(clazz).mark(message,params);
601                }
602            }catch(Exception e){
603                e.printStackTrace();
604            }
605        }       
606        
607        public static void systemMark(String clazz, Object obj) {
608            try{
609                String message = obj + "";
610            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
611                        Map<String, Object> map = new HashMap<String, Object>();
612                        map.put("message", message);
613                        log("MARK", clazz, map);
614            }
615                if(LoggerFactory.isLoadedConfig()){
616                    LoggerFactory.getLogger(clazz).mark(message);
617                }
618            }catch(Exception e){
619                e.printStackTrace();
620            }
621        }       
622        
623        public static void systemMark(Class clazz, String message, Object... params) {
624            try{
625            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
626                        String msg = (message + "").replaceAll("\\{\\}", "%s");
627                        String _message = String.format(msg, converParams(params));
628                        Map<String, Object> map = new HashMap<String, Object>();
629                        map.put("message", _message);
630                        log("MARK", clazz, map);
631            }
632                if(LoggerFactory.isLoadedConfig()){
633                    LoggerFactory.getLogger(clazz).mark(message,params);
634                }
635            }catch(Exception e){
636                e.printStackTrace();
637            }
638        }
639        
640        public static void systemMark(Class clazz, String message, Object obj) {
641            try{
642                Object[] params = new Object[]{obj + ""};
643            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
644                        String msg = (message + "").replaceAll("\\{\\}", "%s");
645                        String _message = String.format(msg, converParams(params));
646                        Map<String, Object> map = new HashMap<String, Object>();
647                        map.put("message", _message);
648                        log("MARK", clazz, map);
649            }
650                if(LoggerFactory.isLoadedConfig()){
651                    LoggerFactory.getLogger(clazz).mark(message,params);
652                }
653            }catch(Exception e){
654                e.printStackTrace();
655            }
656        }       
657        
658        public static void systemMark(Class clazz, Object obj) {
659            try{
660                String message = obj + "";
661            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
662                        Map<String, Object> map = new HashMap<String, Object>();
663                        map.put("message", message);
664                        log("MARK", clazz, map);
665            }
666                if(LoggerFactory.isLoadedConfig()){
667                    LoggerFactory.getLogger(clazz).mark(message);
668                }
669            }catch(Exception e){
670                e.printStackTrace();
671            }
672        }       
673
674        public static void systemError(String clazz, String message, Exception exception) {
675            try{
676                if (LEVEL <= LEVEL_ERROR) {
677                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
678                                Map<String, Object> map = new HashMap<String, Object>();
679                                map.put("message", message);
680                                map.put("exception", exception);
681                                log("ERROR", clazz, map);
682                    }
683                        if(LoggerFactory.isLoadedConfig()){
684                            LoggerFactory.getLogger(clazz).error(message,exception);
685                        }                               
686                }
687            }catch(Exception e){
688                e.printStackTrace();
689            }
690        }
691        
692        public static void systemError(Class clazz, String message, Exception exception) {
693            try{
694                if (LEVEL <= LEVEL_ERROR) {
695                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
696                                Map<String, Object> map = new HashMap<String, Object>();
697                                map.put("message", message);
698                                map.put("exception", exception);
699                                log("ERROR", clazz, map);
700                    }
701                        if(LoggerFactory.isLoadedConfig()){
702                            LoggerFactory.getLogger(clazz).error(message,exception);
703                        }                               
704                }
705            }catch(Exception e){
706                e.printStackTrace();
707            }
708        }
709
710        public static void systemError(String clazz, Exception exception) {
711            try{
712                if (LEVEL <= LEVEL_ERROR) {
713                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
714                                Map<String, Object> map = new HashMap<String, Object>();
715                                map.put("message", exception.getMessage());
716                                map.put("exception", exception);
717                                log("ERROR", clazz, map);
718                    }
719                        if(LoggerFactory.isLoadedConfig()){
720                            LoggerFactory.getLogger(clazz).error(exception);
721                        }                       
722                }
723            }catch(Exception e){
724                e.printStackTrace();
725            }
726        }
727        
728        public static void systemError(Class clazz, Exception exception) {
729            try{
730                if (LEVEL <= LEVEL_ERROR) {
731                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
732                                Map<String, Object> map = new HashMap<String, Object>();
733                                map.put("message", exception.getMessage());
734                                map.put("exception", exception);
735                                log("ERROR", clazz, map);
736                    }
737                        if(LoggerFactory.isLoadedConfig()){
738                            LoggerFactory.getLogger(clazz).error(exception);
739                        }                       
740                }
741            }catch(Exception e){
742                e.printStackTrace();
743            }
744        }
745
746        public static void systemError(String clazz, String message, Object... params) {
747            try{
748                if (LEVEL <= LEVEL_ERROR) {
749                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
750                                String msg = (message + "").replaceAll("\\{\\}", "%s");
751                                String _message = String.format(msg, converParams(params));
752                                Map<String, Object> map = new HashMap<String, Object>();
753                                map.put("message", _message);
754                                log("ERROR", clazz, map);
755                    }
756                        if(LoggerFactory.isLoadedConfig()){
757                            LoggerFactory.getLogger(clazz).error(message,params);
758                        }                               
759                }
760            }catch(Exception e){
761                e.printStackTrace();
762            }
763        }
764        
765        public static void systemError(String clazz, String message, Object obj) {
766            try{
767                if (LEVEL <= LEVEL_ERROR) {
768                    Object[] params = new Object[]{obj + ""};
769                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
770                                String msg = (message + "").replaceAll("\\{\\}", "%s");
771                                String _message = String.format(msg, converParams(params));
772                                Map<String, Object> map = new HashMap<String, Object>();
773                                map.put("message", _message);
774                                log("ERROR", clazz, map);
775                    }
776                        if(LoggerFactory.isLoadedConfig()){
777                            LoggerFactory.getLogger(clazz).error(message,params);
778                        }                               
779                }
780            }catch(Exception e){
781                e.printStackTrace();
782            }
783        }       
784        
785        public static void systemError(Class clazz, String message, Object... params) {
786            try{
787                if (LEVEL <= LEVEL_ERROR) {
788                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
789                                String msg = (message + "").replaceAll("\\{\\}", "%s");
790                                String _message = String.format(msg, converParams(params));
791                                Map<String, Object> map = new HashMap<String, Object>();
792                                map.put("message", _message);
793                                log("ERROR", clazz, map);
794                    }
795                        if(LoggerFactory.isLoadedConfig()){
796                            LoggerFactory.getLogger(clazz).error(message,params);
797                        }                               
798                }
799            }catch(Exception e){
800                e.printStackTrace();
801            }
802        }
803        
804        public static void systemError(Class clazz, String message, Object obj) {
805            try{
806                if (LEVEL <= LEVEL_ERROR) {
807                    Object[] params = new Object[]{obj + ""};
808                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
809                                String msg = (message + "").replaceAll("\\{\\}", "%s");
810                                String _message = String.format(msg, converParams(params));
811                                Map<String, Object> map = new HashMap<String, Object>();
812                                map.put("message", _message);
813                                log("ERROR", clazz, map);
814                    }
815                        if(LoggerFactory.isLoadedConfig()){
816                            LoggerFactory.getLogger(clazz).error(message,params);
817                        }                               
818                }
819            }catch(Exception e){
820                e.printStackTrace();
821            }
822        }       
823
824        public static void systemWarn(String clazz, String message) {
825            try{
826                if (LEVEL <= LEVEL_WARN) {
827                            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
828                                Map<String, Object> map = new HashMap<String, Object>();
829                                map.put("message", message);
830                                log("WARN", clazz, map);
831                    }
832                }
833                if(LoggerFactory.isLoadedConfig()){
834                    LoggerFactory.getLogger(clazz).warn(message);
835                }       
836            }catch(Exception e){
837                e.printStackTrace();
838            }
839        }
840        
841        public static void systemWarn(Class clazz, String message) {
842            try{
843                if (LEVEL <= LEVEL_WARN) {
844                            if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
845                                Map<String, Object> map = new HashMap<String, Object>();
846                                map.put("message", message);
847                                log("WARN", clazz, map);
848                    }
849                }
850                if(LoggerFactory.isLoadedConfig()){
851                    LoggerFactory.getLogger(clazz).warn(message);
852                }               
853            }catch(Exception e){
854                e.printStackTrace();
855            }
856        }
857
858        public static void systemWarn(String clazz, String message, Exception exception) {
859            try{
860                if (LEVEL <= LEVEL_WARN) {
861                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
862                                Map<String, Object> map = new HashMap<String, Object>();
863                                map.put("message", message);
864                                map.put("exception", exception);
865                                log("WARN", clazz, map);
866                    }
867                        if(LoggerFactory.isLoadedConfig()){
868                            LoggerFactory.getLogger(clazz).warn(message,exception);
869                        }                       
870                }
871            }catch(Exception e){
872                e.printStackTrace();
873            }
874        }
875        
876        public static void systemWarn(Class clazz, String message, Exception exception) {
877            try{
878                if (LEVEL <= LEVEL_WARN) {
879                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
880                                Map<String, Object> map = new HashMap<String, Object>();
881                                map.put("message", message);
882                                map.put("exception", exception);
883                                log("WARN", clazz, map);
884                    }
885                        if(LoggerFactory.isLoadedConfig()){
886                            LoggerFactory.getLogger(clazz).warn(message,exception);
887                        }                       
888                }
889            }catch(Exception e){
890                e.printStackTrace();
891            }
892        }
893
894        public static void systemWarn(String clazz, Exception exception) {
895            try{
896                if (LEVEL <= LEVEL_WARN) {
897                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
898                                Map<String, Object> map = new HashMap<String, Object>();
899                                map.put("message", exception.getMessage());
900                                map.put("exception", exception);
901                                log("WARN", clazz, map);
902                    }
903                        if(LoggerFactory.isLoadedConfig()){
904                            LoggerFactory.getLogger(clazz).warn(exception);
905                        }                               
906                }
907            }catch(Exception e){
908                e.printStackTrace();
909            }
910        }
911        
912        public static void systemWarn(Class clazz, Exception exception) {
913            try{
914                if (LEVEL <= LEVEL_WARN) {
915                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
916                                Map<String, Object> map = new HashMap<String, Object>();
917                                map.put("message", exception.getMessage());
918                                map.put("exception", exception);
919                                log("WARN", clazz, map);
920                    }
921                        if(LoggerFactory.isLoadedConfig()){
922                            LoggerFactory.getLogger(clazz).warn(exception);
923                        }                               
924                }
925            }catch(Exception e){
926                e.printStackTrace();
927            }
928        }
929
930        public static void systemWarn(String clazz, String message, Object... params) {
931            try{
932                if (LEVEL <= LEVEL_WARN) {
933                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
934                                String msg = (message + "").replaceAll("\\{\\}", "%s");
935                                String _message = String.format(msg, converParams(params));
936                                Map<String, Object> map = new HashMap<String, Object>();
937                                map.put("message", _message);
938                                log("WARN", clazz, map);
939                    }
940                        if(LoggerFactory.isLoadedConfig()){
941                            LoggerFactory.getLogger(clazz).warn(message,params);
942                        }                               
943                }
944            }catch(Exception e){
945                e.printStackTrace();
946            }
947        }
948        
949        public static void systemWarn(String clazz, String message, Object obj) {
950            try{
951                if (LEVEL <= LEVEL_WARN) {
952                    Object[] params = new Object[]{obj + ""};
953                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
954                                String msg = (message + "").replaceAll("\\{\\}", "%s");
955                                String _message = String.format(msg, converParams(params));
956                                Map<String, Object> map = new HashMap<String, Object>();
957                                map.put("message", _message);
958                                log("WARN", clazz, map);
959                    }
960                        if(LoggerFactory.isLoadedConfig()){
961                            LoggerFactory.getLogger(clazz).warn(message,params);
962                        }                               
963                }
964            }catch(Exception e){
965                e.printStackTrace();
966            }
967        }       
968        
969        public static void systemWarn(Class clazz, String message, Object... params) {
970            try{
971                if (LEVEL <= LEVEL_WARN) {
972                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
973                                String msg = (message + "").replaceAll("\\{\\}", "%s");
974                                String _message = String.format(msg, converParams(params));
975                                Map<String, Object> map = new HashMap<String, Object>();
976                                map.put("message", _message);
977                                log("WARN", clazz, map);
978                    }
979                        if(LoggerFactory.isLoadedConfig()){
980                            LoggerFactory.getLogger(clazz).warn(message,params);
981                        }                               
982                }
983            }catch(Exception e){
984                e.printStackTrace();
985            }
986        }
987        
988        public static void systemWarn(Class clazz, String message, Object obj) {
989            try{
990                if (LEVEL <= LEVEL_WARN) {
991                    Object[] params = new Object[]{obj + ""};
992                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
993                                String msg = (message + "").replaceAll("\\{\\}", "%s");
994                                String _message = String.format(msg, converParams(params));
995                                Map<String, Object> map = new HashMap<String, Object>();
996                                map.put("message", _message);
997                                log("WARN", clazz, map);
998                    }
999                        if(LoggerFactory.isLoadedConfig()){
1000                            LoggerFactory.getLogger(clazz).warn(message,params);
1001                        }                               
1002                }
1003            }catch(Exception e){
1004                e.printStackTrace();
1005            }
1006        }       
1007
1008        public static void systemInfo(String clazz, String message) {
1009            try{
1010                if (LEVEL <= LEVEL_INFO) {
1011                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1012                                Map<String, Object> map = new HashMap<String, Object>();
1013                                map.put("message", message);
1014                                log("INFO", clazz, map);
1015                    }
1016                        if(LoggerFactory.isLoadedConfig()){
1017                            LoggerFactory.getLogger(clazz).info(message);
1018                        }                               
1019                }
1020            }catch(Exception e){
1021                e.printStackTrace();
1022            }
1023        }
1024        
1025        public static void systemInfo(Class clazz, String message) {
1026            try{
1027                if (LEVEL <= LEVEL_INFO) {
1028                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1029                                Map<String, Object> map = new HashMap<String, Object>();
1030                                map.put("message", message);
1031                                log("INFO", clazz, map);
1032                    }
1033                        if(LoggerFactory.isLoadedConfig()){
1034                            LoggerFactory.getLogger(clazz).info(message);
1035                        }                               
1036                }
1037            }catch(Exception e){
1038                e.printStackTrace();
1039            }
1040        }
1041
1042        public static void systemInfo(String clazz, String message, Exception exception) {
1043            try{
1044                if (LEVEL <= LEVEL_INFO) {
1045                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1046                                Map<String, Object> map = new HashMap<String, Object>();
1047                                map.put("message", message);
1048                                map.put("exception", exception);
1049                                log("INFO", clazz, map);
1050                    }
1051                        if(LoggerFactory.isLoadedConfig()){
1052                            LoggerFactory.getLogger(clazz).info(message,exception);
1053                        }                               
1054                }
1055            }catch(Exception e){
1056                e.printStackTrace();
1057            }
1058        }
1059        
1060        public static void systemInfo(Class clazz, String message, Exception exception) {
1061            try{
1062                if (LEVEL <= LEVEL_INFO) {
1063                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1064                                Map<String, Object> map = new HashMap<String, Object>();
1065                                map.put("message", message);
1066                                map.put("exception", exception);
1067                                log("INFO", clazz, map);
1068                    }
1069                        if(LoggerFactory.isLoadedConfig()){
1070                            LoggerFactory.getLogger(clazz).info(message,exception);
1071                        }                               
1072                }
1073            }catch(Exception e){
1074                e.printStackTrace();
1075            }
1076        }
1077
1078        public static void systemInfo(String clazz, Exception exception) {
1079            try{
1080                if (LEVEL <= LEVEL_INFO) {
1081                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1082                                Map<String, Object> map = new HashMap<String, Object>();
1083                                map.put("message", exception.getMessage());
1084                                map.put("exception", exception);
1085                                log("INFO", clazz, map);
1086                    }
1087                        if(LoggerFactory.isLoadedConfig()){
1088                            LoggerFactory.getLogger(clazz).info(exception);
1089                        }                               
1090                }
1091            }catch(Exception e){
1092                e.printStackTrace();
1093            }
1094        }
1095        
1096        public static void systemInfo(Class clazz, Exception exception) {
1097            try{
1098                if (LEVEL <= LEVEL_INFO) {
1099                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1100                                Map<String, Object> map = new HashMap<String, Object>();
1101                                map.put("message", exception.getMessage());
1102                                map.put("exception", exception);
1103                                log("INFO", clazz, map);
1104                    }
1105                        if(LoggerFactory.isLoadedConfig()){
1106                            LoggerFactory.getLogger(clazz).info(exception);
1107                        }                               
1108                }
1109            }catch(Exception e){
1110                e.printStackTrace();
1111            }
1112        }
1113
1114        public static void systemInfo(String clazz, String message, Object... params) {
1115            try{
1116                if (LEVEL <= LEVEL_INFO) {
1117                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1118                                String msg = (message + "").replaceAll("\\{\\}", "%s");
1119                                String _message = String.format(msg, converParams(params));
1120                                Map<String, Object> map = new HashMap<String, Object>();
1121                                map.put("message", _message);
1122                                log("INFO", clazz, map);
1123                    }
1124                        if(LoggerFactory.isLoadedConfig()){
1125                            LoggerFactory.getLogger(clazz).info(message,params);
1126                        }                               
1127                }
1128            }catch(Exception e){
1129                e.printStackTrace();
1130            }
1131        }
1132        
1133        public static void systemInfo(String clazz, String message, Object obj) {
1134            try{
1135                if (LEVEL <= LEVEL_INFO) {
1136                    Object[] params = new Object[]{obj + ""};
1137                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1138                                String msg = (message + "").replaceAll("\\{\\}", "%s");
1139                                String _message = String.format(msg, converParams(params));
1140                                Map<String, Object> map = new HashMap<String, Object>();
1141                                map.put("message", _message);
1142                                log("INFO", clazz, map);
1143                    }
1144                        if(LoggerFactory.isLoadedConfig()){
1145                            LoggerFactory.getLogger(clazz).info(message,params);
1146                        }                               
1147                }
1148            }catch(Exception e){
1149                e.printStackTrace();
1150            }
1151        }       
1152        
1153        public static void systemInfo(Class clazz, String message, Object... params) {
1154            try{
1155                if (LEVEL <= LEVEL_INFO) {
1156                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1157                                String msg = (message + "").replaceAll("\\{\\}", "%s");
1158                                String _message = String.format(msg, converParams(params));
1159                                Map<String, Object> map = new HashMap<String, Object>();
1160                                map.put("message", _message);
1161                                log("INFO", clazz, map);
1162                    }
1163                        if(LoggerFactory.isLoadedConfig()){
1164                            LoggerFactory.getLogger(clazz).info(message,params);
1165                        }                               
1166                }
1167            }catch(Exception e){
1168                e.printStackTrace();
1169            }
1170        }
1171        
1172        public static void systemInfo(Class clazz, String message, Object obj) {
1173            try{
1174                if (LEVEL <= LEVEL_INFO) {
1175                    Object[] params = new Object[]{obj + ""};
1176                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1177                                String msg = (message + "").replaceAll("\\{\\}", "%s");
1178                                String _message = String.format(msg, converParams(params));
1179                                Map<String, Object> map = new HashMap<String, Object>();
1180                                map.put("message", _message);
1181                                log("INFO", clazz, map);
1182                    }
1183                        if(LoggerFactory.isLoadedConfig()){
1184                            LoggerFactory.getLogger(clazz).info(message,params);
1185                        }                               
1186                }
1187            }catch(Exception e){
1188                e.printStackTrace();
1189            }
1190        }       
1191
1192        public static void systemDebug(String clazz, String message) {
1193        try{
1194                if (LEVEL <= LEVEL_DEBUG) {
1195                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1196                                Map<String, Object> map = new HashMap<String, Object>();
1197                                map.put("message", message);
1198                                log("DEBUG", clazz, map);
1199                    }
1200                        if(LoggerFactory.isLoadedConfig()){
1201                            LoggerFactory.getLogger(clazz).debug(message);
1202                        }                               
1203                }
1204        }catch(Exception e){
1205                e.printStackTrace();
1206            }
1207        }
1208        
1209        public static void systemDebug(Class clazz, String message) {
1210            try{
1211                if (LEVEL <= LEVEL_DEBUG) {
1212                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1213                                Map<String, Object> map = new HashMap<String, Object>();
1214                                map.put("message", message);
1215                                log("DEBUG", clazz, map);
1216                    }
1217                        if(LoggerFactory.isLoadedConfig()){
1218                            LoggerFactory.getLogger(clazz).debug(message);
1219                        }                               
1220                }
1221            }catch(Exception e){
1222                e.printStackTrace();
1223            }
1224        }
1225
1226        public static void systemDebug(String clazz, String message, Exception exception) {
1227            try{
1228                if (LEVEL <= LEVEL_DEBUG) {
1229                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1230                                Map<String, Object> map = new HashMap<String, Object>();
1231                                map.put("message", message);
1232                                map.put("exception", exception);
1233                                log("DEBUG", clazz, map);
1234                    }
1235                        if(LoggerFactory.isLoadedConfig()){
1236                            LoggerFactory.getLogger(clazz).debug(exception);
1237                        }                               
1238                }
1239            }catch(Exception e){
1240                e.printStackTrace();
1241            }
1242        }
1243        
1244        public static void systemDebug(Class clazz, String message, Exception exception) {
1245            try{
1246                if (LEVEL <= LEVEL_DEBUG) {
1247                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1248                                Map<String, Object> map = new HashMap<String, Object>();
1249                                map.put("message", message);
1250                                map.put("exception", exception);
1251                                log("DEBUG", clazz, map);
1252                    }
1253                        if(LoggerFactory.isLoadedConfig()){
1254                            LoggerFactory.getLogger(clazz).debug(exception);
1255                        }                               
1256                }
1257            }catch(Exception e){
1258                e.printStackTrace();
1259            }
1260        }
1261
1262        public static void systemDebug(String clazz, Exception exception) {
1263            try{
1264                if (LEVEL <= LEVEL_DEBUG) {
1265                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1266                                Map<String, Object> map = new HashMap<String, Object>();
1267                                map.put("message", exception.getMessage());
1268                                map.put("exception", exception);
1269                                log("DEBUG", clazz, map);
1270                    }
1271                        if(LoggerFactory.isLoadedConfig()){
1272                            LoggerFactory.getLogger(clazz).debug(exception);
1273                        }                               
1274                }
1275            }catch(Exception e){
1276                e.printStackTrace();
1277            }
1278        }
1279        
1280        public static void systemDebug(Class clazz, Exception exception) {
1281            try{
1282                if (LEVEL <= LEVEL_DEBUG) {
1283                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1284                                Map<String, Object> map = new HashMap<String, Object>();
1285                                map.put("message", exception.getMessage());
1286                                map.put("exception", exception);
1287                                log("DEBUG", clazz, map);
1288                    }
1289                        if(LoggerFactory.isLoadedConfig()){
1290                            LoggerFactory.getLogger(clazz).debug(exception);
1291                        }                               
1292                }
1293            }catch(Exception e){
1294                e.printStackTrace();
1295            }
1296        }
1297        
1298        public static void systemDebug(String clazz, String message, Object... params) {
1299            try{
1300                if (LEVEL <= LEVEL_DEBUG) {
1301                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1302                                String msg = (message + "").replaceAll("\\{\\}", "%s");
1303                                String _message = String.format(msg, converParams(params));
1304                                Map<String, Object> map = new HashMap<String, Object>();
1305                                map.put("message", _message);
1306                                log("DEBUG", clazz, map);
1307                    }
1308                        if(LoggerFactory.isLoadedConfig()){
1309                            LoggerFactory.getLogger(clazz).debug(message,params);
1310                        }                               
1311                }
1312            }catch(Exception e){
1313                e.printStackTrace();
1314            }
1315        }       
1316        
1317        public static void systemDebug(String clazz, String message, Object obj) {
1318            try{
1319                if (LEVEL <= LEVEL_DEBUG) {
1320                    Object[] params = new Object[]{obj + ""};
1321                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1322                                String msg = (message + "").replaceAll("\\{\\}", "%s");
1323                                String _message = String.format(msg, converParams(params));
1324                                Map<String, Object> map = new HashMap<String, Object>();
1325                                map.put("message", _message);
1326                                log("DEBUG", clazz, map);
1327                    }
1328                        if(LoggerFactory.isLoadedConfig()){
1329                            LoggerFactory.getLogger(clazz).debug(message,params);
1330                        }                               
1331                }
1332            }catch(Exception e){
1333                e.printStackTrace();
1334            }
1335        }       
1336
1337        public static void systemDebug(Class clazz, String message, Object... params) {
1338            try{
1339                if (LEVEL <= LEVEL_DEBUG) {
1340                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1341                                String msg = (message + "").replaceAll("\\{\\}", "%s");
1342                                String _message = String.format(msg, converParams(params));
1343                                Map<String, Object> map = new HashMap<String, Object>();
1344                                map.put("message", _message);
1345                                log("DEBUG", clazz, map);
1346                    }
1347                        if(LoggerFactory.isLoadedConfig()){
1348                            LoggerFactory.getLogger(clazz).debug(message,params);
1349                        }                               
1350                }
1351            }catch(Exception e){
1352                e.printStackTrace();
1353            }
1354        }
1355        
1356        public static void systemDebug(Class clazz, String message, Object obj) {
1357            try{
1358                if (LEVEL <= LEVEL_DEBUG) {
1359                    Object[] params = new Object[]{obj + ""};
1360                    if(LogRecord.isSystemOut() || !LoggerFactory.isLoadedConfig()){
1361                                String msg = (message + "").replaceAll("\\{\\}", "%s");
1362                                String _message = String.format(msg, converParams(params));
1363                                Map<String, Object> map = new HashMap<String, Object>();
1364                                map.put("message", _message);
1365                                log("DEBUG", clazz, map);
1366                    }
1367                        if(LoggerFactory.isLoadedConfig()){
1368                            LoggerFactory.getLogger(clazz).debug(message,params);
1369                        }                               
1370                }
1371            }catch(Exception e){
1372                e.printStackTrace();
1373            }
1374        }       
1375        
1376        private static void log(String level, String clazzName, Map<String, Object> map) {
1377                map.put("level", level);
1378
1379                StackTraceElement[] threadStacks = Thread.currentThread().getStackTrace();
1380                for (StackTraceElement stack : threadStacks) {
1381                        String className = stack.getClassName();
1382                        if (className.equals(clazzName)) {
1383                                String fileName = stack.getFileName();
1384                                String methodName = stack.getMethodName();
1385                                int lineNumber = stack.getLineNumber();
1386                                map.put("log_file_name", fileName);
1387                                map.put("log_class_name", className);
1388                                map.put("log_method_name", methodName);
1389                                map.put("log_line_number", lineNumber);
1390                                break;
1391                        }
1392                }
1393
1394                Thread currentThread = Thread.currentThread();
1395                long threadId = currentThread.getId();
1396                String threadName = currentThread.getName();
1397
1398                Date logTime = new Date();
1399                map.put("log_time", logTime);
1400                map.put("log_time_format", LogRecord.getLogTimeFormat().format(logTime));
1401                map.put("log_thread_id", threadId);
1402                map.put("log_thread_name", threadName);
1403
1404                Exception exception = (Exception) map.get("exception");
1405                if (exception != null) {
1406                        StringWriter sw = new StringWriter();
1407                        exception.printStackTrace(new PrintWriter(sw));
1408                        String exceptionAsString = sw.toString();
1409                        String exceptionClassName = exception.getClass().getName();
1410                        String exceptionMessage = exception.getMessage();
1411                        StackTraceElement[] stacks = exception.getStackTrace();
1412                        String fileName = null;
1413                        String className = null;
1414                        String methodName = null;
1415                        int lineNumber = 0;
1416                        for (StackTraceElement stack : stacks) {
1417                                fileName = stack.getFileName();
1418                                className = stack.getClassName();
1419                                methodName = stack.getMethodName();
1420                                lineNumber = stack.getLineNumber();
1421                                break;
1422                        }
1423                        map.put("stack_trace", sw.toString());
1424                        map.put("exception_class_name", exceptionClassName);
1425                        map.put("exception_message", exceptionMessage);
1426                        map.put("issued_file_name", fileName);
1427                        map.put("issued_class_name", className);
1428                        map.put("issued_method_name", methodName);
1429                        map.put("issued_line_number", lineNumber);
1430                }
1431
1432                if (!map.containsKey("stack_trace"))
1433                        map.put("stack_trace", "");
1434
1435                if (!map.containsKey("stack_trace_single"))
1436                        map.put("stack_trace_single", "");
1437
1438                if (!map.containsKey("log_file_name"))
1439                        map.put("log_file_name", "Unknown");
1440
1441                if (!map.containsKey("log_class_name"))
1442                        map.put("log_class_name", clazzName);
1443
1444                if (!map.containsKey("log_method_name"))
1445                        map.put("log_method_name", "Unknown");
1446
1447                if (!map.containsKey("log_line_number"))
1448                        map.put("log_line_number", 0);
1449
1450                map.remove("exception");
1451
1452                String msg = LogRecord.format(DEFAULT_MESSAGE_FORMAT, map);
1453                System.out.println(msg);
1454        }       
1455
1456        private static void log(String level, Class clazz, Map<String, Object> map) {
1457            log(level, clazz.getName(),map);
1458        }
1459
1460        protected void log(Integer _level, Map<String, Object> map) {
1461                String levelStr = null;
1462                String log4jMethodName = null;
1463                switch (_level) {
1464                case 0:
1465                        levelStr = "DEBUG";
1466                        break;
1467                case 1:
1468                        levelStr = "INFO";
1469                        break;
1470                case 2:
1471                        levelStr = "WARN";
1472                        break;
1473                case 3:
1474                        levelStr = "ERROR";
1475                        break;
1476                case 4:
1477                        levelStr = "MARK";
1478                        break;
1479                default:
1480                        break;
1481                }
1482                map.put("level", levelStr);
1483
1484                StackTraceElement[] threadStacks = Thread.currentThread().getStackTrace();
1485                for (StackTraceElement stack : threadStacks) {
1486                        String className = stack.getClassName();
1487                        if (className.equals(clazzName)) {
1488                                String fileName = stack.getFileName();
1489                                String methodName = stack.getMethodName();
1490                                int lineNumber = stack.getLineNumber();
1491                                map.put("log_file_name", fileName);
1492                                map.put("log_class_name", className);
1493                                map.put("log_method_name", methodName);
1494                                map.put("log_line_number", lineNumber);
1495                                break;
1496                        }
1497                }
1498
1499                Thread currentThread = Thread.currentThread();
1500                long threadId = currentThread.getId();
1501                String threadName = currentThread.getName();
1502
1503                Date logTime = new Date();
1504                map.put("log_time", logTime);
1505                map.put("log_time_format", LogRecord.getLogTimeFormat().format(logTime));
1506                map.put("log_thread_id", threadId);
1507                map.put("log_thread_name", threadName);
1508
1509                Exception exception = (Exception) map.get("exception");
1510                if (exception != null) {
1511                        StringWriter sw = new StringWriter();
1512                        exception.printStackTrace(new PrintWriter(sw));
1513                        String exceptionAsString = sw.toString();
1514                        String exceptionClassName = exception.getClass().getName();
1515                        String exceptionMessage = exception.getMessage();
1516                        StackTraceElement[] stacks = exception.getStackTrace();
1517                        String fileName = null;
1518                        String className = null;
1519                        String methodName = null;
1520                        int lineNumber = 0;
1521                        for (StackTraceElement stack : stacks) {
1522                                fileName = stack.getFileName();
1523                                className = stack.getClassName();
1524                                methodName = stack.getMethodName();
1525                                lineNumber = stack.getLineNumber();
1526                                break;
1527                        }
1528                        map.put("stack_trace", sw.toString());
1529                        map.put("stack_trace_single", toSingle(sw.toString()));
1530                        map.put("exception_class_name", exceptionClassName);
1531                        map.put("exception_message", exceptionMessage);
1532                        map.put("exception_message_single", toSingle(exceptionMessage));
1533                        map.put("issued_file_name", fileName);
1534                        map.put("issued_class_name", className);
1535                        map.put("issued_method_name", methodName);
1536                        map.put("issued_line_number", lineNumber);
1537                }
1538
1539                if (map.containsKey("message")) {
1540                        map.put("message_single", toSingle((String) map.get("message")));
1541                }
1542
1543                if (!map.containsKey("stack_trace"))
1544                        map.put("stack_trace", "");
1545
1546                if (!map.containsKey("stack_trace_single"))
1547                        map.put("stack_trace_single", "");
1548
1549                if (!map.containsKey("log_file_name"))
1550                        map.put("log_file_name", "Unknown");
1551
1552                if (!map.containsKey("log_class_name"))
1553                        map.put("log_class_name", clazzName);
1554
1555                if (!map.containsKey("log_method_name"))
1556                        map.put("log_method_name", "Unknown");
1557
1558                if (!map.containsKey("log_line_number"))
1559                        map.put("log_line_number", 0);
1560
1561                map.put("id", CommonTools.generateId(16));
1562                map.put("created_at", CommonTools.generateId(16));
1563                map.put("hostname", hostname);
1564
1565                map.remove("exception");
1566
1567                String logClassName = String.format("%s.%s", map.get("log_class_name"), map.get("log_method_name"));
1568                boolean passEnableRegex = checkClassNameEnableRegex(logClassName);
1569                boolean passDisableRegex = !checkClassNameDisableRegex(logClassName);
1570
1571                if (passEnableRegex && passDisableRegex) {
1572                        LogRecord.add(map);
1573                }
1574        }
1575
1576        private boolean checkClassNameEnableRegex(String logClassName) {
1577                if (!ConfigProperties.isBlank(classNameEnableRegex)) {
1578                        return logClassName.matches(classNameEnableRegex);
1579                }
1580                return true;
1581        }
1582
1583        private boolean checkClassNameDisableRegex(String logClassName) {
1584                if (!ConfigProperties.isBlank(classNameDisableRegex)) {
1585                        return logClassName.matches(classNameDisableRegex);
1586                }
1587                return false;
1588        }
1589
1590        public String getClazzName() {
1591                return clazzName;
1592        }
1593
1594        private String toSingle(String text) {
1595                 return CodeEscape.escapeToSingleLineForCsv(text);      
1596        }
1597        
1598        private static String[] converParams(Object... params){
1599            if(params == null)
1600                return new String[]{"null"};
1601                
1602            String[] stringParams = new String[params.length];
1603            for (int i=0;i<params.length;i++){
1604                stringParams[i]= params[i] + "";
1605            } 
1606            return stringParams;
1607        }
1608
1609}