log_switch 0.4.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +133 -0
  3. data/Gemfile +3 -2
  4. data/LICENSE +24 -0
  5. data/README.md +142 -0
  6. data/Rakefile +28 -15
  7. data/lib/log_switch/version.rb +1 -1
  8. data/lib/log_switch.rb +134 -71
  9. data/log_switch.gemspec +33 -32
  10. data/spec/log_switch_spec.rb +97 -87
  11. data/spec/spec_helper.rb +5 -13
  12. metadata +54 -353
  13. data/.gemtest +0 -1
  14. data/History.rdoc +0 -51
  15. data/README.rdoc +0 -192
  16. data/lib/log_switch/mixin.rb +0 -31
  17. data/spec/coverage/assets/0.5.3/app.js +0 -88
  18. data/spec/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  19. data/spec/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  20. data/spec/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  21. data/spec/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  22. data/spec/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  23. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  24. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  25. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  26. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  27. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  28. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  29. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  30. data/spec/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  31. data/spec/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  32. data/spec/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  33. data/spec/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  34. data/spec/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  35. data/spec/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  36. data/spec/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  37. data/spec/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  38. data/spec/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +0 -363
  39. data/spec/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
  40. data/spec/coverage/assets/0.5.3/favicon_green.png +0 -0
  41. data/spec/coverage/assets/0.5.3/favicon_red.png +0 -0
  42. data/spec/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  43. data/spec/coverage/assets/0.5.3/highlight.css +0 -129
  44. data/spec/coverage/assets/0.5.3/highlight.pack.js +0 -1
  45. data/spec/coverage/assets/0.5.3/jquery-1.6.2.min.js +0 -18
  46. data/spec/coverage/assets/0.5.3/jquery.dataTables.min.js +0 -152
  47. data/spec/coverage/assets/0.5.3/jquery.timeago.js +0 -141
  48. data/spec/coverage/assets/0.5.3/jquery.url.js +0 -174
  49. data/spec/coverage/assets/0.5.3/loading.gif +0 -0
  50. data/spec/coverage/assets/0.5.3/magnify.png +0 -0
  51. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  52. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  53. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  54. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  55. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  56. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  57. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  58. data/spec/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  59. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  60. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  61. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  62. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  63. data/spec/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  64. data/spec/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +0 -295
  65. data/spec/coverage/assets/0.5.3/stylesheet.css +0 -383
  66. data/spec/coverage/assets/0.7.1/application.css +0 -1110
  67. data/spec/coverage/assets/0.7.1/application.js +0 -626
  68. data/spec/coverage/assets/0.7.1/fancybox/blank.gif +0 -0
  69. data/spec/coverage/assets/0.7.1/fancybox/fancy_close.png +0 -0
  70. data/spec/coverage/assets/0.7.1/fancybox/fancy_loading.png +0 -0
  71. data/spec/coverage/assets/0.7.1/fancybox/fancy_nav_left.png +0 -0
  72. data/spec/coverage/assets/0.7.1/fancybox/fancy_nav_right.png +0 -0
  73. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_e.png +0 -0
  74. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_n.png +0 -0
  75. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_ne.png +0 -0
  76. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_nw.png +0 -0
  77. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_s.png +0 -0
  78. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_se.png +0 -0
  79. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_sw.png +0 -0
  80. data/spec/coverage/assets/0.7.1/fancybox/fancy_shadow_w.png +0 -0
  81. data/spec/coverage/assets/0.7.1/fancybox/fancy_title_left.png +0 -0
  82. data/spec/coverage/assets/0.7.1/fancybox/fancy_title_main.png +0 -0
  83. data/spec/coverage/assets/0.7.1/fancybox/fancy_title_over.png +0 -0
  84. data/spec/coverage/assets/0.7.1/fancybox/fancy_title_right.png +0 -0
  85. data/spec/coverage/assets/0.7.1/fancybox/fancybox-x.png +0 -0
  86. data/spec/coverage/assets/0.7.1/fancybox/fancybox-y.png +0 -0
  87. data/spec/coverage/assets/0.7.1/fancybox/fancybox.png +0 -0
  88. data/spec/coverage/assets/0.7.1/favicon_green.png +0 -0
  89. data/spec/coverage/assets/0.7.1/favicon_red.png +0 -0
  90. data/spec/coverage/assets/0.7.1/favicon_yellow.png +0 -0
  91. data/spec/coverage/assets/0.7.1/loading.gif +0 -0
  92. data/spec/coverage/assets/0.7.1/magnify.png +0 -0
  93. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  94. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  95. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  96. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  97. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  98. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  99. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  100. data/spec/coverage/assets/0.7.1/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  101. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_222222_256x240.png +0 -0
  102. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  103. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_454545_256x240.png +0 -0
  104. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png +0 -0
  105. data/spec/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  106. data/spec/coverage/index.html +0 -81
  107. data/spec/log_switch/coverage/assets/0.5.3/app.js +0 -88
  108. data/spec/log_switch/coverage/assets/0.5.3/fancybox/blank.gif +0 -0
  109. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_close.png +0 -0
  110. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_loading.png +0 -0
  111. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_nav_left.png +0 -0
  112. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_nav_right.png +0 -0
  113. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_shadow_e.png +0 -0
  114. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_shadow_n.png +0 -0
  115. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_shadow_ne.png +0 -0
  116. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_shadow_nw.png +0 -0
  117. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_shadow_s.png +0 -0
  118. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_shadow_se.png +0 -0
  119. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_shadow_sw.png +0 -0
  120. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_shadow_w.png +0 -0
  121. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_title_left.png +0 -0
  122. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_title_main.png +0 -0
  123. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_title_over.png +0 -0
  124. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancy_title_right.png +0 -0
  125. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancybox-x.png +0 -0
  126. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancybox-y.png +0 -0
  127. data/spec/log_switch/coverage/assets/0.5.3/fancybox/fancybox.png +0 -0
  128. data/spec/log_switch/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.css +0 -363
  129. data/spec/log_switch/coverage/assets/0.5.3/fancybox/jquery.fancybox-1.3.1.pack.js +0 -44
  130. data/spec/log_switch/coverage/assets/0.5.3/favicon_green.png +0 -0
  131. data/spec/log_switch/coverage/assets/0.5.3/favicon_red.png +0 -0
  132. data/spec/log_switch/coverage/assets/0.5.3/favicon_yellow.png +0 -0
  133. data/spec/log_switch/coverage/assets/0.5.3/highlight.css +0 -129
  134. data/spec/log_switch/coverage/assets/0.5.3/highlight.pack.js +0 -1
  135. data/spec/log_switch/coverage/assets/0.5.3/jquery-1.6.2.min.js +0 -18
  136. data/spec/log_switch/coverage/assets/0.5.3/jquery.dataTables.min.js +0 -152
  137. data/spec/log_switch/coverage/assets/0.5.3/jquery.timeago.js +0 -141
  138. data/spec/log_switch/coverage/assets/0.5.3/jquery.url.js +0 -174
  139. data/spec/log_switch/coverage/assets/0.5.3/loading.gif +0 -0
  140. data/spec/log_switch/coverage/assets/0.5.3/magnify.png +0 -0
  141. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  142. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  143. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  144. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  145. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  146. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  147. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  148. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  149. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-icons_222222_256x240.png +0 -0
  150. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  151. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-icons_454545_256x240.png +0 -0
  152. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-icons_888888_256x240.png +0 -0
  153. data/spec/log_switch/coverage/assets/0.5.3/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  154. data/spec/log_switch/coverage/assets/0.5.3/smoothness/jquery-ui-1.8.4.custom.css +0 -295
  155. data/spec/log_switch/coverage/assets/0.5.3/stylesheet.css +0 -383
  156. data/spec/log_switch/coverage/index.html +0 -81
  157. data/spec/log_switch/mixin_spec.rb +0 -89
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ecedbe5e49ac7e09fd71760ccec36aedf1270f72029101fffd3219d4447da256
4
+ data.tar.gz: c2968035a4838d42cb787439f3ba65497666105d4ba04c163e3983f2cdbb7c43
5
+ SHA512:
6
+ metadata.gz: e293009d9babdd7ba1236a18679e44faf3158bcc286215ddebb3de51e3ea29c3a27c9e38e3d1e8cb832d772ad839ef6fdf1dce864060f08088e51483afaeb64a
7
+ data.tar.gz: 1ca8b618a1419224bd546c2c301a60e54a58727577569e8369b7b61f1686f37dfcf9b64e05a703275d1428e5a593718d2be98a7bd735dfdf29920a7b78a33dcd
data/CHANGELOG.md ADDED
@@ -0,0 +1,133 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
6
+ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.1.0] - 2026-07-15
11
+
12
+ ### Added
13
+
14
+ - Declared the license (Unlicense) in the gemspec; the LICENSE file now ships with the gem.
15
+ - The gemspec now declares a `changelog_uri`, so rubygems.org links to the changelog. It points at
16
+ the released version's tag rather than a branch, so each release's link is immutable.
17
+
18
+ ### Changed
19
+
20
+ - The gemspec now requires Ruby >= 3.3. Older Rubies will continue to resolve to 1.0.0.
21
+ - Replaced the tailor linter with RuboCop, and the dead Travis config with GitHub Actions, testing
22
+ Ruby 3.3, 3.4 and 4.0.
23
+
24
+ ### Fixed
25
+
26
+ - Declared `logger` as a runtime dependency. `lib/log_switch.rb` has always required it, but the
27
+ gemspec never declared it — so under Bundler on Ruby 4.0, where `logger` is no longer a default
28
+ gem, requiring `log_switch` raised LoadError.
29
+
30
+ ## [1.0.0] - 2014-10-10
31
+
32
+ ### Added
33
+
34
+ - LogSwitch can now be included in your own module, then that included in other modules. This allows
35
+ toggling logging per includer.
36
+
37
+ ### Removed
38
+
39
+ - Removed `LogSwitch::Mixin` in favor of simpler implementation.
40
+
41
+ ### Fixed
42
+
43
+ - [gh-5](https://github.com/turboladen/log_switch/issues/5): The improvements listed above alleviate
44
+ this problem.
45
+
46
+ ## 0.4.1 - 2013-01-04
47
+
48
+ ### Fixed
49
+
50
+ - Initialize `@log` before calling it, thus removing warnings when running with `-w`.
51
+
52
+ ## [0.4.0] - 2012-11-12
53
+
54
+ ### Added
55
+
56
+ - [gh-4](https://github.com/turboladen/log_switch/issues/4): Added ability to toggle the prepending
57
+ of the class name to log messages. This lets you know which class/object is logging each message —
58
+ useful for when you have a number of different classes logging.
59
+
60
+ ## [0.3.0] - 2012-02-03
61
+
62
+ ### Added
63
+
64
+ - [gh-2](https://github.com/turboladen/log_switch/issues/2): Added ability to mix in
65
+ `LogSwitch::Mixin` to classes to allow calling `#log` in your class and have it delegate to your
66
+ singleton logger.
67
+
68
+ ### Fixed
69
+
70
+ - [gh-3](https://github.com/turboladen/log_switch/issues/3): Fixed warning on `@before_block`.
71
+
72
+ ## [0.2.0] - 2011-12-05
73
+
74
+ ### Added
75
+
76
+ - Added ability to pass a block to `.log` to have code executed before logging.
77
+ - Added `before` hook to allow code to be executed every time log gets called (but before the
78
+ message actually gets logged).
79
+
80
+ ### Fixed
81
+
82
+ - [gh-1](https://github.com/turboladen/log_switch/issues/1): Only log `#each_line` when that method
83
+ is supported on the object being logged.
84
+
85
+ ## [0.1.4] - 2011-10-10
86
+
87
+ ### Removed
88
+
89
+ - Removed gemspec enforcement of >= 1.9.2
90
+
91
+ ## [0.1.3] - 2011-10-10
92
+
93
+ ### Added
94
+
95
+ - Made 1.8.7 compatible.
96
+
97
+ ### Removed
98
+
99
+ - Removed dev deps: metric_fu, code_statistics
100
+
101
+ ## [0.1.2] - 2011-10-09
102
+
103
+ ### Fixed
104
+
105
+ - Just realized author is supposed to be my real name. :)
106
+
107
+ ## [0.1.1] - 2011-10-09
108
+
109
+ ### Fixed
110
+
111
+ - Fixed author field in .gemspec
112
+
113
+ ## [0.1.0] - 2011-10-07
114
+
115
+ ### Added
116
+
117
+ - `require` and `extend` to mix in to your class/module to get a single point of logging
118
+ - Switch on/off logging
119
+ - Use whatever Logger you want
120
+
121
+ <!-- 0.4.1 is intentionally unlinked: it was never tagged or released to rubygems. -->
122
+
123
+ [unreleased]: https://github.com/turboladen/log_switch/compare/v1.1.0...HEAD
124
+ [1.1.0]: https://github.com/turboladen/log_switch/compare/v1.0.0...v1.1.0
125
+ [1.0.0]: https://github.com/turboladen/log_switch/compare/v0.4.0...v1.0.0
126
+ [0.4.0]: https://github.com/turboladen/log_switch/compare/v0.3.0...v0.4.0
127
+ [0.3.0]: https://github.com/turboladen/log_switch/compare/v0.2.0...v0.3.0
128
+ [0.2.0]: https://github.com/turboladen/log_switch/compare/v0.1.4...v0.2.0
129
+ [0.1.4]: https://github.com/turboladen/log_switch/compare/v0.1.3...v0.1.4
130
+ [0.1.3]: https://github.com/turboladen/log_switch/compare/v0.1.2...v0.1.3
131
+ [0.1.2]: https://github.com/turboladen/log_switch/compare/v0.1.1...v0.1.2
132
+ [0.1.1]: https://github.com/turboladen/log_switch/compare/v0.1.0...v0.1.1
133
+ [0.1.0]: https://github.com/turboladen/log_switch/releases/tag/v0.1.0
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
- source :rubygems
2
- gemspec
1
+ # frozen_string_literal: true
3
2
 
3
+ source 'https://rubygems.org'
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
data/README.md ADDED
@@ -0,0 +1,142 @@
1
+ # log_switch
2
+
3
+ <https://github.com/turboladen/log_switch>
4
+
5
+ ## Description
6
+
7
+ While developing other gems that needed a single class/singleton style logger, I got tired of
8
+ repeating the code to create that logger and mix it in to my base class. I just wanted to require
9
+ something, mix it in, and log:
10
+
11
+ ```ruby
12
+ MyThing.new.log "some message"
13
+ ```
14
+
15
+ ...and be able to switch that logging off programmatically:
16
+
17
+ ```ruby
18
+ MyThing.logging_enabled = false
19
+ ```
20
+
21
+ This gem does that.
22
+
23
+ ## Synopsis
24
+
25
+ ### Basic use
26
+
27
+ `include LogSwitch` to give your class a class-level logger and an instance-level `#log` method.
28
+ **Logging is off by default** — turn it on explicitly:
29
+
30
+ ```ruby
31
+ require 'log_switch'
32
+
33
+ class MyThing
34
+ include LogSwitch
35
+ end
36
+
37
+ MyThing.logging_enabled = true
38
+ MyThing.new.log "I like you, Ruby."
39
+ # => D, [2026-07-15T12:46:30.206465 #66434] DEBUG -- : <MyThing> I like you, Ruby.
40
+ ```
41
+
42
+ Switch it back off and calls become no-ops:
43
+
44
+ ```ruby
45
+ MyThing.logging_enabled = false
46
+ MyThing.new.log "You're my favorite." # => nothing is written
47
+
48
+ MyThing.logging_enabled = true # ...and back on, for the examples below
49
+ ```
50
+
51
+ Note the class name is prepended to each message. That is on by default.
52
+
53
+ ### Log levels
54
+
55
+ The default level is `:debug`. Change it with `default_log_level`:
56
+
57
+ ```ruby
58
+ MyThing.default_log_level = :warn
59
+ MyThing.new.log "Crap!"
60
+ # => W, [2026-07-15T12:46:30.206563 #66434] WARN -- : <MyThing> Crap!
61
+ ```
62
+
63
+ Or pass a level per call:
64
+
65
+ ```ruby
66
+ MyThing.new.log "Stuff!", :info
67
+ # => I, [2026-07-15T12:46:30.206499 #66434] INFO -- : <MyThing> Stuff!
68
+ ```
69
+
70
+ The level is passed straight through to your Logger, so any method it responds to will do.
71
+
72
+ ### Using your own Logger
73
+
74
+ `LogSwitch` defaults to a `Logger` writing to `STDOUT`. Point it anywhere:
75
+
76
+ ```ruby
77
+ MyThing.logger = Logger.new('log.txt')
78
+ MyThing.new.log "hi!"
79
+ ```
80
+
81
+ `LogSwitch.logger` sets the default for includers that have not set their own, and
82
+ `LogSwitch.reset_config!` puts things back to a fresh `STDOUT` logger.
83
+
84
+ ### Multi-line messages
85
+
86
+ Anything responding to `#each_line` is logged one line per call, so a multi-line message stays
87
+ readable:
88
+
89
+ ```ruby
90
+ MyThing.new.log "line one\nline two"
91
+ # => D, [...] DEBUG -- : <MyThing> line one
92
+ # => D, [...] DEBUG -- : <MyThing> line two
93
+ ```
94
+
95
+ Objects that do not respond to `#each_line` (an Array, an Exception) are logged whole.
96
+
97
+ ### Hooks
98
+
99
+ Pass a block to `#log` and it runs before the message is written — handy for one-off setup:
100
+
101
+ ```ruby
102
+ require 'fileutils'
103
+ log_directory = File.expand_path('log')
104
+
105
+ MyThing.new.log("Thanks brah!") do
106
+ FileUtils.mkdir_p(log_directory)
107
+ end
108
+ ```
109
+
110
+ For something that should run before _every_ call, use `before_log`:
111
+
112
+ ```ruby
113
+ MyThing.before_log = proc { FileUtils.mkdir_p(log_directory) }
114
+ MyThing.new.log "Thanks brah!" # runs the hook, then logs
115
+ MyThing.new.log "I'm hungry..." # runs it again
116
+ ```
117
+
118
+ ## Requirements
119
+
120
+ - Ruby >= 3.3. Tested on 3.3, 3.4 and 4.0 (see `.github/workflows/ci.yml`).
121
+ - Runtime dependency: `logger` (no longer a default gem as of Ruby 4.0).
122
+
123
+ ## Install
124
+
125
+ ```sh
126
+ gem install log_switch
127
+ ```
128
+
129
+ ## Developers
130
+
131
+ After checking out the source:
132
+
133
+ ```sh
134
+ bundle install
135
+ bundle exec rake # specs + RuboCop
136
+ ```
137
+
138
+ ## Thanks
139
+
140
+ I need to thank the [savon](https://github.com/savonrb/savon) project for most of the code here.
141
+ Somehow I ran across how they do logging and started following suit. The code in `log_switch` is
142
+ almost identical to Savon's logging.
data/Rakefile CHANGED
@@ -1,29 +1,42 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
  require 'yard'
6
+ require 'rubocop/rake_task'
4
7
 
5
8
  YARD::Rake::YardocTask.new do |t|
6
- t.files = %w(lib/**/*.rb - History.rdoc)
7
- t.options = %W(--title log_switch Documentation (#{LogSwitch::VERSION}))
8
- t.options += %w(--main README.rdoc)
9
+ t.files = %w[lib/**/*.rb - CHANGELOG.md]
10
+ t.options = %W[--title log_switch Documentation (#{LogSwitch::VERSION})]
11
+ t.options += %w[--main README.md]
9
12
  end
10
13
 
11
14
  RSpec::Core::RakeTask.new do |t|
12
- t.ruby_opts = %w(-w)
15
+ t.ruby_opts = %w[-w]
13
16
  end
14
17
 
15
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION > "1.9"
16
- require 'tailor/rake_task'
18
+ RuboCop::RakeTask.new
19
+
20
+ # RuboCop covers Ruby; dprint covers the Markdown and YAML. It is a binary
21
+ # rather than a gem, so `bundle install` cannot supply it -- fail loudly with
22
+ # somewhere to go rather than skipping, which would make the gate a no-op
23
+ # exactly when nobody notices.
24
+ desc 'Check non-Ruby formatting with dprint'
25
+ task :dprint do
26
+ abort <<~MSG unless system('command -v dprint > /dev/null 2>&1')
27
+ dprint is not installed, so Markdown/YAML formatting was not checked.
28
+ Install it (https://dprint.dev/install/) -- e.g. `brew install dprint` --
29
+ or run `rake spec rubocop` to skip this deliberately.
30
+ MSG
17
31
 
18
- Tailor::RakeTask.new do |task|
19
- task.file_set 'lib/**/*.rb'
20
- task.file_set 'spec/**/*.rb', :specs
21
- end
32
+ sh 'dprint check'
33
+ end
22
34
 
23
- # Alias for rubygems-test
24
- task :test => [:spec, :tailor]
25
- else
26
- task :test => :spec
35
+ desc 'Format non-Ruby files with dprint'
36
+ task 'dprint:fmt' do
37
+ sh 'dprint fmt'
27
38
  end
28
39
 
29
- task :default => :test
40
+ task test: %i[spec rubocop dprint]
41
+
42
+ task default: :test
@@ -1,3 +1,3 @@
1
1
  module LogSwitch
2
- VERSION = '0.4.0'
2
+ VERSION = '1.1.0'
3
3
  end
data/lib/log_switch.rb CHANGED
@@ -1,93 +1,156 @@
1
- require "logger"
2
- require File.expand_path(File.dirname(__FILE__) + '/log_switch/version')
3
- require File.expand_path(File.dirname(__FILE__) + '/log_switch/mixin')
1
+ require 'logger'
2
+ require_relative 'log_switch/version'
4
3
 
5
- # LogSwitch allows for extending a class/module with a logger and, most
6
- # importantly, allows for turning off logging programmatically. See the
7
- # +README.rdoc+ for more info.
4
+ # LogSwitch mixes a logger into a class/module and, most importantly, allows for
5
+ # turning off logging programmatically. See README.md for more info.
8
6
  module LogSwitch
7
+ def self.included(base)
8
+ @includers ||= []
9
+ @includers << base
10
+ base.extend ClassMethods
11
+ base.send(:include, InstanceMethods)
9
12
 
10
- # Saves the name of the class that extended itself with this module. Used
11
- # by {LogSwitch::Mixin} to know which class to include itself to.
12
- def self.extend_object(base)
13
- @extender = base
14
- super(base)
13
+ base.class_eval do
14
+ def self.included(b)
15
+ b.extend ClassMethods
16
+ b.send :include, InstanceMethods
17
+ end
18
+ end
15
19
  end
16
20
 
17
- # Simply returns the name of the class that extended itself with this module.
18
- # It's set by {.extend_object}.
19
- #
20
- # @return [Class] The class that extended itself with LogSwitch.
21
- def self.extender
22
- @extender
21
+ # Defaults to a +Logger+ writing to STDOUT.
22
+ def self.logger
23
+ @logger ||= ::Logger.new STDOUT
23
24
  end
24
25
 
25
- # Use to turn logging on or off.
26
- attr_writer :log
26
+ def self.logger=(new_logger)
27
+ @logger = new_logger
28
+ end
27
29
 
28
- # Set this to the Logger you want to use.
29
- attr_writer :logger
30
+ # Sets back to defaults.
31
+ def self.reset_config!
32
+ self.logger = ::Logger.new STDOUT
30
33
 
31
- # Set the log level so you don't have to pass it in on your call.
32
- attr_writer :log_level
34
+ @includers.each do |klass|
35
+ klass.logging_enabled = false
36
+ klass.log_class_name = true
37
+ end
38
+ end
33
39
 
34
- # Toggle prepending the class name of the #log caller to the log message.
35
- attr_writer :log_class_name
40
+ module ClassMethods
41
+ # TODO: broken -- the class variables below are declared in this module body,
42
+ # so they live on ClassMethods itself and every includer shares one slot:
43
+ # `A.logging_enabled = true` also enables B. Intent is per-includer config.
36
44
 
37
- # Tells whether logging is turned on or not.
38
- def log?
39
- @log != false
40
- end
45
+ # @param value [Boolean]
46
+ def logging_enabled
47
+ @@logging_enabled ||= false
48
+ end
41
49
 
42
- # Defaults to a +Logger+ writing to STDOUT.
43
- def logger
44
- @logger ||= ::Logger.new STDOUT
45
- end
50
+ # Tells whether logging is turned on or not.
51
+ #
52
+ # @param value [Boolean]
53
+ def logging_enabled?
54
+ !!logging_enabled
55
+ end
46
56
 
47
- # @return [Symbol] The current default log level. Starts off as :debug.
48
- def log_level
49
- @log_level ||= :debug
50
- end
57
+ # Use to turn logging on or off.
58
+ #
59
+ # @param value [Boolean]
60
+ def logging_enabled=(value)
61
+ @@logging_enabled = value
62
+ end
51
63
 
52
- # @return [Boolean] Tells whether logging of the class name with the log
53
- # message is turned on.
54
- def log_class_name?
55
- @log_class_name == true
56
- end
64
+ # @return [Symbol] The current default log level. Starts off as :debug.
65
+ def default_log_level
66
+ @@default_log_level ||= :debug
67
+ end
68
+
69
+ # @param level [Symbol]
70
+ def default_log_level=(level)
71
+ @@default_log_level = level
72
+ end
73
+
74
+ # @return [Boolean] Tells whether logging of the class name with the log
75
+ # message is turned on.
76
+ def log_class_name?
77
+ log_class_name
78
+ end
57
79
 
58
- # {#log} calls the block given to this method before it logs every time.
59
- # This, thus, acts as a hook in the case where you want to make sure some
60
- # code gets executed before you log a message. Useful for making sure a file
61
- # exists before logging to it.
62
- #
63
- # @param [Proc] block The block of code to execute before logging a message
64
- # with {#log}.
65
- def before(&block)
66
- @before_block ||= block
80
+ # TODO: broken -- `||=` against a truthy default overwrites a stored `false`
81
+ # on the next read, so `log_class_name = false` never sticks.
82
+ def log_class_name
83
+ @@log_class_name ||= true
84
+ end
85
+
86
+ # Toggle prepending the class name of the #log caller to the log message.
87
+ def log_class_name=(value)
88
+ @@log_class_name = value
89
+ end
90
+
91
+ def logger
92
+ @@logger ||= LogSwitch.logger
93
+ end
94
+
95
+ def logger=(new_logger)
96
+ @@logger = new_logger
97
+ end
98
+
99
+ # {#log} calls the block given to this method before it logs every time.
100
+ # This, thus, acts as a hook in the case where you want to make sure some
101
+ # code gets executed before you log a message. Useful for making sure a file
102
+ # exists before logging to it.
103
+ #
104
+ # @param [Proc] block The block of code to execute before logging a message
105
+ # with {#log}.
106
+ # TODO: broken -- `||=` keeps only the first assignment, and #before_log
107
+ # initialises the slot on first read, so later hooks are silently ignored.
108
+ def before_log=(block)
109
+ @@before_block ||= block
110
+ end
111
+
112
+ def before_log
113
+ @@before_block ||= Proc.new do; end
114
+ end
67
115
  end
68
116
 
69
- # Logs a message using the level provided. If no level provided, use
70
- # +@log_level+.
71
- #
72
- # @param [String] message The message to log.
73
- # @param [Symbol] level The log level to send to your Logger.
74
- def log(message, level=log_level)
75
- before.call unless before.nil?
76
- yield if block_given?
77
-
78
- if log?
79
- if message.respond_to? :each_line
80
- message.each_line { |line| logger.send level, line.chomp }
81
- else
82
- logger.send(level, message)
117
+ module InstanceMethods
118
+ def logger
119
+ self.class.logger
120
+ end
121
+
122
+ # Logs a message using the level provided. If no level provided, use
123
+ # +@log_level+.
124
+ #
125
+ # @param [String] message The message to log.
126
+ # @param [Symbol] level The log level to send to your Logger.
127
+ def log(message, level=nil)
128
+ level ||= self.class.default_log_level
129
+
130
+ self.class.before_log.call
131
+ yield if block_given?
132
+
133
+ if self.class.logging_enabled?
134
+ if message.respond_to? :each_line
135
+ message.each_line do |line|
136
+ msg = filter_class_name(line.chomp)
137
+ logger.send(level, msg)
138
+ end
139
+ else
140
+ message = filter_class_name(message)
141
+ logger.send(level, message)
142
+ end
83
143
  end
84
144
  end
85
- end
86
145
 
87
- # Sets back to defaults.
88
- def reset_config!
89
- self.log = true
90
- self.logger = ::Logger.new STDOUT
91
- self.log_class_name = false
146
+ private
147
+
148
+ def filter_class_name(message)
149
+ if self.class.log_class_name?
150
+ "<#{self.class.name}> #{message}"
151
+ else
152
+ message
153
+ end
154
+ end
92
155
  end
93
156
  end