log4r 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (319) hide show
  1. data/README +2 -2
  2. data/Rakefile +3 -3
  3. data/TODO +0 -34
  4. data/examples/filelog.rb +25 -0
  5. data/examples/logs/TestSize000001.log +576 -0
  6. data/examples/logs/TestSize000002.log +567 -0
  7. data/examples/logs/TestSize000003.log +552 -0
  8. data/examples/logs/TestSize000004.log +552 -0
  9. data/examples/logs/TestSize000005.log +552 -0
  10. data/examples/logs/TestSize000006.log +552 -0
  11. data/examples/logs/TestSize000007.log +552 -0
  12. data/examples/logs/TestSize000008.log +552 -0
  13. data/examples/logs/TestSize000009.log +552 -0
  14. data/examples/logs/TestSize000010.log +552 -0
  15. data/examples/logs/TestSize000011.log +552 -0
  16. data/examples/logs/TestSize000012.log +552 -0
  17. data/examples/logs/TestSize000013.log +552 -0
  18. data/examples/logs/TestSize000014.log +552 -0
  19. data/examples/logs/TestSize000015.log +552 -0
  20. data/examples/logs/TestSize000016.log +552 -0
  21. data/examples/logs/TestSize000017.log +552 -0
  22. data/examples/logs/TestSize000018.log +552 -0
  23. data/examples/logs/TestSize000019.log +535 -0
  24. data/examples/logs/TestSize000020.log +534 -0
  25. data/examples/logs/TestSize000021.log +534 -0
  26. data/examples/logs/TestSize000022.log +534 -0
  27. data/examples/logs/TestSize000023.log +534 -0
  28. data/examples/logs/TestSize000024.log +534 -0
  29. data/examples/logs/TestSize000025.log +534 -0
  30. data/examples/logs/TestSize000026.log +534 -0
  31. data/examples/logs/TestSize000027.log +534 -0
  32. data/examples/logs/TestSize000028.log +534 -0
  33. data/examples/logs/TestSize000029.log +534 -0
  34. data/examples/logs/TestSize000030.log +534 -0
  35. data/examples/logs/TestSize000031.log +534 -0
  36. data/examples/logs/TestSize000032.log +534 -0
  37. data/examples/logs/TestSize000033.log +534 -0
  38. data/examples/logs/TestSize000034.log +534 -0
  39. data/examples/logs/TestSize000035.log +534 -0
  40. data/examples/logs/TestSize000036.log +534 -0
  41. data/examples/logs/TestSize000037.log +534 -0
  42. data/examples/logs/TestSize000038.log +534 -0
  43. data/examples/logs/TestSize000039.log +534 -0
  44. data/examples/logs/TestSize000040.log +534 -0
  45. data/examples/logs/TestSize000041.log +534 -0
  46. data/examples/logs/TestSize000042.log +534 -0
  47. data/examples/logs/TestSize000043.log +534 -0
  48. data/examples/logs/TestSize000044.log +534 -0
  49. data/examples/logs/TestSize000045.log +534 -0
  50. data/examples/logs/TestSize000046.log +534 -0
  51. data/examples/logs/TestSize000047.log +534 -0
  52. data/examples/logs/TestSize000048.log +534 -0
  53. data/examples/logs/TestSize000049.log +534 -0
  54. data/examples/logs/TestSize000050.log +534 -0
  55. data/examples/logs/TestSize000051.log +534 -0
  56. data/examples/logs/TestSize000052.log +534 -0
  57. data/examples/logs/TestSize000053.log +534 -0
  58. data/examples/logs/TestSize000054.log +534 -0
  59. data/examples/logs/TestSize000055.log +534 -0
  60. data/examples/logs/TestSize000056.log +534 -0
  61. data/examples/logs/TestSize000057.log +534 -0
  62. data/examples/logs/TestSize000058.log +534 -0
  63. data/examples/logs/TestSize000059.log +534 -0
  64. data/examples/logs/TestSize000060.log +534 -0
  65. data/examples/logs/TestSize000061.log +534 -0
  66. data/examples/logs/TestSize000062.log +534 -0
  67. data/examples/logs/TestSize000063.log +534 -0
  68. data/examples/logs/TestSize000064.log +534 -0
  69. data/examples/logs/TestSize000065.log +534 -0
  70. data/examples/logs/TestSize000066.log +534 -0
  71. data/examples/logs/TestSize000067.log +534 -0
  72. data/examples/logs/TestSize000068.log +534 -0
  73. data/examples/logs/TestSize000069.log +534 -0
  74. data/examples/logs/TestSize000070.log +534 -0
  75. data/examples/logs/TestSize000071.log +534 -0
  76. data/examples/logs/TestSize000072.log +534 -0
  77. data/examples/logs/TestSize000073.log +534 -0
  78. data/examples/logs/TestSize000074.log +534 -0
  79. data/examples/logs/TestSize000075.log +534 -0
  80. data/examples/logs/TestSize000076.log +534 -0
  81. data/examples/logs/TestSize000077.log +534 -0
  82. data/examples/logs/TestSize000078.log +534 -0
  83. data/examples/logs/TestSize000079.log +534 -0
  84. data/examples/logs/TestSize000080.log +534 -0
  85. data/examples/logs/TestSize000081.log +534 -0
  86. data/examples/logs/TestSize000082.log +534 -0
  87. data/examples/logs/TestSize000083.log +534 -0
  88. data/examples/logs/TestSize000084.log +534 -0
  89. data/examples/logs/TestSize000085.log +534 -0
  90. data/examples/logs/TestSize000086.log +534 -0
  91. data/examples/logs/TestSize000087.log +534 -0
  92. data/examples/logs/TestSize000088.log +534 -0
  93. data/examples/logs/TestSize000089.log +534 -0
  94. data/examples/logs/TestSize000090.log +534 -0
  95. data/examples/logs/TestSize000091.log +534 -0
  96. data/examples/logs/TestSize000092.log +534 -0
  97. data/examples/logs/TestSize000093.log +534 -0
  98. data/examples/logs/TestSize000094.log +534 -0
  99. data/examples/logs/TestSize000095.log +534 -0
  100. data/examples/logs/TestSize000096.log +534 -0
  101. data/examples/logs/TestSize000097.log +534 -0
  102. data/examples/logs/TestSize000098.log +534 -0
  103. data/examples/logs/TestSize000099.log +534 -0
  104. data/examples/logs/TestSize000100.log +534 -0
  105. data/examples/logs/TestSize000101.log +534 -0
  106. data/examples/logs/TestSize000102.log +534 -0
  107. data/examples/logs/TestSize000103.log +534 -0
  108. data/examples/logs/TestSize000104.log +534 -0
  109. data/examples/logs/TestSize000105.log +534 -0
  110. data/examples/logs/TestSize000106.log +534 -0
  111. data/examples/logs/TestSize000107.log +534 -0
  112. data/examples/logs/TestSize000108.log +534 -0
  113. data/examples/logs/TestSize000109.log +534 -0
  114. data/examples/logs/TestSize000110.log +534 -0
  115. data/examples/logs/TestSize000111.log +534 -0
  116. data/examples/logs/TestSize000112.log +534 -0
  117. data/examples/logs/TestSize000113.log +534 -0
  118. data/examples/logs/TestSize000114.log +534 -0
  119. data/examples/logs/TestSize000115.log +534 -0
  120. data/examples/logs/TestSize000116.log +534 -0
  121. data/examples/logs/TestSize000117.log +534 -0
  122. data/examples/logs/TestSize000118.log +534 -0
  123. data/examples/logs/TestSize000119.log +534 -0
  124. data/examples/logs/TestSize000120.log +534 -0
  125. data/examples/logs/TestSize000121.log +534 -0
  126. data/examples/logs/TestSize000122.log +534 -0
  127. data/examples/logs/TestSize000123.log +534 -0
  128. data/examples/logs/TestSize000124.log +534 -0
  129. data/examples/logs/TestSize000125.log +534 -0
  130. data/examples/logs/TestSize000126.log +534 -0
  131. data/examples/logs/TestSize000127.log +534 -0
  132. data/examples/logs/TestSize000128.log +534 -0
  133. data/examples/logs/TestSize000129.log +534 -0
  134. data/examples/logs/TestSize000130.log +534 -0
  135. data/examples/logs/TestSize000131.log +534 -0
  136. data/examples/logs/TestSize000132.log +534 -0
  137. data/examples/logs/TestSize000133.log +534 -0
  138. data/examples/logs/TestSize000134.log +534 -0
  139. data/examples/logs/TestSize000135.log +534 -0
  140. data/examples/logs/TestSize000136.log +534 -0
  141. data/examples/logs/TestSize000137.log +534 -0
  142. data/examples/logs/TestSize000138.log +534 -0
  143. data/examples/logs/TestSize000139.log +534 -0
  144. data/examples/logs/TestSize000140.log +534 -0
  145. data/examples/logs/TestSize000141.log +534 -0
  146. data/examples/logs/TestSize000142.log +534 -0
  147. data/examples/logs/TestSize000143.log +534 -0
  148. data/examples/logs/TestSize000144.log +534 -0
  149. data/examples/logs/TestSize000145.log +534 -0
  150. data/examples/logs/TestSize000146.log +534 -0
  151. data/examples/logs/TestSize000147.log +534 -0
  152. data/examples/logs/TestSize000148.log +534 -0
  153. data/examples/logs/TestSize000149.log +534 -0
  154. data/examples/logs/TestSize000150.log +534 -0
  155. data/examples/logs/TestSize000151.log +534 -0
  156. data/examples/logs/TestSize000152.log +534 -0
  157. data/examples/logs/TestSize000153.log +534 -0
  158. data/examples/logs/TestSize000154.log +534 -0
  159. data/examples/logs/TestSize000155.log +534 -0
  160. data/examples/logs/TestSize000156.log +534 -0
  161. data/examples/logs/TestSize000157.log +534 -0
  162. data/examples/logs/TestSize000158.log +534 -0
  163. data/examples/logs/TestSize000159.log +534 -0
  164. data/examples/logs/TestSize000160.log +534 -0
  165. data/examples/logs/TestSize000161.log +534 -0
  166. data/examples/logs/TestSize000162.log +534 -0
  167. data/examples/logs/TestSize000163.log +534 -0
  168. data/examples/logs/TestSize000164.log +534 -0
  169. data/examples/logs/TestSize000165.log +534 -0
  170. data/examples/logs/TestSize000166.log +534 -0
  171. data/examples/logs/TestSize000167.log +534 -0
  172. data/examples/logs/TestSize000168.log +534 -0
  173. data/examples/logs/TestSize000169.log +534 -0
  174. data/examples/logs/TestSize000170.log +534 -0
  175. data/examples/logs/TestSize000171.log +534 -0
  176. data/examples/logs/TestSize000172.log +534 -0
  177. data/examples/logs/TestSize000173.log +534 -0
  178. data/examples/logs/TestSize000174.log +534 -0
  179. data/examples/logs/TestSize000175.log +534 -0
  180. data/examples/logs/TestSize000176.log +534 -0
  181. data/examples/logs/TestSize000177.log +534 -0
  182. data/examples/logs/TestSize000178.log +534 -0
  183. data/examples/logs/TestSize000179.log +534 -0
  184. data/examples/logs/TestSize000180.log +534 -0
  185. data/examples/logs/TestSize000181.log +534 -0
  186. data/examples/logs/TestSize000182.log +534 -0
  187. data/examples/logs/TestSize000183.log +534 -0
  188. data/examples/logs/TestSize000184.log +534 -0
  189. data/examples/logs/TestSize000185.log +534 -0
  190. data/examples/logs/TestSize000186.log +534 -0
  191. data/examples/logs/TestSize000187.log +312 -0
  192. data/examples/logs/TestTime000001.log +11 -0
  193. data/examples/logs/TestTime000002.log +10 -0
  194. data/examples/logs/TestTime000003.log +10 -0
  195. data/examples/logs/TestTime000004.log +10 -0
  196. data/examples/logs/TestTime000005.log +10 -0
  197. data/examples/logs/TestTime000006.log +10 -0
  198. data/examples/logs/TestTime000007.log +10 -0
  199. data/examples/logs/TestTime000008.log +10 -0
  200. data/examples/logs/TestTime000009.log +10 -0
  201. data/examples/logs/TestTime000010.log +9 -0
  202. data/src/log4r.rb +5 -2
  203. data/src/log4r/GDC.rb +40 -0
  204. data/src/log4r/MDC.rb +59 -0
  205. data/src/log4r/NDC.rb +87 -0
  206. data/src/log4r/formatter/patternformatter.rb +11 -6
  207. data/src/log4r/outputter/bob.patch +25 -0
  208. data/src/log4r/outputter/emailoutputter.rb.orig +118 -0
  209. data/src/log4r/outputter/emailoutputter.rb.rej +46 -0
  210. data/src/log4r/outputter/fileoutputter.rb +12 -5
  211. data/src/log4r/outputter/rollingfileoutputter.rb +8 -3
  212. data/src/log4r/outputter/win32eventoutputter.rb +136 -0
  213. data/src/log4r/rdoc/GDC +14 -0
  214. data/src/log4r/rdoc/MDC +16 -0
  215. data/src/log4r/rdoc/NDC +41 -0
  216. data/src/log4r/rdoc/win32eventoutputter +7 -0
  217. data/src/log4r/repository.rb +73 -52
  218. data/src/log4r/yamlconfigurator.rb +0 -0
  219. data/tests/testGDC.rb +26 -0
  220. data/tests/testMDC.rb +21 -0
  221. data/tests/testNDC.rb +27 -0
  222. data/tests/testthreads.rb +23 -0
  223. metadata +215 -98
  224. data/src/doc/Log4r.html +0 -392
  225. data/src/doc/Log4r/BasicFormatter.html +0 -370
  226. data/src/doc/Log4r/ConfigError.html +0 -207
  227. data/src/doc/Log4r/Configurator.html +0 -1050
  228. data/src/doc/Log4r/DateFileOutputter.html +0 -454
  229. data/src/doc/Log4r/DefaultFormatter.html +0 -205
  230. data/src/doc/Log4r/EmailOutputter.html +0 -636
  231. data/src/doc/Log4r/FileOutputter.html +0 -321
  232. data/src/doc/Log4r/Formatter.html +0 -291
  233. data/src/doc/Log4r/IOOutputter.html +0 -392
  234. data/src/doc/Log4r/Log4rConfig.html +0 -193
  235. data/src/doc/Log4r/Log4rTools.html +0 -370
  236. data/src/doc/Log4r/LogEvent.html +0 -360
  237. data/src/doc/Log4r/LogServer.html +0 -322
  238. data/src/doc/Log4r/Logger.html +0 -1132
  239. data/src/doc/Log4r/Logger/LoggerFactory.html +0 -200
  240. data/src/doc/Log4r/Logger/Repository.html +0 -207
  241. data/src/doc/Log4r/ObjectFormatter.html +0 -262
  242. data/src/doc/Log4r/Outputter.html +0 -910
  243. data/src/doc/Log4r/Outputter/OutputterFactory.html +0 -200
  244. data/src/doc/Log4r/Outputter/consoleoutputters_rb.html +0 -57
  245. data/src/doc/Log4r/Outputter/datefileoutputter_rb.html +0 -93
  246. data/src/doc/Log4r/Outputter/emailoutputter_rb.html +0 -179
  247. data/src/doc/Log4r/Outputter/fileoutputter_rb.html +0 -64
  248. data/src/doc/Log4r/Outputter/iooutputter_rb.html +0 -59
  249. data/src/doc/Log4r/Outputter/outputter_rb.html +0 -222
  250. data/src/doc/Log4r/Outputter/outputterfactory_rb.html +0 -62
  251. data/src/doc/Log4r/Outputter/remoteoutputter_rb.html +0 -59
  252. data/src/doc/Log4r/Outputter/rollingfileoutputter_rb.html +0 -66
  253. data/src/doc/Log4r/Outputter/staticoutputter_rb.html +0 -55
  254. data/src/doc/Log4r/Outputter/syslogoutputter_rb.html +0 -110
  255. data/src/doc/Log4r/Outputter/tst_rb.html +0 -54
  256. data/src/doc/Log4r/PatternFormatter.html +0 -422
  257. data/src/doc/Log4r/ROMPClient.html +0 -193
  258. data/src/doc/Log4r/ROMPServer.html +0 -193
  259. data/src/doc/Log4r/RemoteOutputter.html +0 -384
  260. data/src/doc/Log4r/RollingFileOutputter.html +0 -528
  261. data/src/doc/Log4r/RootLogger.html +0 -512
  262. data/src/doc/Log4r/SimpleFormatter.html +0 -258
  263. data/src/doc/Log4r/StderrOutputter.html +0 -250
  264. data/src/doc/Log4r/StdoutOutputter.html +0 -250
  265. data/src/doc/Log4r/SyslogOutputter.html +0 -533
  266. data/src/doc/Log4r/YamlConfigurator.html +0 -948
  267. data/src/doc/Log4r/base_rb.html +0 -57
  268. data/src/doc/Log4r/config_rb.html +0 -76
  269. data/src/doc/Log4r/configurator_rb.html +0 -370
  270. data/src/doc/Log4r/formatter/formatter_rb.html +0 -121
  271. data/src/doc/Log4r/formatter/patternformatter_rb.html +0 -233
  272. data/src/doc/Log4r/lib/drbloader_rb.html +0 -57
  273. data/src/doc/Log4r/lib/xmlloader_rb.html +0 -57
  274. data/src/doc/Log4r/logevent_rb.html +0 -55
  275. data/src/doc/Log4r/logger_rb.html +0 -293
  276. data/src/doc/Log4r/loggerfactory_rb.html +0 -66
  277. data/src/doc/Log4r/logserver_rb.html +0 -161
  278. data/src/doc/Log4r/rdoc/configurator.html +0 -444
  279. data/src/doc/Log4r/rdoc/emailoutputter.html +0 -261
  280. data/src/doc/Log4r/rdoc/formatter.html +0 -200
  281. data/src/doc/Log4r/rdoc/log4r.html +0 -268
  282. data/src/doc/Log4r/rdoc/logger.html +0 -364
  283. data/src/doc/Log4r/rdoc/logserver.html +0 -247
  284. data/src/doc/Log4r/rdoc/outputter.html +0 -295
  285. data/src/doc/Log4r/rdoc/patternformatter.html +0 -313
  286. data/src/doc/Log4r/rdoc/syslogoutputter.html +0 -179
  287. data/src/doc/Log4r/rdoc/yamlconfigurator.html +0 -169
  288. data/src/doc/Log4r/repository_rb.html +0 -62
  289. data/src/doc/Log4r/staticlogger_rb.html +0 -55
  290. data/src/doc/Log4r/yamlconfigurator_rb.html +0 -95
  291. data/src/doc/REXML.html +0 -193
  292. data/src/doc/created.rid +0 -1
  293. data/src/doc/images/brick.png +0 -0
  294. data/src/doc/images/brick_link.png +0 -0
  295. data/src/doc/images/bug.png +0 -0
  296. data/src/doc/images/bullet_black.png +0 -0
  297. data/src/doc/images/bullet_toggle_minus.png +0 -0
  298. data/src/doc/images/bullet_toggle_plus.png +0 -0
  299. data/src/doc/images/date.png +0 -0
  300. data/src/doc/images/find.png +0 -0
  301. data/src/doc/images/loadingAnimation.gif +0 -0
  302. data/src/doc/images/macFFBgHack.png +0 -0
  303. data/src/doc/images/package.png +0 -0
  304. data/src/doc/images/page_green.png +0 -0
  305. data/src/doc/images/page_white_text.png +0 -0
  306. data/src/doc/images/page_white_width.png +0 -0
  307. data/src/doc/images/plugin.png +0 -0
  308. data/src/doc/images/ruby.png +0 -0
  309. data/src/doc/images/tag_green.png +0 -0
  310. data/src/doc/images/wrench.png +0 -0
  311. data/src/doc/images/wrench_orange.png +0 -0
  312. data/src/doc/images/zoom.png +0 -0
  313. data/src/doc/index.html +0 -384
  314. data/src/doc/js/darkfish.js +0 -116
  315. data/src/doc/js/jquery.js +0 -32
  316. data/src/doc/js/quicksearch.js +0 -114
  317. data/src/doc/js/thickbox-compressed.js +0 -10
  318. data/src/doc/rdoc.css +0 -696
  319. data/src/log4r/outputter/tst.rb +0 -8
data/src/log4r/GDC.rb ADDED
@@ -0,0 +1,40 @@
1
+ # :include: rdoc/GDC
2
+ #
3
+ # == Other Info
4
+ #
5
+ # Version:: $Id: GDC.rb,v 1.1 2010/01/12 02:53:43 colbygk Exp $
6
+ # Author:: Colby Gutierrez-Kraybill <colby(at)astro.berkeley.edu>
7
+
8
+ module Log4r
9
+ GDCNAME = "log4rGDC"
10
+
11
+ # See log4r/GDC.rb
12
+ class GDC
13
+ private_class_method :new
14
+
15
+ def self.check_thread_instance()
16
+ if ( Thread.main != Thread.current ):
17
+ raise "Can only initialize Global Diagnostic Context from Thread.main"
18
+ else
19
+ if ( Thread.main[GDCNAME] == nil ):
20
+ Thread.main[GDCNAME] = $0
21
+ end
22
+ end
23
+ end
24
+
25
+ def self.clear()
26
+ check_thread_instance()
27
+ end
28
+
29
+ def self.get()
30
+ check_thread_instance()
31
+ return Thread.main[GDCNAME]
32
+ end
33
+
34
+ def self.set( a_name )
35
+ check_thread_instance()
36
+ Thread.main[GDCNAME] = a_name
37
+ end
38
+ end
39
+ end
40
+
data/src/log4r/MDC.rb ADDED
@@ -0,0 +1,59 @@
1
+ # :include: rdoc/MDC
2
+ #
3
+ # == Other Info
4
+ #
5
+ # Version:: $Id: MDC.rb,v 1.1 2010/01/12 02:21:29 colbygk Exp $
6
+ # Author:: Colby Gutierrez-Kraybill <colby(at)astro.berkeley.edu>
7
+
8
+ require 'monitor'
9
+
10
+ module Log4r
11
+ MDCNAME = "log4rMDC"
12
+ MDCNAMEMAXDEPTH = "log4rMDCMAXDEPTH"
13
+ $globalMDCLock = Monitor.new
14
+
15
+ # See log4r/MDC.rb
16
+ class MDC < Monitor
17
+ private_class_method :new
18
+
19
+ def self.check_thread_instance()
20
+ # need to interlock here, so that if
21
+ # another thread is entering this section
22
+ # of code before the main thread does,
23
+ # then the main thread copy of the MDC
24
+ # is setup before then attempting to clone
25
+ # it off
26
+ if ( Thread.current[MDCNAME] == nil ) then
27
+ $globalMDCLock.synchronize do
28
+ if ( Thread.main[MDCNAME] == nil ) then
29
+ Thread.main[MDCNAME] = Hash.new
30
+ end
31
+ if ( Thread.current != Thread.main ) then
32
+ Thread.current[MDCNAME] = Hash.new
33
+ Thread.main[MDCNAME].each{ |k,v| Thread.current[MDCNAME][k] = v }
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ def self.get( a_key )
40
+ self.check_thread_instance()
41
+ Thread.current[MDCNAME].fetch(a_key, "");
42
+ end
43
+
44
+ def self.get_context()
45
+ self.check_thread_instance()
46
+ return Thread.current[MDCNAME].clone
47
+ end
48
+
49
+ def self.put( a_key, a_value )
50
+ self.check_thread_instance()
51
+ Thread.current[MDCNAME][a_key] = a_value
52
+ end
53
+
54
+ def self.remove( a_key )
55
+ self.check_thread_instance()
56
+ Thread.current[MDCNAME].delete( a_key )
57
+ end
58
+ end
59
+ end
data/src/log4r/NDC.rb ADDED
@@ -0,0 +1,87 @@
1
+ # :include: rdoc/NDC
2
+ #
3
+ # == Other Info
4
+ #
5
+ # Version:: $Id: NDC.rb,v 1.1 2010/01/12 02:21:29 colbygk Exp $
6
+ # Author:: Colby Gutierrez-Kraybill <colby(at)astro.berkeley.edu>
7
+
8
+ module Log4r
9
+ NDCNAME = "log4rNDC"
10
+ NDCNAMEMAXDEPTH = "log4rNDCMAXDEPTH"
11
+ NDCDEFAULTMAXDEPTH = 100
12
+
13
+ # See log4r/NDC.rb
14
+ class NDC
15
+ private_class_method :new
16
+
17
+ def self.check_thread_instance()
18
+ if ( Thread.current[NDCNAME] == nil ):
19
+ Thread.current[NDCNAME] = Array.new
20
+ Thread.current[NDCNAMEMAXDEPTH] = NDCDEFAULTMAXDEPTH
21
+ Thread.current[NDCNAME]
22
+ end
23
+ end
24
+
25
+ def self.clear()
26
+ self.check_thread_instance()
27
+ Thread.current[NDCNAME].clear
28
+ end
29
+
30
+ def self.clone_stack()
31
+ self.check_thread_instance()
32
+ return Thread.current[NDCNAME].clone
33
+ end
34
+
35
+ def self.get_depth()
36
+ self.check_thread_instance()
37
+ return Thread.current[NDCNAME].length
38
+ end
39
+
40
+ def self.inherit( a_stack )
41
+ if ( a_stack.class == Array ) then
42
+ if ( Thread.current[NDCNAME] != nil ) then
43
+ Thread.current[NDCNAME].clear
44
+ Thread.current[NDCNAME] = nil
45
+ end
46
+ Thread.current[NDCNAME] = a_stack
47
+ else
48
+ raise "Expecting Array in NDC.inherit"
49
+ end
50
+ end
51
+
52
+ def self.get()
53
+ self.check_thread_instance
54
+ return Thread.current[NDCNAME] * " "
55
+ end
56
+
57
+ def self.peek()
58
+ self.check_thread_instance()
59
+ return Thread.current[NDCNAME].last
60
+ end
61
+
62
+ def self.pop()
63
+ self.check_thread_instance()
64
+ return Thread.current[NDCNAME].pop
65
+ end
66
+
67
+ def self.push( value )
68
+ self.check_thread_instance()
69
+ if ( Thread.current[NDCNAME].length < Thread.current[NDCNAMEMAXDEPTH] ):
70
+ Thread.current[NDCNAME].push( value )
71
+ end
72
+ end
73
+
74
+ def self.remove()
75
+ self.check_thread_instance()
76
+ Thread.current[NDCNAME].clear
77
+ Thread.current[NDCNAMEMAXDEPTH] = nil
78
+ Thread.current[NDCNAME] = nil
79
+ end
80
+
81
+ def self.set_max_depth( max_depth )
82
+ self.check_thread_instance()
83
+ Thread.current[NDCNAMEMAXDEPTH] = max_depth
84
+ end
85
+ end
86
+ end
87
+
@@ -2,9 +2,12 @@
2
2
  #
3
3
  # == Other Info
4
4
  #
5
- # Version:: $Id: patternformatter.rb,v 1.5 2009/09/25 20:33:33 colbygk Exp $
5
+ # Version:: $Id: patternformatter.rb,v 1.6 2009/10/28 19:55:34 colbygk Exp $
6
6
 
7
7
  require "log4r/formatter/formatter"
8
+ require "log4r/GDC"
9
+ require "log4r/MDC"
10
+ require "log4r/NDC"
8
11
 
9
12
  module Log4r
10
13
  # See log4r/formatter/patternformatter.rb
@@ -14,23 +17,29 @@ module Log4r
14
17
  # %c - event short name
15
18
  # %C - event fullname
16
19
  # %d - date
20
+ # %g - Global Diagnostic Context (GDC)
17
21
  # %t - trace
18
22
  # %m - message
19
23
  # %h - thread name
20
24
  # %p - process ID aka PID
21
25
  # %M - formatted message
22
26
  # %l - Level in string form
27
+ # %x - Nested Diagnostic Context (NDC)
28
+ # %X - Mapped Diagnostic Context (MDC), syntax is "%X.key"
23
29
  # %% - Insert a %
24
30
  DirectiveTable = {
25
31
  "c" => 'event.name',
26
32
  "C" => 'event.fullname',
27
33
  "d" => 'format_date',
34
+ "g" => 'GDC.get()',
28
35
  "t" => '(event.tracer.nil? ? "no trace" : event.tracer[0])',
29
36
  "m" => 'event.data',
30
- "h" => 'thread_name',
37
+ "h" => '(Thread.current[:name] or Thread.current.to_s)',
31
38
  "p" => 'Process.pid.to_s',
32
39
  "M" => 'format_object(event.data)',
33
40
  "l" => 'LNAMES[event.level]',
41
+ "x" => 'NDC.get()',
42
+ "X" => '($4 != "" ? MDC.get($4.to_s)',
34
43
  "%" => '"%"'
35
44
  }
36
45
 
@@ -74,10 +83,6 @@ module Log4r
74
83
  PatternFormatter.create_format_methods(self)
75
84
  end
76
85
 
77
- def thread_name
78
- Thread.current[:name] || Thread.current.to_s
79
- end
80
-
81
86
  # PatternFormatter works by dynamically defining a <tt>format</tt> method
82
87
  # based on the supplied pattern format. This method contains a call to
83
88
  # Kernel#sptrintf with arguments containing the data requested in
@@ -0,0 +1,25 @@
1
+ begin
2
+ 3.times do
3
+ begin
4
+ ### send email
5
+ @smtp.sendmail(rfc822msg, @from, @to)
6
+ break
7
+ rescue Net::SMTPServerBusy => e
8
+ Logger.log_internal(-2) {
9
+ "Try to restart EmailOutputter '#{@name}'! (#{e.message})"
10
+ }
11
+ @smtp = Net::SMTP.start(*@params)
12
+ rescue Exception => e
13
+ Logger.log_internal(-2) {
14
+ "EmailOutputter '#{@name}' couldn't send email! (#{e.message})"
15
+ break
16
+ }
17
+ Logger.log_internal {e}
18
+ self.level = OFF
19
+ end
20
+ end
21
+ ensure
22
+ @buff.clear
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,118 @@
1
+ # :include: ../rdoc/emailoutputter
2
+
3
+ require 'log4r/outputter/outputter'
4
+ require 'log4r/staticlogger'
5
+ require 'net/smtp'
6
+
7
+ module Log4r
8
+
9
+ class EmailOutputter < Outputter
10
+ attr_reader :server, :port, :domain, :acct, :authtype, :subject
11
+
12
+ def initialize(_name, hash={})
13
+ super(_name, hash)
14
+ validate(hash)
15
+ @buff = []
16
+ begin
17
+ Logger.log_internal {
18
+ "EmailOutputter '#{@name}' running SMTP client on #{@server}:#{@port}"
19
+ }
20
+ rescue Exception => e
21
+ Logger.log_internal(-2) {
22
+ "EmailOutputter '#{@name}' failed to start SMTP client!"
23
+ }
24
+ Logger.log_internal {e}
25
+ self.level = OFF
26
+ raise e
27
+ end
28
+ end
29
+
30
+ # send out an email with the current buffer
31
+ def flush
32
+ synch { send_mail }
33
+ Logger.log_internal {"Flushed EmailOutputter '#{@name}'"}
34
+ end
35
+
36
+ private
37
+
38
+ def validate(hash)
39
+ @buffsize = (hash[:buffsize] or hash['buffsize'] or 100).to_i
40
+ @formatfirst = Log4rTools.decode_bool(hash, :formatfirst, false)
41
+ decode_immediate_at(hash)
42
+ validate_smtp_params(hash)
43
+ end
44
+
45
+ def decode_immediate_at(hash)
46
+ @immediate = Hash.new
47
+ _at = (hash[:immediate_at] or hash['immediate_at'])
48
+ return if _at.nil?
49
+ Log4rTools.comma_split(_at).each {|lname|
50
+ level = LNAMES.index(lname)
51
+ if level.nil?
52
+ Logger.log_internal(-2) do
53
+ "EmailOutputter: skipping bad immediate_at level name '#{lname}'"
54
+ end
55
+ next
56
+ end
57
+ @immediate[level] = true
58
+ }
59
+ end
60
+
61
+ def validate_smtp_params(hash)
62
+ @from = (hash[:from] or hash['from'])
63
+ raise ArgumentError, "Must specify from address" if @from.nil?
64
+ _to = (hash[:to] or hash['to'] or "")
65
+ @to = Log4rTools.comma_split(_to)
66
+ raise ArgumentError, "Must specify recepients" if @to.empty?
67
+ @server = (hash[:server] or hash['server'] or 'localhost')
68
+ @port = (hash[:port] or hash['port'] or 25).to_i
69
+ @domain = (hash[:domain] or hash['domain'] or ENV['HOSTNAME'])
70
+ @acct = (hash[:acct] or hash['acct'])
71
+ @passwd = (hash[:passwd] or hash['passwd'])
72
+ @authtype = (hash[:authtype] or hash['authtype'] or :cram_md5).to_s.intern
73
+ @subject = (hash[:subject] or hash['subject'] or "Message of #{$0}")
74
+ @params = [@server, @port, @domain, @acct, @passwd, @authtype]
75
+ end
76
+
77
+ def canonical_log(event)
78
+ synch {
79
+ @buff.push case @formatfirst
80
+ when true then @formatter.format event
81
+ else event
82
+ end
83
+ send_mail if @buff.size >= @buffsize or @immediate[event.level]
84
+ }
85
+ end
86
+
87
+ def send_mail
88
+ msg =
89
+ case @formatfirst
90
+ when true then @buff.join
91
+ else @buff.collect{|e| @formatter.format e}.join
92
+ end
93
+
94
+ ### build a mail header for RFC 822
95
+ rfc822msg =
96
+ "From: #{@from}\n" +
97
+ "To: #{@to}\n" +
98
+ "Subject: #{@subject}\n" +
99
+ "Date: #{Time.now.strftime( "%a, %d %b %Y %H:%M:%S %z %Z")}\n" +
100
+ "Message-Id: <#{"%.8f" % Time.now.to_f}@#{@domain}>\n\n" +
101
+ "#{msg}"
102
+
103
+ ### send email
104
+ begin Net::SMTP.start(*@params) do |smtp|
105
+ smtp.sendmail(rfc822msg, @from, @to)
106
+ end
107
+ rescue Exception => e
108
+ Logger.log_internal(-2) {
109
+ "EmailOutputter '#{@name}' couldn't send email!"
110
+ }
111
+ Logger.log_internal {e}
112
+ self.level = OFF
113
+ raise e
114
+ ensure @buff.clear
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,46 @@
1
+ ***************
2
+ *** 100,114 ****
3
+ "Message-Id: <#{"%.8f" % Time.now.to_f}@#{@domain}>\n\n" +
4
+ "#{msg}"
5
+
6
+ - ### send email
7
+ - begin @smtp.sendmail(rfc822msg, @from, @to)
8
+ - rescue Exception => e
9
+ - Logger.log_internal(-2) {
10
+ - "EmailOutputter '#{@name}' couldn't send email!"
11
+ - }
12
+ - Logger.log_internal {e}
13
+ - self.level = OFF
14
+ - ensure @buff.clear
15
+ end
16
+ end
17
+ end
18
+ --- 100,127 ----
19
+ "Message-Id: <#{"%.8f" % Time.now.to_f}@#{@domain}>\n\n" +
20
+ "#{msg}"
21
+
22
+ + begin
23
+ + 3.times do
24
+ + begin
25
+ + ### send email
26
+ + @smtp.sendmail(rfc822msg, @from, @to)
27
+ + break
28
+ + rescue Net::SMTPServerBusy => e
29
+ + Logger.log_internal(-2) {
30
+ + "Try to restart EmailOutputter '#{@name}'! (#{e.message})"
31
+ + }
32
+ + @smtp = Net::SMTP.start(*@params)
33
+ + rescue Exception => e
34
+ + Logger.log_internal(-2) {
35
+ + "EmailOutputter '#{@name}' couldn't send email! (#{e.message})"
36
+ + break
37
+ + }
38
+ + Logger.log_internal {e}
39
+ + self.level = OFF
40
+ + end
41
+ + end
42
+ + ensure
43
+ + @buff.clear
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  # :nodoc:
2
- # Version:: $Id: fileoutputter.rb,v 1.1.1.1 2004/03/19 03:31:09 fando Exp $
2
+ # Version:: $Id: fileoutputter.rb,v 1.2 2009/09/29 18:13:13 colbygk Exp $
3
3
 
4
4
  require "log4r/outputter/iooutputter"
5
5
  require "log4r/staticlogger"
@@ -18,6 +18,7 @@ module Log4r
18
18
 
19
19
  @trunc = Log4rTools.decode_bool(hash, :trunc, true)
20
20
  _filename = (hash[:filename] or hash['filename'])
21
+ @create = Log4rTools.decode_bool(hash, :create, true)
21
22
 
22
23
  if _filename.class != String
23
24
  raise TypeError, "Argument 'filename' must be a String", caller
@@ -38,10 +39,16 @@ module Log4r
38
39
  end
39
40
 
40
41
  @filename = _filename
41
- @out = File.new(@filename, (@trunc ? "w" : "a"))
42
- Logger.log_internal {
43
- "FileOutputter '#{@name}' writing to #{@filename}"
44
- }
42
+ if ( @create == true ) then
43
+ @out = File.new(@filename, (@trunc ? "w" : "a"))
44
+ Logger.log_internal {
45
+ "FileOutputter '#{@name}' writing to #{@filename}"
46
+ }
47
+ else
48
+ Logger.log_internal {
49
+ "FileOutputter '#{@name}' called with :create == false, #{@filename}"
50
+ }
51
+ end
45
52
  end
46
53
 
47
54
  end