日志数据: 我们准备工作都做好了,但是接下来该怎么做呢?这里先要搞清楚,只有明确了表中字段的含义,我们才可以根据字段的意思做出效果,所以要先摸明白表中字段含义
生成数据: 数据字段含义已经明了,现在开始获取数据。时时刻刻记得我们前面的数据处理流程,按照自己心中的流程走下去,犯错的时候你也有节奏感,看图:
心中要有图,真正开发的时候,数据一定会有的,所以流程一定要清晰,这里的数据只是辅助清晰流程的
生成流程: 数据生成样板:
main函数动作:
控制延时时间: 前端向后端传输数据,可以一批(10000条),也可以一次一条传输,我们日后有个德鲁伊,要一条一条分析,所以要控制一条一条的来
循环遍历次数: 默认1000条数据,
循环遍历: 我们的json中有两种类型的数据,分别是业务数据,还有日志数据
创建bean对象,直接通过工具类转化为json即可
对于事件时间,就是第二层json里面套了第三层json
处理系统时间: 也就是获取我们拼接好的 | 左边的时间戳
创建项目: idea: maven就行
pom: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 <properties > <slf4j.version > 1.7.20</slf4j.version > <logback.version > 1.0.7</logback.version > </properties > <dependencies > <dependency > <groupId > com.alibaba</groupId > <artifactId > fastjson</artifactId > <version > 1.2.51</version > </dependency > <dependency > <groupId > ch.qos.logback</groupId > <artifactId > logback-core</artifactId > <version > ${logback.version}</version > </dependency > <dependency > <groupId > ch.qos.logback</groupId > <artifactId > logback-classic</artifactId > <version > ${logback.version}</version > </dependency > </dependencies > <build > <plugins > <plugin > <artifactId > maven-compiler-plugin</artifactId > <version > 2.3.2</version > <configuration > <source > 1.8</source > <target > 1.8</target > </configuration > </plugin > <plugin > <artifactId > maven-assembly-plugin </artifactId > <configuration > <descriptorRefs > <descriptorRef > jar-with-dependencies</descriptorRef > </descriptorRefs > <archive > <manifest > <mainClass > com.atguigu.appclient.AppMain</mainClass > </manifest > </archive > </configuration > <executions > <execution > <id > make-assembly</id > <phase > package</phase > <goals > <goal > single</goal > </goals > </execution > </executions > </plugin > </plugins > </build >
bean: 点我下载
main: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 package com.ls.appclient;import com.alibaba.fastjson.JSON;import com.alibaba.fastjson.JSONArray;import com.alibaba.fastjson.JSONObject;import com.ls.bean.*;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import java.io.UnsupportedEncodingException;import java.util.Random;public class AppMain { private final static Logger logger = LoggerFactory.getLogger(AppMain.class); private static Random rand = new Random(); private static int s_mid = 0 ; private static int s_uid = 0 ; private static int s_goodsid = 0 ; public static void main (String[] args) { Long delay = args.length > 0 ? Long.parseLong(args[0 ]) : 0L ; int loop_len = args.length > 1 ? Integer.parseInt(args[1 ]) : 1000 ; generateLog(delay, loop_len); } private static void generateLog (Long delay, int loop_len) { for (int i = 0 ; i < loop_len; i++) { int flag = rand.nextInt(2 ); switch (flag) { case (0 ): AppStart appStart = generateStart(); String jsonString = JSON.toJSONString(appStart); logger.info(jsonString); break ; case (1 ): JSONObject json = new JSONObject(); json.put("ap" , "app" ); json.put("cm" , generateComFields()); JSONArray eventsArray = new JSONArray(); if (rand.nextBoolean()) { eventsArray.add(generateDisplay()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generateNewsDetail()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generateNewList()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generateAd()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generateNotification()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generatbeforeground()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generateBackground()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generateError()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generateComment()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generateFavorites()); json.put("et" , eventsArray); } if (rand.nextBoolean()) { eventsArray.add(generatePraise()); json.put("et" , eventsArray); } long millis = System.currentTimeMillis(); logger.info(millis + "|" + json.toJSONString()); break ; } try { Thread.sleep(delay); } catch (InterruptedException e) { e.printStackTrace(); } } } private static JSONObject generateComFields () { AppBase appBase = new AppBase(); appBase.setMid(s_mid + "" ); s_mid++; appBase.setUid(s_uid + "" ); s_uid++; appBase.setVc("" + rand.nextInt(20 )); appBase.setVn("1." + rand.nextInt(4 ) + "." + rand.nextInt(10 )); appBase.setOs("8." + rand.nextInt(3 ) + "." + rand.nextInt(10 )); int flag = rand.nextInt(3 ); switch (flag) { case (0 ): appBase.setL("es" ); break ; case (1 ): appBase.setL("en" ); break ; case (2 ): appBase.setL("pt" ); break ; } appBase.setSr(getRandomChar(1 )); flag = rand.nextInt(2 ); switch (flag) { case 0 : appBase.setAr("BR" ); case 1 : appBase.setAr("MX" ); } flag = rand.nextInt(3 ); switch (flag) { case 0 : appBase.setBa("Sumsung" ); appBase.setMd("sumsung-" + rand.nextInt(20 )); break ; case 1 : appBase.setBa("Huawei" ); appBase.setMd("Huawei-" + rand.nextInt(20 )); break ; case 2 : appBase.setBa("HTC" ); appBase.setMd("HTC-" + rand.nextInt(20 )); break ; } appBase.setSv("V2." + rand.nextInt(10 ) + "." + rand.nextInt(10 )); appBase.setG(getRandomCharAndNumr(8 ) + "@gmail.com" ); flag = rand.nextInt(4 ); switch (flag) { case 0 : appBase.setHw("640*960" ); break ; case 1 : appBase.setHw("640*1136" ); break ; case 2 : appBase.setHw("750*1134" ); break ; case 3 : appBase.setHw("1080*1920" ); break ; } long millis = System.currentTimeMillis(); appBase.setT("" + (millis - rand.nextInt(99999999 ))); flag = rand.nextInt(3 ); switch (flag) { case 0 : appBase.setNw("3G" ); break ; case 1 : appBase.setNw("4G" ); break ; case 2 : appBase.setNw("WIFI" ); break ; } appBase.setLn((-34 - rand.nextInt(83 ) - rand.nextInt(60 ) / 10.0 ) + "" ); appBase.setLa((32 - rand.nextInt(85 ) - rand.nextInt(60 ) / 10.0 ) + "" ); return (JSONObject) JSON.toJSON(appBase); } private static JSONObject generateDisplay () { AppDisplay appDisplay = new AppDisplay(); boolean boolFlag = rand.nextInt(10 ) < 7 ; if (boolFlag) { appDisplay.setAction("1" ); } else { appDisplay.setAction("2" ); } String goodsId = s_goodsid + "" ; s_goodsid++; appDisplay.setGoodsid(goodsId); int flag = rand.nextInt(6 ); appDisplay.setPlace("" + flag); flag = 1 + rand.nextInt(2 ); appDisplay.setExtend1("" + flag); flag = 1 + rand.nextInt(100 ); appDisplay.setCategory("" + flag); JSONObject jsonObject = (JSONObject) JSON.toJSON(appDisplay); return packEventJson("display" , jsonObject); } private static JSONObject generateNewsDetail () { AppNewsDetail appNewsDetail = new AppNewsDetail(); int flag = 1 + rand.nextInt(3 ); appNewsDetail.setEntry(flag + "" ); appNewsDetail.setAction("" + (rand.nextInt(4 ) + 1 )); appNewsDetail.setGoodsid(s_goodsid + "" ); flag = 1 + rand.nextInt(3 ); appNewsDetail.setShowtype(flag + "" ); flag = rand.nextInt(6 ); appNewsDetail.setShowtype("" + flag); flag = rand.nextInt(10 ) * rand.nextInt(7 ); appNewsDetail.setNews_staytime(flag + "" ); flag = rand.nextInt(10 ) * rand.nextInt(7 ); appNewsDetail.setLoading_time(flag + "" ); flag = rand.nextInt(10 ); switch (flag) { case 1 : appNewsDetail.setType1("102" ); break ; case 2 : appNewsDetail.setType1("201" ); break ; case 3 : appNewsDetail.setType1("325" ); break ; case 4 : appNewsDetail.setType1("433" ); break ; case 5 : appNewsDetail.setType1("542" ); break ; default : appNewsDetail.setType1("" ); break ; } flag = 1 + rand.nextInt(100 ); appNewsDetail.setCategory("" + flag); JSONObject eventJson = (JSONObject) JSON.toJSON(appNewsDetail); return packEventJson("newsdetail" , eventJson); } private static JSONObject generateNewList () { AppLoading appLoading = new AppLoading(); int flag = rand.nextInt(3 ) + 1 ; appLoading.setAction(flag + "" ); flag = rand.nextInt(10 ) * rand.nextInt(7 ); appLoading.setLoading_time(flag + "" ); flag = rand.nextInt(10 ); switch (flag) { case 1 : appLoading.setType1("102" ); break ; case 2 : appLoading.setType1("201" ); break ; case 3 : appLoading.setType1("325" ); break ; case 4 : appLoading.setType1("433" ); break ; case 5 : appLoading.setType1("542" ); break ; default : appLoading.setType1("" ); break ; } flag = 1 + rand.nextInt(2 ); appLoading.setLoading_way("" + flag); appLoading.setExtend1("" ); appLoading.setExtend2("" ); flag = 1 + rand.nextInt(3 ); appLoading.setType("" + flag); JSONObject jsonObject = (JSONObject) JSON.toJSON(appLoading); return packEventJson("loading" , jsonObject); } private static JSONObject generateAd () { AppAd appAd = new AppAd(); int flag = rand.nextInt(3 ) + 1 ; appAd.setEntry(flag + "" ); flag = rand.nextInt(5 ) + 1 ; appAd.setAction(flag + "" ); flag = rand.nextInt(10 ) > 6 ? 2 : 1 ; appAd.setContent(flag + "" ); flag = rand.nextInt(10 ); switch (flag) { case 1 : appAd.setDetail("102" ); break ; case 2 : appAd.setDetail("201" ); break ; case 3 : appAd.setDetail("325" ); break ; case 4 : appAd.setDetail("433" ); break ; case 5 : appAd.setDetail("542" ); break ; default : appAd.setDetail("" ); break ; } flag = rand.nextInt(4 ) + 1 ; appAd.setSource(flag + "" ); flag = rand.nextInt(2 ) + 1 ; appAd.setBehavior(flag + "" ); flag = rand.nextInt(10 ); appAd.setNewstype("" + flag); flag = rand.nextInt(6 ); appAd.setShow_style("" + flag); JSONObject jsonObject = (JSONObject) JSON.toJSON(appAd); return packEventJson("ad" , jsonObject); } private static AppStart generateStart () { AppStart appStart = new AppStart(); appStart.setMid(s_mid + "" ); s_mid++; appStart.setUid(s_uid + "" ); s_uid++; appStart.setVc("" + rand.nextInt(20 )); appStart.setVn("1." + rand.nextInt(4 ) + "." + rand.nextInt(10 )); appStart.setOs("8." + rand.nextInt(3 ) + "." + rand.nextInt(10 )); appStart.setEn("start" ); int flag = rand.nextInt(3 ); switch (flag) { case (0 ): appStart.setL("es" ); break ; case (1 ): appStart.setL("en" ); break ; case (2 ): appStart.setL("pt" ); break ; } appStart.setSr(getRandomChar(1 )); flag = rand.nextInt(2 ); switch (flag) { case 0 : appStart.setAr("BR" ); case 1 : appStart.setAr("MX" ); } flag = rand.nextInt(3 ); switch (flag) { case 0 : appStart.setBa("Sumsung" ); appStart.setMd("sumsung-" + rand.nextInt(20 )); break ; case 1 : appStart.setBa("Huawei" ); appStart.setMd("Huawei-" + rand.nextInt(20 )); break ; case 2 : appStart.setBa("HTC" ); appStart.setMd("HTC-" + rand.nextInt(20 )); break ; } appStart.setSv("V2." + rand.nextInt(10 ) + "." + rand.nextInt(10 )); appStart.setG(getRandomCharAndNumr(8 ) + "@gmail.com" ); flag = rand.nextInt(4 ); switch (flag) { case 0 : appStart.setHw("640*960" ); break ; case 1 : appStart.setHw("640*1136" ); break ; case 2 : appStart.setHw("750*1134" ); break ; case 3 : appStart.setHw("1080*1920" ); break ; } long millis = System.currentTimeMillis(); appStart.setT("" + (millis - rand.nextInt(99999999 ))); flag = rand.nextInt(3 ); switch (flag) { case 0 : appStart.setNw("3G" ); break ; case 1 : appStart.setNw("4G" ); break ; case 2 : appStart.setNw("WIFI" ); break ; } appStart.setLn((-34 - rand.nextInt(83 ) - rand.nextInt(60 ) / 10.0 ) + "" ); appStart.setLa((32 - rand.nextInt(85 ) - rand.nextInt(60 ) / 10.0 ) + "" ); flag = rand.nextInt(5 ) + 1 ; appStart.setEntry(flag + "" ); flag = rand.nextInt(2 ) + 1 ; appStart.setOpen_ad_type(flag + "" ); flag = rand.nextInt(10 ) > 8 ? 2 : 1 ; appStart.setAction(flag + "" ); appStart.setLoading_time(rand.nextInt(20 ) + "" ); flag = rand.nextInt(10 ); switch (flag) { case 1 : appStart.setDetail("102" ); break ; case 2 : appStart.setDetail("201" ); break ; case 3 : appStart.setDetail("325" ); break ; case 4 : appStart.setDetail("433" ); break ; case 5 : appStart.setDetail("542" ); break ; default : appStart.setDetail("" ); break ; } appStart.setExtend1("" ); return appStart; } private static JSONObject generateNotification () { AppNotification appNotification = new AppNotification(); int flag = rand.nextInt(4 ) + 1 ; appNotification.setAction(flag + "" ); flag = rand.nextInt(4 ) + 1 ; appNotification.setType(flag + "" ); appNotification.setAp_time((System.currentTimeMillis() - rand.nextInt(99999999 )) + "" ); appNotification.setContent("" ); JSONObject jsonObject = (JSONObject) JSON.toJSON(appNotification); return packEventJson("notification" , jsonObject); } private static JSONObject generatbeforeground () { AppActive_foreground appActive_foreground = new AppActive_foreground(); int flag = rand.nextInt(2 ); switch (flag) { case 1 : appActive_foreground.setAccess(flag + "" ); break ; default : appActive_foreground.setAccess("" ); break ; } flag = rand.nextInt(3 ) + 1 ; appActive_foreground.setPush_id(flag + "" ); JSONObject jsonObject = (JSONObject) JSON.toJSON(appActive_foreground); return packEventJson("active_foreground" , jsonObject); } private static JSONObject generateBackground () { AppActive_background appActive_background = new AppActive_background(); int flag = rand.nextInt(3 ) + 1 ; appActive_background.setActive_source(flag + "" ); JSONObject jsonObject = (JSONObject) JSON.toJSON(appActive_background); return packEventJson("active_background" , jsonObject); } private static JSONObject generateError () { AppErrorLog appErrorLog = new AppErrorLog(); String[] errorBriefs = {"at cn.lift.dfdf.web.AbstractBaseController.validInbound(AbstractBaseController.java:72)" , "at cn.lift.appIn.control.CommandUtil.getInfo(CommandUtil.java:67)" }; String[] errorDetails = {"java.lang.NullPointerException\\n " + "at cn.lift.appIn.web.AbstractBaseController.validInbound(AbstractBaseController.java:72)\\n " + "at cn.lift.dfdf.web.AbstractBaseController.validInbound" , "at cn.lift.dfdfdf.control.CommandUtil.getInfo(CommandUtil.java:67)\\n " + "at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\\n" + " at java.lang.reflect.Method.invoke(Method.java:606)\\n" }; appErrorLog.setErrorBrief(errorBriefs[rand.nextInt(errorBriefs.length)]); appErrorLog.setErrorDetail(errorDetails[rand.nextInt(errorDetails.length)]); JSONObject jsonObject = (JSONObject) JSON.toJSON(appErrorLog); return packEventJson("error" , jsonObject); } private static JSONObject packEventJson (String eventName, JSONObject jsonObject) { JSONObject eventJson = new JSONObject(); eventJson.put("ett" , (System.currentTimeMillis() - rand.nextInt(99999999 )) + "" ); eventJson.put("en" , eventName); eventJson.put("kv" , jsonObject); return eventJson; } private static String getRandomChar (Integer length) { StringBuilder str = new StringBuilder(); Random random = new Random(); for (int i = 0 ; i < length; i++) { str.append((char ) (65 + random.nextInt(26 ))); } return str.toString(); } private static String getRandomCharAndNumr (Integer length) { StringBuilder str = new StringBuilder(); Random random = new Random(); for (int i = 0 ; i < length; i++) { boolean b = random.nextBoolean(); if (b) { str.append((char ) (65 + random.nextInt(26 ))); } else { str.append(String.valueOf(random.nextInt(10 ))); } } return str.toString(); } private static JSONObject generateFavorites () { AppFavorites favorites = new AppFavorites(); favorites.setCourse_id(rand.nextInt(10 )); favorites.setUserid(rand.nextInt(10 )); favorites.setAdd_time((System.currentTimeMillis() - rand.nextInt(99999999 )) + "" ); JSONObject jsonObject = (JSONObject) JSON.toJSON(favorites); return packEventJson("favorites" , jsonObject); } private static JSONObject generatePraise () { AppPraise praise = new AppPraise(); praise.setId(rand.nextInt(10 )); praise.setUserid(rand.nextInt(10 )); praise.setTarget_id(rand.nextInt(10 )); praise.setType(rand.nextInt(4 ) + 1 ); praise.setAdd_time((System.currentTimeMillis() - rand.nextInt(99999999 )) + "" ); JSONObject jsonObject = (JSONObject) JSON.toJSON(praise); return packEventJson("praise" , jsonObject); } private static JSONObject generateComment () { AppComment comment = new AppComment(); comment.setComment_id(rand.nextInt(10 )); comment.setUserid(rand.nextInt(10 )); comment.setP_comment_id(rand.nextInt(5 )); comment.setContent(getCONTENT()); comment.setAddtime((System.currentTimeMillis() - rand.nextInt(99999999 )) + "" ); comment.setOther_id(rand.nextInt(10 )); comment.setPraise_count(rand.nextInt(1000 )); comment.setReply_count(rand.nextInt(200 )); JSONObject jsonObject = (JSONObject) JSON.toJSON(comment); return packEventJson("comment" , jsonObject); } private static char getRandomChar () { String str = "" ; int hightPos; int lowPos; Random random = new Random(); hightPos = (176 + Math.abs(random.nextInt(39 ))); lowPos = (161 + Math.abs(random.nextInt(93 ))); byte [] b = new byte [2 ]; b[0 ] = (Integer.valueOf(hightPos)).byteValue(); b[1 ] = (Integer.valueOf(lowPos)).byteValue(); try { str = new String(b, "GBK" ); } catch (UnsupportedEncodingException e) { e.printStackTrace(); System.out.println("错误" ); } return str.charAt(0 ); } private static String getCONTENT () { StringBuilder str = new StringBuilder(); for (int i = 0 ; i < rand.nextInt(100 ); i++) { str.append(getRandomChar()); } return str.toString(); } }
xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 <?xml version="1.0" encoding="UTF-8"?> <configuration debug ="false" > <property name ="LOG_HOME" value ="/tmp/logs/" /> <appender name ="STDOUT" class ="ch.qos.logback.core.ConsoleAppender" > <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern > %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern > </encoder > </appender > <appender name ="FILE" class ="ch.qos.logback.core.rolling.RollingFileAppender" > <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern > ${LOG_HOME}/app-%d{yyyy-MM-dd}.log</FileNamePattern > <MaxHistory > 30</MaxHistory > </rollingPolicy > <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <pattern > %msg%n</pattern > </encoder > <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> <MaxFileSize > 10MB</MaxFileSize > </triggeringPolicy > </appender > <appender name ="ASYNC_FILE" class = "ch.qos.logback.classic.AsyncAppender" > <discardingThreshold > 0</discardingThreshold > <queueSize > 512</queueSize > <appender-ref ref = "FILE" /> </appender > <root level ="INFO" > <appender-ref ref ="STDOUT" /> <appender-ref ref ="ASYNC_FILE" /> <appender-ref ref ="error" /> </root > </configuration >
打包 用idea的package打包