-
Notifications
You must be signed in to change notification settings - Fork 0
/
osc-blog.html
5110 lines (4212 loc) · 530 KB
/
osc-blog.html
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
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html class="theme-next mist" lang="zh-CN">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2"/>
<meta name="theme-color" content="#222"/>
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2"/>
<link rel="stylesheet" href="/css/main.css?v=7.0.0"/>
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=7.0.0">
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=7.0.0">
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=7.0.0">
<link rel="mask-icon" href="/images/logo.svg?v=7.0.0" color="#222">
<script id="hexo.configurations">
var NexT = window.NexT || {};
var CONFIG = {
root: '/',
scheme: 'Mist',
version: '7.0.0',
sidebar: {"position":"right","display":"hide","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
fancybox: false,
fastclick: false,
lazyload: false,
tabs: true,
motion: {"enable":false,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
algolia: {
applicationID: '',
apiKey: '',
indexName: '',
hits: {"per_page":10},
labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
}
};
</script>
<meta name="description" content="Mr_Kail的博客 body { font: 12px/21px Tahoma, "Microsoft Yahei", Geneva, sans-serif; } h1 a { color: #40AA53; }">
<meta property="og:type" content="website">
<meta property="og:title" content="Mr.Kail's Blog">
<meta property="og:url" content="http://blog.kail.xyz/osc-blog.html">
<meta property="og:site_name" content="Mr.Kail's Blog">
<meta property="og:description" content="Mr_Kail的博客 body { font: 12px/21px Tahoma, "Microsoft Yahei", Geneva, sans-serif; } h1 a { color: #40AA53; }">
<meta property="og:locale" content="zh-CN">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185110_D7wn.jpg">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185109_eRyg.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185109_xPiT.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_R7gf.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_Mt3u.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_R7gf.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_Mt3u.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_nKze.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_zYJu.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_nKze.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_zYJu.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_nKze.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_zYJu.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_nKze.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185106_zYJu.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185056_EARC.jpg">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185056_Co9w.jpg">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185056_7Hh4.jpg">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185056_ZYJq.jpg">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185054_zRLu.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185054_FDF1.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185054_zRLu.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185054_FDF1.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185046_nR6n.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185046_sksg.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185046_nR6n.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185046_sksg.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185046_nR6n.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201605/28185046_sksg.gif">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201507/31164121_6DLB.png">
<meta property="og:image" content="http://static.oschina.net/uploads/img/201507/31164122_kg7c.gif">
<meta property="og:updated_time" content="2018-06-16T13:21:39.506Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Mr.Kail's Blog">
<meta name="twitter:description" content="Mr_Kail的博客 body { font: 12px/21px Tahoma, "Microsoft Yahei", Geneva, sans-serif; } h1 a { color: #40AA53; }">
<meta name="twitter:image" content="http://static.oschina.net/uploads/img/201605/28185110_D7wn.jpg">
<link rel="canonical" href="http://blog.kail.xyz/osc-blog.html"/>
<script id="page.configurations">
CONFIG.page = {
sidebar: "",
};
</script>
<title> | Mr.Kail's Blog</title>
<noscript>
<style>
.use-motion .motion-element,
.use-motion .brand,
.use-motion .menu-item,
.sidebar-inner,
.use-motion .post-block,
.use-motion .pagination,
.use-motion .comments,
.use-motion .post-header,
.use-motion .post-body,
.use-motion .collection-title { opacity: initial; }
.use-motion .logo,
.use-motion .site-title,
.use-motion .site-subtitle {
opacity: initial;
top: initial;
}
.use-motion .logo-line-before i { left: initial; }
.use-motion .logo-line-after i { right: initial; }
</style>
</noscript>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">
<div class="container sidebar-position-right page-post-detail">
<div class="headband"></div>
<header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
<div class="header-inner"><div class="site-brand-wrapper">
<div class="site-meta">
<div class="custom-logo-site-title">
<a href="/" class="brand" rel="start">
<span class="logo-line-before"><i></i></span>
<span class="site-title">Mr.Kail's Blog</span>
<span class="logo-line-after"><i></i></span>
</a>
</div>
</div>
<div class="site-nav-toggle">
<button aria-label="切换导航栏">
<span class="btn-bar"></span>
<span class="btn-bar"></span>
<span class="btn-bar"></span>
</button>
</div>
</div>
<nav class="site-nav">
<ul id="menu" class="menu">
<li class="menu-item menu-item-tags">
<a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i> <br/>标签</a>
</li>
<li class="menu-item menu-item-categories">
<a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i> <br/>分类</a>
</li>
<li class="menu-item menu-item-archives">
<a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i> <br/>归档</a>
</li>
<li class="menu-item menu-item-docs">
<a href="http://blog.kail.xyz/docsify" rel="section"><i class="menu-item-icon fa fa-fw fa-github"></i> <br/>Docs</a>
</li>
</ul>
</nav>
</div>
</header>
<main id="main" class="main">
<div class="main-inner">
<div class="content-wrap">
<div id="content" class="content">
<div id="posts" class="posts-expand">
<div class="post-block page">
<header class="post-header">
<h2 class="post-title" itemprop="name headline">
</h2>
<div class="post-meta">
</div>
</header>
<div class="post-body">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="zh-CN" xml:lang="zh-CN" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Language" content="zh-CN">
<title>Mr_Kail的博客</title>
<style>
body {
font: 12px/21px Tahoma, "Microsoft Yahei", Geneva, sans-serif;
}
h1 a {
color: #40AA53;
}
h1 a,
h2 a {
text-decoration: none;
}
.backupDesc em {
font-style: normal;
}
.blog {
margin: 0 0 20px 0;
border: 1px solid #ccc;
background: #ffc;
padding: 10px;
}
.blog h2 {
border-bottom: 1px solid #ccc;
padding: 0 0 10px 0;
}
.blog h2 a.top {
float: right;
font-weight: normal;
font-size: 9pt;
}
.blog .outline {
background: #fff;
border: 1px solid #eee;
padding: 10px;
color: #666;
}
.commentList {
margin: 20px 0 0 0;
}
.comment {
margin: 0 0 10px 0;
border: 1px solid #ddd;
background: #ffe;
padding: 5px;
}
.comment .author {
float: left;
font-weight: bold;
}
.comment .date {
float: left;
margin: 0 0 0 10px;
}
.comment .content {
clear: left;
margin: 5px 0 0 0;
}
</style>
</head>
<body>
<h1><a name="top" href="http://my.oschina.net/yokoboy/blog" target="_blank" rel="noopener">Mr_Kail的博客@OSCHINA</a></h1>
<p class="backupDesc">共有<em>49</em>篇文章,备份时间:2016-06-09 18:23:07</p>
<ol>
<li><a href="#blog_683398">log4j——配置详解</a></li>
<li><a href="#blog_683397">free命令——显示内存使用情况</a></li>
<li><a href="#blog_683396">MySQL——基础入门</a></li>
<li><a href="#blog_683395">js中的逻辑运算符</a></li>
<li><a href="#blog_683394">Java加载资源文件时的路径问题</a></li>
<li><a href="#blog_683393">JDK 1.5 新特性——枚举</a></li>
<li><a href="#blog_683391">Spring 实例化bean的初始化方法和销毁方法 init-method destroy-method</a></li>
<li><a href="#blog_683390">JDK 1.5 新特性——C风格的格式化输出</a></li>
<li><a href="#blog_683389">Spring实例化Bean的三种方式</a></li>
<li><a href="#blog_683385">JQuery——那些当时我想不到的知识点</a></li>
<li><a href="#blog_683384">JDK 1.5 新特性——静态导入</a></li>
<li><a href="#blog_683382">JDK 1.5 新特性——泛型</a></li>
<li><a href="#blog_683377">常用命令小计</a></li>
<li><a href="#blog_683375">EasyUI——常见用法总结</a></li>
<li><a href="#blog_683374">JDK 1.5 新特性——可变参数</a></li>
<li><a href="#blog_683373">hibernate自动建库(MySQL)</a></li>
<li><a href="#blog_683372">网站robots.txt文件简析</a></li>
<li><a href="#blog_683371">firebird——gsec命令</a></li>
<li><a href="#blog_683370">MySQL JDBC URL中几个重要参数说明</a></li>
<li><a href="#blog_683369">firebird——isql命令</a></li>
<li><a href="#blog_683366">JDK 1.5 新特性</a></li>
<li><a href="#blog_683365">log4j——入门初识</a></li>
<li><a href="#blog_683364">scrollLeft,scrollTop,滚动代码的总结</a></li>
<li><a href="#blog_683361">css3阴影效果</a></li>
<li><a href="#blog_683359">firebird——命令行管理初识</a></li>
<li><a href="#blog_683358">top命令——监视用户进程</a></li>
<li><a href="#blog_683357">Jquery.cookie 插件</a></li>
<li><a href="#blog_683356">EasyUI——Dialog自定义Toolbar和buttons</a></li>
<li><a href="#blog_683355">js 实现“暂停”功能</a></li>
<li><a href="#blog_683354">JDK 1.5 新特性——自动拆箱装箱</a></li>
<li><a href="#blog_683350">JDK 1.5 新特性——Scanner</a></li>
<li><a href="#blog_683349">firebird——Spring hibernate 集成连接配置</a></li>
<li><a href="#blog_683347">MySQL——数据导出与导入(备份与还原)</a></li>
<li><a href="#blog_683343">JDK 1.5 新特性——增强for循环</a></li>
<li><a href="#blog_683342">JDK 环境变量配置</a></li>
<li><a href="#blog_683341">事件冒泡</a></li>
<li><a href="#blog_611855">导出大数据量到Excel</a></li>
<li><a href="#blog_611852">mycli</a></li>
<li><a href="#blog_539747">RabbitMQ 安装</a></li>
<li><a href="#blog_508855">Zookeeper 安装</a></li>
<li><a href="#blog_489667">PHP + Nginx</a></li>
<li><a href="#blog_489662">Java类中静态内容的初始化顺序</a></li>
<li><a href="#blog_480158">Ubuntu Desktop 系统配置</a></li>
<li><a href="#blog_478634">ubuntu 常用软件</a></li>
<li><a href="#blog_396620">MongoDB 入门笔记</a></li>
</ol>
<div class="blogList">
<div class="blog">
<h2><a href="#top" class="top">回到顶部</a><a name="blog_683398" href="http://my.oschina.net/yokoboy/blog/683398" target="_blank" rel="noopener">log4j——配置详解</a></h2>
<div class="outline">
<div class="date">时间:2016-05-28 18:51:08</div>
<div class="catalog">分类:日常记录</div>
</div>
<div class="content">
<p> </p>
<p>Log4j日志是分等级的,级别由高到低分别为:<strong><span style="color:#ff0000"> OFF ,FATAL ,ERROR ,WARN ,INFO ,DEBUG ,ALL。</span> </strong></p>
<p>Log4j建议只使用<strong>FATAL ,ERROR ,WARN ,INFO ,DEBUG</strong>这五个级别。</p>
<p> </p>
<p>Log4j有个根配置,大概就是全局配置,其他配置继承与根配置</p>
<p>log4j.rootLogger=<strong><span style="color:#ff0000">debug</span></strong>,<strong><span style="color:#ff9900">appender1,appender2……</span></strong></p>
<p>debug代表日志的等级,只有debug或者比debug高的等级的日志才会被输出。</p>
<p>后面的<strong>appender1,appender2……</strong>可以控制日志以什么方式输出输出到哪。</p>
<p> </p>
<p>log4j.rootLogger代表全局的输出方式,其他输出方式继承自全局输出方式。</p>
<p> </p>
<pre>
<code><strong><span style="font-size:18pt">常用输出目的地如下:</span></strong></code></pre>
<p> </p>
<pre>
<code><span style="color:#000000"><span style="color:#ff0000"><strong>org.apache.log4j.ConsoleAppender(控制台)</strong></span> org.apache.log4j.FileAppender(文件) <strong><span style="color:#ff0000">org.apache.log4j.DailyRollingFileAppender(每天产生一个日志文件)</span></strong> org.apache.log4j.RollingFileAppender(文件大小到达指定尺寸的时候产生一个新的文件) org.apache.log4j.WriterAppender(将日志信息以流格式发送到任意指定的地方)
<strong><span style="color:#ff0000">org.apache.log4j.jdbc.JDBCAppender(将日志信息输出到数据库)</span></strong>
</span></code></pre>
<p><strong><span style="font-size:16px">(1)ConsoleAppender选项:</span></strong><br> Threshold=WARN:指定日志信息的最低输出级别,默认为DEBUG。
<br> ImmediateFlush=true:表示所有消息都会被立即输出,设为false则不输出,默认值是true。
<br> Target=System.err:默认值是System.out。
</p>
<p><br>
<strong><span style="font-size:16px">(2)FileAppender选项:</span></strong><br> Threshold=WARN:指定日志信息的最低输出级别,默认为DEBUG。
<br> ImmediateFlush=true:表示所有消息都会被立即输出,设为false则不输出,默认值是true。
<br> Append=false:true表示消息增加到指定文件中,false则将消息覆盖指定的文件内容,默认值是true。
<br> File=D:/logs/logging.log4j:指定消息输出到logging.log4j文件中。
</p>
<p><br>
<span style="font-size:16px"><strong>(3)DailyRollingFileAppender选项:</strong></span><br> Threshold=WARN:指定日志信息的最低输出级别,默认为DEBUG。
<br> ImmediateFlush=true:表示所有消息都会被立即输出,设为false则不输出,默认值是true。
<br> Append=false:true表示消息增加到指定文件中,false则将消息覆盖指定的文件内容,默认值是true。
<br> File=D:/logs/logging.log4j:指定当前消息输出到logging.log4j文件中。
<br> DatePattern='.'yyyy-MM:每月滚动一次日志文件,即每月产生一个新的日志文件。当前月的日志文件名为logging.log4j,前一个月的日志文件名为logging.log4j.yyyy-MM。
<br> 另外,也可以指定按周、天、时、分等来滚动日志文件,对应的格式如下:
<br> 1)'.'yyyy-MM:每月
<br> 2)'.'yyyy-ww:每周
<br> 3)'.'yyyy-MM-dd:每天
<br> 4)'.'yyyy-MM-dd-a:每天两次
<br> 5)'.'yyyy-MM-dd-HH:每小时
<br> 6)'.'yyyy-MM-dd-HH-mm:每分钟
</p>
<p><br>
<span style="font-size:16px"><strong>(4)RollingFileAppender选项:</strong></span><br> Threshold=WARN:指定日志信息的最低输出级别,默认为DEBUG。
<br> ImmediateFlush=true:表示所有消息都会被立即输出,设为false则不输出,默认值是true。
<br> Append=false:true表示消息增加到指定文件中,false则将消息覆盖指定的文件内容,默认值是true。
<br> File=D:/logs/logging.log4j:指定消息输出到logging.log4j文件中。
<br> MaxFileSize=100KB:后缀可以是KB, MB 或者GB。在日志文件到达该大小时,将会自动滚动,即将原来的内容移到logging.log4j.1文件中。<br> MaxBackupIndex=2:指定可以产生的滚动文件的最大数,例如,设为2则可以产生logging.log4j.1,logging.log4j.2两个滚动文件和一个logging.log4j文件。
</p>
<p> </p>
<pre>
<code><strong><span style="font-size:18pt">配置日志信息的输出格式(Layout):</span></strong></code></pre>
<p> </p>
<p><br> log4j.appender.appenderName.layout=className
<br> className:可设值如下:
</p>
<pre>
<code>(1<span style="color:#000000">)org.apache.log4j.HTMLLayout(以HTML表格形式布局) (</span>2<span style="color:#000000">)org.apache.log4j.PatternLayout(可以灵活地指定布局模式) (</span>3<span style="color:#000000">)org.apache.log4j.SimpleLayout(包含日志信息的级别和信息字符串) (</span>4)org.apache.log4j.TTCCLayout(包含日志产生的时间、线程、类别等等信息)</code></pre>
<p> </p>
<p><br>
<strong><span style="font-size:16px">(1)HTMLLayout选项:</span></strong><br> LocationInfo=true:输出java文件名称和行号,默认值是false。
<br> Title=My Logging: 默认值是Log4J Log Messages。</p>
<p><br>
<strong><span style="font-size:16px">(2)PatternLayout选项:</span></strong><br> ConversionPattern=%m%n:设定以怎样的格式显示消息。
<br>
<br> 格式化符号说明:
<br>
<br>
<strong>%p:</strong>输出日志信息的优先级,即DEBUG,INFO,WARN,ERROR,FATAL。<br>
<strong>%d:</strong>输出日志时间点的日期或时间,默认格式为ISO8601,也可以在其后指定格式,如:%d{yyyy/MM/dd HH:mm:ss,SSS}。<br> %r:输出自应用程序启动到输出该log信息耗费的毫秒数。
<br> %t:输出产生该日志事件的线程名。
<br>
<strong>%l:</strong>输出日志事件的发生位置,相当于%c.%M(%F:%L)的组合,包括类全名、方法、文件名以及在代码中的行数。例如:test.TestLog4j.main(TestLog4j.java:10)。<br> %c:输出日志信息所属的类目,通常就是所在类的全名。
<br>
<strong>%M:</strong>输出产生日志信息的方法名。<br> %F:输出日志消息产生时所在的文件名称。
<br>
<strong>%L::</strong>输出代码中的行号。<br>
<strong>%m::</strong>输出代码中指定的具体日志信息。<br>
<strong>%n:</strong>输出一个回车换行符,Windows平台为"\r\n",Unix平台为"\n"。<br> %x:输出和当前线程相关联的NDC(嵌套诊断环境),尤其用到像java servlets这样的多客户多线程的应用中。<br> %%:输出一个"%"字符。
<br> 另外,还可以在%与格式字符之间加上修饰符来控制其最小长度、最大长度、和文本的对齐方式。如:
<br> 1) c:指定输出category的名称,最小的长度是20,如果category的名称长度小于20的话,默认的情况下右对齐。<br> 2)%-20c:"-"号表示左对齐。
<br> 3)%.30c:指定输出category的名称,最大的长度是30,如果category的名称长度大于30的话,就会将左边多出的字符截掉,但小于30的话也不会补空格。
</p>
<p> </p>
<p> </p>
<pre>
<code><span style="font-size:18pt"><strong>附录<span style="font-size:15px">(Log4j比较全面的配置)</span></strong></span></code></pre>
<p> </p>
<p><br>
<br> Log4j配置文件实现了输出到控制台、文件、回滚文件、发送日志邮件、输出到数据库日志表、自定义标签等全套功能。
</p>
<p>log4j.rootLogger=DEBUG,console,dailyFile,im<br>
<br>
<span style="color:#333399; font-size:14pt"><strong># 控制台(console)</strong></span><br>
<span style="color:#333399">log4j.appender.console=org.apache.log4j.ConsoleAppender</span><br>
<span style="color:#333399">log4j.appender.console.Threshold=DEBUG</span><br>
<span style="color:#333399">log4j.appender.console.ImmediateFlush=true</span><br>
<span style="color:#333399">log4j.appender.console.Target=System.err</span><br>
<span style="color:#333399">log4j.appender.console.layout=org.apache.log4j.PatternLayout</span><br>
<span style="color:#333399">log4j.appender.console.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n</span></p>
<hr>
<p><br>
<span style="color:#333399"><strong><span style="font-size:14pt"># 日志文件(logFile)</span></strong>
</span><br>
<span style="color:#333399">log4j.appender.logFile=org.apache.log4j.FileAppender</span><br>
<span style="color:#333399">log4j.appender.logFile.Threshold=DEBUG</span><br>
<span style="color:#333399">log4j.appender.logFile.ImmediateFlush=true</span><br>
<span style="color:#333399">log4j.appender.logFile.Append=true</span><br>
<span style="color:#333399">log4j.appender.logFile.File=D:/logs/log.log4j</span><br>
<span style="color:#333399">log4j.appender.logFile.layout=org.apache.log4j.PatternLayout</span><br>
<span style="color:#333399">log4j.appender.logFile.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n</span></p>
<hr>
<p><br>
<span style="color:#333399"><strong><span style="font-size:14pt"># 回滚文件(rollingFile)</span></strong>
</span><br>
<span style="color:#333399">log4j.appender.rollingFile=org.apache.log4j.RollingFileAppender</span><br>
<span style="color:#333399">log4j.appender.rollingFile.Threshold=DEBUG</span><br>
<span style="color:#333399">log4j.appender.rollingFile.ImmediateFlush=true</span><br>
<span style="color:#333399">log4j.appender.rollingFile.Append=true</span><br>
<span style="color:#333399">log4j.appender.rollingFile.File=D:/logs/log.log4j</span><br>
<span style="color:#333399">log4j.appender.rollingFile.MaxFileSize=200KB</span><br>
<span style="color:#333399">log4j.appender.rollingFile.MaxBackupIndex=50</span><br>
<span style="color:#333399">log4j.appender.rollingFile.layout=org.apache.log4j.PatternLayout</span><br>
<span style="color:#333399">log4j.appender.rollingFile.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n</span></p>
<hr>
<p><br>
<span style="color:#333399"><strong><span style="font-size:14pt"># 定期回滚日志文件(dailyFile)</span></strong>
</span><br>
<span style="color:#333399">log4j.appender.dailyFile=org.apache.log4j.DailyRollingFileAppender</span><br>
<span style="color:#333399">log4j.appender.dailyFile.Threshold=DEBUG</span><br>
<span style="color:#333399">log4j.appender.dailyFile.ImmediateFlush=true</span><br>
<span style="color:#333399">log4j.appender.dailyFile.Append=true</span><br>
<span style="color:#333399">log4j.appender.dailyFile.File=D:/logs/log.log4j</span><br>
<span style="color:#333399">log4j.appender.dailyFile.DatePattern='.'yyyy-MM-dd</span><br>
<span style="color:#333399">log4j.appender.dailyFile.layout=org.apache.log4j.PatternLayout</span><br>
<span style="color:#333399">log4j.appender.dailyFile.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n</span></p>
<hr>
<p><br>
<span style="color:#c0c0c0"><strong><span style="font-size:14pt"># 应用于socket</span></strong>
</span><br>
<span style="color:#c0c0c0">log4j.appender.socket=org.apache.log4j.RollingFileAppender</span><br>
<span style="color:#c0c0c0">log4j.appender.socket.RemoteHost=localhost</span><br>
<span style="color:#c0c0c0">log4j.appender.socket.Port=5001</span><br>
<span style="color:#c0c0c0">log4j.appender.socket.LocationInfo=true</span><br>
<span style="color:#c0c0c0"># Set up for Log Factor 5</span><br>
<span style="color:#c0c0c0">log4j.appender.socket.layout=org.apache.log4j.PatternLayout</span><br>
<span style="color:#c0c0c0">log4j.appender.socket.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n</span><br>
<span style="color:#c0c0c0"># Log Factor 5 Appender</span><br>
<span style="color:#c0c0c0">log4j.appender.LF5_APPENDER=org.apache.log4j.lf5.LF5Appender</span><br>
<span style="color:#c0c0c0">log4j.appender.LF5_APPENDER.MaxNumberOfRecords=2000</span></p>
<hr>
<p><br>
<span style="color:#c0c0c0"><strong><span style="font-size:14pt"># 发送日志到指定邮件</span></strong>
</span><br>
<span style="color:#c0c0c0">log4j.appender.mail=org.apache.log4j.net.SMTPAppender</span><br>
<span style="color:#c0c0c0">log4j.appender.mail.Threshold=FATAL</span><br>
<span style="color:#c0c0c0">log4j.appender.mail.BufferSize=10</span><br>
<span style="color:#c0c0c0">log4j.appender.mail.From = [email protected]</span><br>
<span style="color:#c0c0c0">log4j.appender.mail.SMTPHost=mail.com</span><br>
<span style="color:#c0c0c0">log4j.appender.mail.Subject=Log4J Message</span><br>
<span style="color:#c0c0c0">log4j.appender.mail.To= [email protected]</span><br>
<span style="color:#c0c0c0">log4j.appender.mail.layout=org.apache.log4j.PatternLayout</span><br>
<span style="color:#c0c0c0">log4j.appender.mail.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n</span></p>
<hr>
<p><br>
<span style="color:#333399"><strong><span style="font-size:14pt"># 应用于数据库</span></strong>
</span><br>
<span style="color:#333399">log4j.appender.database=org.apache.log4j.jdbc.JDBCAppender</span><br>
<span style="color:#333399">log4j.appender.database.URL=jdbc:mysql://localhost:3306/test</span><br>
<span style="color:#333399">log4j.appender.database.driver=com.mysql.jdbc.Driver</span><br>
<span style="color:#333399">log4j.appender.database.user=root</span><br>
<span style="color:#333399">log4j.appender.database.password=</span><br>
<span style="color:#333399">log4j.appender.database.sql=INSERT INTO LOG4J (Message) VALUES('=[%-5p] %d(%r) --> [%t] %l: %m %x %n')</span><br>
<span style="color:#333399">log4j.appender.database.layout=org.apache.log4j.PatternLayout</span><br>
<span style="color:#333399">log4j.appender.database.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n</span></p>
<hr>
<p><br>
<span style="color:#c0c0c0"><strong><span style="font-size:14pt"># 自定义Appender</span></strong>
</span><br>
<span style="color:#c0c0c0">log4j.appender.im = net.cybercorlin.util.logger.appender.IMAppender</span><br>
<span style="color:#c0c0c0">log4j.appender.im.host = mail.cybercorlin.net</span><br>
<span style="color:#c0c0c0">log4j.appender.im.username = username</span><br>
<span style="color:#c0c0c0">log4j.appender.im.password = password</span><br>
<span style="color:#c0c0c0">log4j.appender.im.recipient = [email protected]</span><br>
<span style="color:#c0c0c0">log4j.appender.im.layout=org.apache.log4j.PatternLayout</span><br>
<span style="color:#c0c0c0">log4j.appender.im.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n</span></p>
<p> </p>
<p> </p>
</div>
</div>
<div class="blog">
<h2><a href="#top" class="top">回到顶部</a><a name="blog_683397" href="http://my.oschina.net/yokoboy/blog/683397" target="_blank" rel="noopener">free命令——显示内存使用情况</a></h2>
<div class="outline">
<div class="date">时间:2016-05-28 18:51:08</div>
<div class="catalog">分类:日常记录</div>
</div>
<div class="content">
<p> </p>
<p>free命令用来显示内存的使用情况,使用权限是所有用户。</p>
<p><img alt="" src="http://static.oschina.net/uploads/img/201605/28185110_D7wn.jpg"></p>
<p>下面是对这些数值的解释:<br>
<strong>total:</strong><strong>总计物理内存的大小。</strong><br>
<strong>used:</strong><strong>已使用多大。</strong><br>
<strong>free:</strong><strong>可用有多少。</strong><br> Shared:多个进程共享的内存总额。
<br> Buffers/cached:磁盘缓存的大小。
<br> 第三行(-/+ buffers/cached):<br> used:已使用多大。
<br> free:可用有多少。
</p>
<p><span style="font-size:18pt"><strong>格式</strong></span><br>
<span style="color:#ff0000"><strong>free [-b -k -m] [-o] [-s delay] [-t] [-V]</strong></span></p>
<p><br>
<span style="font-size:18pt"><strong>主要参数</strong></span><br>
<span style="color:#ff0000">-b -k -m:分别以字节(KB、MB)为单位显示内存使用情况。</span><br>
<span style="color:#ff0000">-s delay:显示每隔多少秒数来显示一次内存使用情况。</span><br> -t:显示内存总和列。
<br> -o:不显示缓冲区调节列。
</p>
<p> </p>
<p> free命令是用来查看内存使用情况的主要命令。和top命令相比,它的优点是使用简单,并且只占用很少的系统资源。</p>
<p> 通过-s参数可以使用free命令不间断地监视有多少内存在使用,这样可以把它当作一个方便实时监控器。</p>
<p> </p>
<p style="text-align:right"><来自互联网></p>
<p style="text-align:right"> </p>
</div>
</div>
<div class="blog">
<h2><a href="#top" class="top">回到顶部</a><a name="blog_683396" href="http://my.oschina.net/yokoboy/blog/683396" target="_blank" rel="noopener">MySQL——基础入门</a></h2>
<div class="outline">
<div class="date">时间:2016-05-28 18:51:07</div>
<div class="catalog">分类:日常记录</div>
</div>
<div class="content">
<p> </p>
<p><strong><span style="font-size:16px">1. 进入mysql</span></strong></p>
<p><strong> mysql -u root -p</strong></p>
<p> 然后就会提示输入密码,密码正确之后既可以进入。</p>
<p> </p>
<p><strong><span style="font-size:16px">2. 退出编辑</span></strong></p>
<p><span style="font-size:14px"> 进入Mysql编辑的时候会出现这种情况。</span></p>
<p><span style="font-size:14px"> </span></p>
<p><span style="font-size:14px"> 这时候按 \c就能退出编辑</span></p>
<p><span style="font-size:14px"> </span></p>
<p> </p>
<p><span style="font-size:16px"><strong>3. 退出MySQL</strong></span></p>
<p><span style="font-size:14px"> Ctrl + C 或者 quit 或者 exit</span></p>
<p> </p>
<p><span style="font-size:16px"><strong>4. 进入MySQL响应的数据库并管理</strong></span></p>
<p> 进入MySQL之后,<strong> use person;</strong> 进入person数据库</p>
<p> <strong>show tables;</strong> 显示所有表</p>
<p> 然后就可以使用SQL语句查询更新删除了。</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
</div>
<div class="blog">
<h2><a href="#top" class="top">回到顶部</a><a name="blog_683395" href="http://my.oschina.net/yokoboy/blog/683395" target="_blank" rel="noopener">js中的逻辑运算符</a></h2>
<div class="outline">
<div class="date">时间:2016-05-28 18:51:07</div>
<div class="catalog">分类:日常记录</div>
</div>
<div class="content">
<p> </p>
<pre>
<code> $(<span style="color:#0000ff">function</span><span style="color:#000000">() { </span><span style="color:#0000ff">if</span> (""<span style="color:#000000">) { console.info(</span>" \"\" true"<span style="color:#000000">); } </span><span style="color:#0000ff">else</span><span style="color:#000000"> { console.info(</span>" \"\" false"<span style="color:#000000">); } </span><span style="color:#0000ff">if</span> (0<span style="color:#000000">) { console.info(</span>" 0 true"<span style="color:#000000">); } </span><span style="color:#0000ff">else</span><span style="color:#000000"> { console.info(</span>" 0 false"<span style="color:#000000">); } </span><span style="color:#0000ff">if</span><span style="color:#000000"> (undefined) { console.info(</span>" undefined true"<span style="color:#000000">); } </span><span style="color:#0000ff">else</span><span style="color:#000000"> { console.info(</span>" undefined false"<span style="color:#000000">); } </span><span style="color:#008000">//</span><span style="color:#008000"> if (a) {//ReferenceError: aa is not defined</span>
<span style="color:#0000ff">if</span> ("a"<span style="color:#000000">) { console.info(</span>" a true"<span style="color:#000000">); } </span><span style="color:#0000ff">else</span><span style="color:#000000"> { console.info(</span>" a false"<span style="color:#000000">); } </span><span style="color:#0000ff">if</span> (<span style="color:#0000ff">null</span><span style="color:#000000">) { console.info(</span>" null true"<span style="color:#000000">); } </span><span style="color:#0000ff">else</span><span style="color:#000000"> { console.info(</span>" null false"<span style="color:#000000">); } console.info(</span>"time" || <span style="color:#0000ff">null</span><span style="color:#000000">); </span><span style="color:#008000">//</span><span style="color:#008000">time</span>
console.info("" || <span style="color:#0000ff">null</span><span style="color:#000000">); </span><span style="color:#008000">//</span><span style="color:#008000">null</span>
console.info(<span style="color:#0000ff">null</span> || ""<span style="color:#000000">); </span><span style="color:#008000">//</span><span style="color:#008000">空字符串</span>
<span style="color:#0000ff">var</span><span style="color:#000000"> a; console.info(a); </span><span style="color:#008000">//</span><span style="color:#008000">undefined</span>
a = a ||<span style="color:#000000"> []; console.info(a); </span><span style="color:#008000">//</span><span style="color:#008000">[]</span>
<span style="color:#008000">/*</span><span style="color:#008000">* * * undefined的含义其实是定义了一个引用,但是引用没有之上任何变量 * 例如:var a; a的含义就是undefined、 * * 但是如果你直接使用 aa, 没有 var aa; 那么浏览器会直接报错 * 火狐报的错是 ReferenceError: aa is not defined * 也就是说if(aa){} 或者 aa = aa || []; 浏览器都会报错(引用错误) * * 但是,aa="string"; 这种使用方法是没有错误的! * </span><span style="color:#008000">*/</span>
<span style="color:#008000">//</span><span style="color:#008000">aa = "string";console.info(aa);-->string</span>
<span style="color:#000000"> console.info(aa); </span><span style="color:#008000">//</span><span style="color:#008000">ReferenceError: aa is not defined</span>
});</code></pre>
<p>上面代码在火狐上产生的效果如下图:</p>
<p> </p>
<p> </p>
<p>总结下来就是:</p>
<p><span style="color:#ff0000"><strong>在js 中, 空字符串、null、undefined、0 都代表false。</strong></span></p>
<p>在学习C++的时候,我们知道,逻辑运算符有“截断”(忘了叫什么名字了)的特性:或运算符|| 当第一次遇见true的时候,就不在往下面执行了!</p>
<p>那么在js中也只这样的。</p>
<pre>
<code><span style="color:#000000"> console.info(</span>"time" || <span style="color:#0000ff">null</span><span style="color:#000000">);<span style="color:#008000">//</span><span style="color:#008000">time time代表true,后面就不执行了,返回time</span> </span>console.info("" || <span style="color:#0000ff">null</span><span style="color:#000000">);<span style="color:#008000">//</span><span style="color:#008000">null "" 代表false,继续执行,返回null</span> </span>console.info(<span style="color:#0000ff">null</span> || ""<span style="color:#000000">);<span style="color:#008000">//</span><span style="color:#008000">空字符串 null <span style="color:#000000"><span style="color:#008000">代表false,<span style="color:#000000"><span style="color:#008000">继续</span></span>执行,返回""</span></span></span>
</span></code></pre>
<pre>
<code>a = a ||<span style="color:#000000"> [];
那么这句话的意思就是 如果a未定义就创建一个数组对象!
</span></code></pre>
<p> </p>
<p> </p>
</div>
</div>
<div class="blog">
<h2><a href="#top" class="top">回到顶部</a><a name="blog_683394" href="http://my.oschina.net/yokoboy/blog/683394" target="_blank" rel="noopener">Java加载资源文件时的路径问题</a></h2>
<div class="outline">
<div class="date">时间:2016-05-28 18:51:07</div>
<div class="catalog">分类:日常记录</div>
</div>
<div class="content">
<p> </p>
<p>文件目录结构如下:</p>
<p>|--book.xml</p>
<p>|--src</p>
<p> |--book1.xml</p>
<p> |--com</p>
<p> |--yokoboy </p>
<p> |--Test.java</p>
<p> |--book2.xml</p>
<p> </p>
<p><strong><span style="font-size:18pt">方法一、 使用ClassLoader找到book1.xml和book2.xml</span></strong></p>
<pre>
<code class="language-java">System.out.println(ClassLoader.getSystemClassLoader().getResource("book1.xml"));
System.out.println(ClassLoader.getSystemClassLoader().getResource("com/yokoboy/book2.xml"));
System.out.println(ClassLoader.getSystemClassLoader().getResource("/"));//返回null</code></pre>
<p> </p>
<p>注意:ClassLoader默认行根目录开始,前面不能加 '/' ,如果里面给的是空字符串,则返回硬盘上bin目录的绝对路径。</p>
<p> </p>
<p><strong><span style="font-size:18pt">方法二、 使用(类名.class)找到book1.xml和book2.xml</span></strong></p>
<pre>
<code class="language-java">System.out.println(Test.class.getResource("/"));//bin目录绝对路径
System.out.println(Test.class.getResource("/book1.xml"));
System.out.println(Test.class.getResource("http://www.cnblogs.com/book1.xml"));
System.out.println(Test.class.getResource("/com/yokoboy/book2.xml"));
System.out.println(Test.class.getResource("book2.xml"));
System.out.println(Test.class.getResource(""));//com.yokoboy包的绝对路径
System.out.println(Test.class.getResource("http://www.cnblogs.com/../book.xml"));//超出bin(src)范围了,返回null</code></pre>
<p>说明: Test.class.getResource 会相对于Test.class文件寻找,'/' 代表项目根目录,什么也不写代表当前目录。</p>
<p> </p>
<p> </p>
</div>
</div>
<div class="blog">
<h2><a href="#top" class="top">回到顶部</a><a name="blog_683393" href="http://my.oschina.net/yokoboy/blog/683393" target="_blank" rel="noopener">JDK 1.5 新特性——枚举</a></h2>
<div class="outline">
<div class="date">时间:2016-05-28 18:51:07</div>
<div class="catalog">分类:日常记录</div>
</div>
<div class="content">
<pre>
<code><span style="color:#008080"> 1</span> <span style="color:#0000ff">class</span><span style="color:#000000"> MyEnum { </span><span style="color:#008080"> 2</span>
<span style="color:#008080"> 3</span> <span style="color:#0000ff">private</span><span style="color:#000000"> MyEnum() { </span><span style="color:#008080"> 4</span> <span style="color:#000000"> } </span><span style="color:#008080"> 5</span>
<span style="color:#008080"> 6</span> <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">final</span> MyEnum e1 = <span style="color:#0000ff">new</span><span style="color:#000000"> MyEnum(); </span><span style="color:#008080"> 7</span> <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">final</span> MyEnum e2 = <span style="color:#0000ff">new</span><span style="color:#000000"> MyEnum(); </span><span style="color:#008080"> 8</span> <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">final</span> MyEnum e3 = <span style="color:#0000ff">new</span><span style="color:#000000"> MyEnum(); </span><span style="color:#008080"> 9</span> <span style="color:#000000">} </span><span style="color:#008080">10</span>
<span style="color:#008080">11</span> <span style="color:#0000ff">public</span> <span style="color:#0000ff">class</span><span style="color:#000000"> LikeEnum { </span><span style="color:#008080">12</span>
<span style="color:#008080">13</span> <span style="color:#0000ff">public</span> <span style="color:#0000ff">static</span> <span style="color:#0000ff">void</span><span style="color:#000000"> main(String[] args) { </span><span style="color:#008080">14</span> <span style="color:#008000">//</span><span style="color:#008000"> MyEnum myEnum=new MyEnum();</span><span style="color:#008000">//</span><span style="color:#008000">报错 ,不能创建对象</span>
<span style="color:#008080">15</span> System.out.println(MyEnum.e1);<span style="color:#008000">//</span><span style="color:#008000">不能从外部创建对象,只能使用内部已经常见的对象这就是枚举的原型,提高了程序的安全性</span>
<span style="color:#008080">16</span> <span style="color:#000000"> } </span><span style="color:#008080">17</span> }</code></pre>