customlogger 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b83205247923c4adfe9f0a6ab7b3ddd6247b130e
4
- data.tar.gz: 991b7b21198ef829b72355c040b135a4230f56d1
3
+ metadata.gz: f537834e644caa7759a3babbbe4605abd4383be1
4
+ data.tar.gz: aeec376281de9d07e1838ca4be9f3d7b037c180d
5
5
  SHA512:
6
- metadata.gz: 5cd3178688ffad3d178bbb0934ebaab9053d803c841ef3da32cc838d47508ce3e499f8a3ca065fca5bb168643ee0fd1b32217067a30c24c84f52d44a887c0942
7
- data.tar.gz: dcf6f31edfbef2a63f71a2a404515145b2441fc5a91445eb7b7dd2f4d11c7aa668e54f72429a6cf188bd7a222f4ca59752a5374c248473e4ac1f1dbb78d84792
6
+ metadata.gz: ca3c22a1a8c2f2544b3ececca47f84bb09a0617990b388cd784f793371c4bcc4d8413b99556d0aaccd013520c5901fba7eae568ef96b3c267144e03038a0f796
7
+ data.tar.gz: 2263f2251b89035282457b846a47d38452297a62023f574ee02a945bb7d6f67ce25ef2d668ab4843d9a61501405675e6dfc6e405ddf6ff393b2736b8c1a7981e
data/.gitignore CHANGED
File without changes
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
- - 2.1
3
+ - 2.1.1
5
4
  - 2.0.0
6
- - 1.9.3
5
+ - 1.9.3
6
+ - 1.9.2
data/Gemfile CHANGED
File without changes
data/LICENSE CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
@@ -45,8 +45,6 @@ at the examples below.
45
45
  #### Log error
46
46
 
47
47
  CustomLogger.error 'This is an error message'
48
- CustomLogger.error = 'This is an error message'
49
- CustomLogger.error 'This is an error message', 'Error Title'
50
48
  CustomLogger.error('This is an error message', 'Error Title')
51
49
 
52
50
  ![Error Screenshot](https://raw.githubusercontent.com/SaimonL/repo-assets/master/customlogger/error.png)
@@ -54,8 +52,6 @@ at the examples below.
54
52
  #### Log warning
55
53
 
56
54
  CustomLogger.warning 'This is a warning message'
57
- CustomLogger.warning = 'This is a warning message'
58
- CustomLogger.warning 'This is a warning message', 'Warning Title'
59
55
  CustomLogger.warning('This is a warning message', 'Warning Title')
60
56
 
61
57
  ![Warning Screenshot](https://raw.githubusercontent.com/SaimonL/repo-assets/master/customlogger/warning.png)
@@ -63,8 +59,6 @@ at the examples below.
63
59
  #### Log debug
64
60
 
65
61
  CustomLogger.debug 'This is a debug message'
66
- CustomLogger.debug = 'This is a debug message'
67
- CustomLogger.debug 'This is a debug message', 'Debug Title'
68
62
  CustomLogger.debug('This is a debug message', 'Debug Title')
69
63
 
70
64
  ![Debug Screenshot](https://raw.githubusercontent.com/SaimonL/repo-assets/master/customlogger/debug.png)
@@ -72,8 +66,6 @@ at the examples below.
72
66
  #### Log info
73
67
 
74
68
  CustomLogger.info 'This is an info message'
75
- CustomLogger.info = 'This is an info message'
76
- CustomLogger.info 'This is an info message', 'Info Title'
77
69
  CustomLogger.info('This is an info message', 'Info Title')
78
70
 
79
71
  ![Info Screenshot](https://raw.githubusercontent.com/SaimonL/repo-assets/master/customlogger/info.png)
@@ -85,8 +77,6 @@ is 1000 characters horizontal without any line break then that is what you
85
77
  will see. Basically it is inside of a 'pre' html tag.
86
78
 
87
79
  CustomLogger.raw 'This is a raw message'
88
- CustomLogger.raw = 'This is a raw message'
89
- CustomLogger.raw 'This is a raw message', 'Raw Title'
90
80
  CustomLogger.raw('This is a raw message', 'Raw Title')
91
81
 
92
82
  ![Raw Screenshot](https://raw.githubusercontent.com/SaimonL/repo-assets/master/customlogger/raw.png)
@@ -111,13 +101,23 @@ looking for.
111
101
 
112
102
  #### Clear All Logs
113
103
 
104
+ To clear all logs that are there in the html file
105
+
114
106
  CustomLogger.clear
115
107
 
108
+ To auto clear all logs on EACH log
109
+
110
+ CustomLogger.auto_clear = true
111
+
112
+ To disable auto clear all logs on EACH log (default)
113
+
114
+ CustomLogger.auto_clear = true
115
+
116
116
  ## Log File
117
117
 
118
118
  You will find the log file in:
119
119
 
120
- log/customlogger.html
120
+ log/custom_logger.html
121
121
 
122
122
 
123
123
  ## Running Test On Gem (Not Rails App)
data/Rakefile CHANGED
File without changes
data/customlogger.gemspec CHANGED
File without changes
data/lib/customlogger.rb CHANGED
@@ -2,17 +2,35 @@ require 'json'
2
2
  require 'customlogger/version'
3
3
  require 'customlogger/html_template'
4
4
 
5
+
5
6
  module CustomLogger
6
- LOOP_LIMIT = 512
7
+ LOOP_LIMIT = 2048
7
8
  SECTION_HTML = '<section><hr></section>'
8
9
 
10
+ @log_path = [ Dir.pwd, '/log' ].join
11
+ @file_name = 'custom_logger.html'
12
+
13
+ @title = 'Custom Logger'
14
+ @error_colors = {
15
+ error: '#8b0000', warning: '#5e3927',
16
+ debug: '#004000', info: '#1b3d4f'
17
+ }
18
+
19
+ @auto_clear = false
20
+
21
+ @logged_total = 0
22
+
9
23
  class << self
10
24
  def path=(value)
11
25
  @log_path = value
12
26
  end
13
27
 
14
28
  def path
15
- @log_path||=[ Dir.pwd, '/log' ].join
29
+ if @log_path.nil? || @log_path == ''
30
+ [ Dir.pwd, '/log' ].join
31
+ else
32
+ @log_path
33
+ end
16
34
  end
17
35
 
18
36
  def file=(value)
@@ -20,7 +38,11 @@ module CustomLogger
20
38
  end
21
39
 
22
40
  def file
23
- @file_name||='CustomLogger.html'
41
+ if @file_name.nil? || @file_name == ''
42
+ 'custom_logger.html'
43
+ else
44
+ @file_name
45
+ end
24
46
  end
25
47
 
26
48
  def title=(value)
@@ -28,16 +50,15 @@ module CustomLogger
28
50
  end
29
51
 
30
52
  def title
31
- @title||='Custome Logger'
53
+ @title
32
54
  end
33
55
 
34
56
  def error_color(state, color)
35
- set_error_colors if @error_colors.nil?
36
57
  @error_colors[state] = color
37
58
  end
38
59
 
39
60
  def error_colors
40
- @error_colors||=set_error_colors
61
+ @error_colors
41
62
  end
42
63
 
43
64
  def new
@@ -50,52 +71,40 @@ module CustomLogger
50
71
  'Wiped All Old Logs'
51
72
  end
52
73
 
53
- def error=(value)
54
- log(:error, value)
55
- value
74
+ def auto_clear=(value)
75
+ @auto_clear = value
56
76
  end
57
77
 
58
- def error(value, title=nil)
59
- log(:error, value, title)
60
- value
78
+ def auto_clear
79
+ @auto_clear
61
80
  end
62
81
 
63
- def warning=(value)
64
- log(:warning, value)
82
+ def error(value, title=nil)
83
+ clear if @auto_clear
84
+ log(:error, value, title)
65
85
  value
66
86
  end
67
87
 
68
88
  def warning(value, title=nil)
89
+ clear if @auto_clear
69
90
  log(:warning, value, title)
70
91
  value
71
92
  end
72
93
 
73
- def debug=(value)
74
- log(:debug, value)
75
- value
76
- end
77
-
78
94
  def debug(value, title=nil)
95
+ clear if @auto_clear
79
96
  log(:debug, value, title)
80
97
  value
81
98
  end
82
99
 
83
- def info=(value)
84
- log(:info, value)
85
- value
86
- end
87
-
88
100
  def info(value, title=nil)
101
+ clear if @auto_clear
89
102
  log(:info, value, title)
90
103
  value
91
104
  end
92
105
 
93
- def raw=(value)
94
- log(:raw, value)
95
- value
96
- end
97
-
98
106
  def raw(value, title=nil)
107
+ clear if @auto_clear
99
108
  log(:raw, value, title)
100
109
  value
101
110
  end
@@ -105,15 +114,17 @@ module CustomLogger
105
114
  SECTION_HTML
106
115
  end
107
116
 
117
+ def demo
118
+ clear
119
+ error 'This is an error message...', 'Error'
120
+ warning 'This is a warning message...', 'Warning'
121
+ info 'This is an info message...', 'Info'
122
+ debug 'This is an debug message...', 'Debug'
123
+ raw 'This is an raw message...', 'Raw'
124
+ [ 'Demo complete for file: ', file ].join
125
+ end
108
126
 
109
127
  private
110
- def set_error_colors
111
- @error_colors = {
112
- error: '#8b0000', warning: '#6d422e',
113
- debug: '#ececec', info: '#285b75'
114
- }
115
- end
116
-
117
128
  def new_log_file
118
129
  file_path_name = [ path, file ].join('/')
119
130
  system "mkdir -p #{path}"
@@ -121,10 +132,27 @@ module CustomLogger
121
132
  end
122
133
 
123
134
  def log(state, message, title = nil)
135
+ title = format_title(title)
136
+ message = format_message(message)
137
+
138
+ abort('Infinite loop possibility!!') if @logged_total > LOOP_LIMIT
139
+
140
+ file_path_name = [ path, file ].join('/')
141
+ new_log_file unless File.exist?(file_path_name)
142
+
143
+ written_logs = build_log(file_path_name, state, message, title)
144
+ File.open(file_path_name, 'w') { |file| file.write(written_logs) }
145
+ @logged_total += 1
146
+ end
147
+
148
+ def format_title(title)
124
149
  if !title.nil? && !title.is_a?(String)
125
150
  title = title.inspect
126
151
  end
152
+ title
153
+ end
127
154
 
155
+ def format_message(message)
128
156
  unless %w(Array Hash String).include?(message.class.name)
129
157
  if defined?(Module::ActiveRecord).nil?
130
158
  message = message.inspect
@@ -132,28 +160,10 @@ module CustomLogger
132
160
  if message.is_a?(ActiveRecord::Base)
133
161
  message = JSON.pretty_generate(message.as_json)
134
162
  message = message.gsub!(/\n/,'<br>')
135
- else
136
- message = message.inspect
137
163
  end
138
164
  end
139
165
  end
140
-
141
- if @logged_total.nil?
142
- @logged_total = 0
143
- else
144
- abort('Infinite loop possibility!!') if @logged_total > LOOP_LIMIT
145
- end
146
-
147
- file_path_name = [ path, file ].join('/')
148
- new_log_file unless File.exist?(file_path_name)
149
-
150
- written_logs = File.read(file_path_name)
151
- written_logs = written_logs[0..-15].to_s
152
- written_logs = written_logs[0...-1] if written_logs[-1] == '<'
153
- written_logs.concat(to_html(state, message, title))
154
- written_logs.concat('</body></html>')
155
- File.open(file_path_name, 'w') { |file| file.write(written_logs) }
156
- @logged_total += 1
166
+ message
157
167
  end
158
168
 
159
169
  def to_html(state, message, title)
@@ -167,6 +177,14 @@ module CustomLogger
167
177
  end
168
178
  end
169
179
 
180
+ def build_log(file_path_name, state, message, title)
181
+ written_logs = File.read(file_path_name)
182
+ written_logs = written_logs[0..-15].to_s
183
+ written_logs = written_logs[0...-1] if written_logs[-1] == '<'
184
+ written_logs.concat(to_html(state, message, title))
185
+ written_logs.concat('</body></html>')
186
+ end
187
+
170
188
  def html
171
189
  error_colors
172
190
  HTMLTemplate.html(@title, @error_colors)
@@ -60,7 +60,7 @@ class HTMLTemplate
60
60
  font-family: monospace, monospace, serif;
61
61
  font-size: 0.9em;
62
62
  color: #{error_colors[:debug]};
63
- background-color: #f8fbe2;
63
+ background-color: #efffe2;
64
64
  border-color: #bbcbad;
65
65
  padding: 8px;
66
66
  border: 1px solid #bbcbad;
@@ -108,7 +108,7 @@ class HTMLTemplate
108
108
  font-family: monospace, monospace, serif;
109
109
  font-size: 0.9em;
110
110
  color: #303030;
111
- background-color: #dcdcdc;
111
+ background-color: #f7f7f7;
112
112
  border-color: #a0a0a0;
113
113
  padding: 8px;
114
114
  border: 1px solid #a0a0a0;
@@ -132,7 +132,7 @@ class HTMLTemplate
132
132
  </style>
133
133
  </head>
134
134
  <body>
135
- <h2>Custome Logger</h2>
135
+ <h2>Custom Logger</h2>
136
136
  </body></html>
137
137
  HTML
138
138
  end
@@ -1,3 +1,3 @@
1
1
  module Customlogger
2
- VERSION = '0.0.8'
2
+ VERSION = '0.0.9'
3
3
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'with Custom Logger' do
4
+ describe 'with error colors' do
5
+ it 'will have default error colors' do
6
+ expect( CustomLogger.error_colors
7
+ ).to eq ({ error: '#8b0000', warning: '#5e3927', debug: '#004000',
8
+ info: '#1b3d4f' })
9
+ end
10
+
11
+ it 'will allow to set error color' do
12
+ CustomLogger.error_color(:error, 'lovell')
13
+ expect( CustomLogger.error_colors
14
+ ).to eq ({ error: 'lovell', warning: '#5e3927', debug: '#004000',
15
+ info: '#1b3d4f' })
16
+ end
17
+
18
+ it 'will allow to set warning color' do
19
+ CustomLogger.error_color(:warning, 'slovell')
20
+ expect( CustomLogger.error_colors
21
+ ).to eq ({ error: 'lovell', warning: 'slovell', debug: '#004000',
22
+ info: '#1b3d4f' })
23
+ end
24
+
25
+ it 'will allow to set debug color' do
26
+ CustomLogger.error_color(:debug, 'saimon')
27
+ expect( CustomLogger.error_colors
28
+
29
+ ).to eq ({ error: 'lovell', warning: 'slovell', debug: 'saimon',
30
+ info: '#1b3d4f' })
31
+ end
32
+
33
+ it 'will allow to set debug color' do
34
+ CustomLogger.error_color(:info, 'ssl')
35
+ expect( CustomLogger.error_colors
36
+
37
+ ).to eq ({ error: 'lovell', warning: 'slovell', debug: 'saimon',
38
+ info: 'ssl' })
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,149 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'with Custom Logger' do
4
+
5
+ describe 'with loggin file' do
6
+ before(:all) do
7
+ CustomLogger.path = Dir.pwd
8
+ CustomLogger.file = 'delete-me.html'
9
+ @file_location = [ CustomLogger.path, CustomLogger.file ].join '/'
10
+ end
11
+
12
+ after(:all) { File.delete [ CustomLogger.path, CustomLogger.file ].join '/' }
13
+
14
+ describe 'with error loggin' do
15
+ before(:all) do
16
+ CustomLogger.error('this is an error', 'hello')
17
+ @data = read_file(@file_location)
18
+ end
19
+
20
+ it 'will add error message to the html file' do
21
+ expect(@data).to include 'this is an error'
22
+ end
23
+
24
+ it 'will add error title to the html file' do
25
+ expect(@data).to include '<header>hello</header>'
26
+ end
27
+ end
28
+
29
+ describe 'with warning loggin' do
30
+ before(:all) do
31
+ CustomLogger.warning('this is an warning', 'hi there')
32
+ @data = read_file(@file_location)
33
+ end
34
+
35
+ it 'will add error message to the html file' do
36
+ expect(@data).to include 'this is an warning'
37
+ end
38
+
39
+ it 'will add error title to the html file' do
40
+ expect(@data).to include '<header>hi there</header>'
41
+ end
42
+ end
43
+
44
+ describe 'with debug loggin' do
45
+ before(:all) do
46
+ CustomLogger.debug('this is an debug', 'hi you')
47
+ @data = read_file(@file_location)
48
+ end
49
+
50
+ it 'will add error message to the html file' do
51
+ expect(@data).to include 'this is an debug'
52
+ end
53
+
54
+ it 'will add error title to the html file' do
55
+ expect(@data).to include '<header>hi you</header>'
56
+ end
57
+ end
58
+
59
+ describe 'with info loggin' do
60
+ before(:all) do
61
+ CustomLogger.info('this is an info', 'hello you')
62
+ @data = read_file(@file_location)
63
+ end
64
+
65
+ it 'will add error message to the html file' do
66
+ expect(@data).to include 'this is an info'
67
+ end
68
+
69
+ it 'will add error title to the html file' do
70
+ expect(@data).to include '<header>hello you</header>'
71
+ end
72
+ end
73
+
74
+ describe 'with raw loggin' do
75
+ before(:all) do
76
+ CustomLogger.raw('this is an raw', 'hello abc')
77
+ @data = read_file(@file_location)
78
+ end
79
+
80
+ it 'will add error message to the html file' do
81
+ expect(@data).to include 'this is an raw'
82
+ end
83
+
84
+ it 'will add error title to the html file' do
85
+ expect(@data).to include '<header>hello abc</header>'
86
+ end
87
+ end
88
+
89
+ describe 'with new_line' do
90
+ before(:all) do
91
+ CustomLogger.new_line
92
+ @data = read_file(@file_location)
93
+ end
94
+
95
+ it 'will add a section' do
96
+ expect(@data).to include '<section><hr></section>'
97
+ end
98
+ end
99
+
100
+ describe 'with cleanup' do
101
+ before(:all) do
102
+ CustomLogger.clear
103
+ @data = read_file(@file_location)
104
+ end
105
+
106
+ it 'will cleanup file log' do
107
+ expect(@data).to_not include '<header>hello abc</header>'
108
+ end
109
+ end
110
+
111
+ describe 'with no file' do
112
+ before(:each) { File.delete([ CustomLogger.path, CustomLogger.file ].join('/')) }
113
+
114
+ it 'will be able to create a file on the fly' do
115
+ expect(CustomLogger.error('ss saimon')).to eq 'ss saimon'
116
+ end
117
+ end
118
+
119
+ describe 'with auto clear being on' do
120
+ after(:all) { CustomLogger.auto_clear = false }
121
+ before(:all) do
122
+ CustomLogger.clear
123
+ CustomLogger.auto_clear = true
124
+ end
125
+
126
+ before(:each) { CustomLogger.info('Hello there') }
127
+
128
+ it 'will clear the old log' do
129
+ CustomLogger.error('ss saimon')
130
+ @data = read_file(@file_location)
131
+ expect(@data).to_not include 'Hello there'
132
+ end
133
+
134
+ it 'will show the most recet log' do
135
+ CustomLogger.error('ss saimon')
136
+ CustomLogger.error('foo bar')
137
+ @data = read_file(@file_location)
138
+ expect(@data).to include 'foo bar'
139
+ end
140
+
141
+ it 'will show the most recet log and not previous' do
142
+ CustomLogger.error('ss saimon')
143
+ CustomLogger.error('foo bar')
144
+ @data = read_file(@file_location)
145
+ expect(@data).to_not include 'ss saimon'
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'with Custom Logger' do
4
+ describe 'with logging message' do
5
+ before(:each) do
6
+ allow(CustomLogger).to receive(:log).and_return(true)
7
+ end
8
+
9
+ it 'will return new line html code when new line is called' do
10
+ expect(CustomLogger.new_line).to eq '<section><hr></section>'
11
+ end
12
+
13
+ describe 'with title' do
14
+ it 'will return logged error' do'<section><hr></section>'
15
+ expect(CustomLogger.error('ss saimon', 'my title')).to eq 'ss saimon'
16
+ end
17
+
18
+ it 'will return logged warning' do
19
+ expect(CustomLogger.warning('ss saimon 123', 'my title')).to eq 'ss saimon 123'
20
+ end
21
+
22
+ it 'will return logged info' do
23
+ expect(CustomLogger.info('ss saimon 123 abc', 'my title')).to eq 'ss saimon 123 abc'
24
+ end
25
+
26
+ it 'will return logged raw' do
27
+ expect(CustomLogger.raw('saimon 123 abc', 'my title')).to eq 'saimon 123 abc'
28
+ end
29
+ end
30
+
31
+ describe 'without title' do
32
+ it 'will return logged error' do
33
+ expect(CustomLogger.error('ss saimon')).to eq 'ss saimon'
34
+ end
35
+
36
+ it 'will return logged warning' do
37
+ expect(CustomLogger.warning('ss saimon 123')).to eq 'ss saimon 123'
38
+ end
39
+
40
+ it 'will return logged info' do
41
+ expect(CustomLogger.info('ss saimon 123 abc')).to eq 'ss saimon 123 abc'
42
+ end
43
+
44
+ it 'will return logged raw' do
45
+ expect(CustomLogger.raw('saimon 123 abc')).to eq 'saimon 123 abc'
46
+ end
47
+ end
48
+ end
49
+ end
@@ -4,6 +4,7 @@ describe 'with Custom Logger' do
4
4
 
5
5
  describe 'with path call' do
6
6
  it 'will return current path if not specified' do
7
+ CustomLogger.path = nil
7
8
  expect(CustomLogger.path).to eq [ Dir.pwd, '/log' ].join
8
9
  end
9
10
 
@@ -15,7 +16,8 @@ describe 'with Custom Logger' do
15
16
 
16
17
  describe 'with file call' do
17
18
  it 'will return current file name if not specified' do
18
- expect(CustomLogger.file).to eq 'CustomLogger.html'
19
+ CustomLogger.file = nil
20
+ expect(CustomLogger.file).to eq 'custom_logger.html'
19
21
  end
20
22
 
21
23
  it 'will return set file name if was specified' do
@@ -26,211 +28,12 @@ describe 'with Custom Logger' do
26
28
 
27
29
  describe 'with title call' do
28
30
  it 'will return current title if not specified' do
29
- expect(CustomLogger.title).to eq 'Custome Logger'
31
+ expect(CustomLogger.title).to eq 'Custom Logger'
30
32
  end
31
33
 
32
34
  it 'will return set title if was specified' do
33
- CustomLogger.title = 'Custome Logger Saimon Lovell'
34
- expect(CustomLogger.title).to eq 'Custome Logger Saimon Lovell'
35
- end
36
- end
37
-
38
- describe 'with error colors' do
39
- it 'will have default error colors' do
40
- expect( CustomLogger.error_colors
41
- ).to eq ({ error: '#8b0000', warning: '#6d422e', debug: '#ececec',
42
- info: '#285b75' })
43
- end
44
-
45
- it 'will allow to set error color' do
46
- CustomLogger.error_color(:error, 'lovell')
47
- expect( CustomLogger.error_colors
48
- ).to eq ({ error: 'lovell', warning: '#6d422e', debug: '#ececec',
49
- info: '#285b75' })
50
- end
51
-
52
- it 'will allow to set warning color' do
53
- CustomLogger.error_color(:warning, 'slovell')
54
- expect( CustomLogger.error_colors
55
- ).to eq ({ error: 'lovell', warning: 'slovell', debug: '#ececec',
56
- info: '#285b75' })
57
- end
58
-
59
- it 'will allow to set debug color' do
60
- CustomLogger.error_color(:debug, 'saimon')
61
- expect( CustomLogger.error_colors
62
-
63
- ).to eq ({ error: 'lovell', warning: 'slovell', debug: 'saimon',
64
- info: '#285b75' })
65
- end
66
-
67
- it 'will allow to set debug color' do
68
- CustomLogger.error_color(:info, 'ssl')
69
- expect( CustomLogger.error_colors
70
-
71
- ).to eq ({ error: 'lovell', warning: 'slovell', debug: 'saimon',
72
- info: 'ssl' })
73
- end
74
- end
75
-
76
- describe 'with logging message' do
77
- before(:each) do
78
- allow(CustomLogger).to receive(:log).and_return(true)
79
- end
80
-
81
- it 'will return new line html code when new line is called' do
82
- expect(CustomLogger.new_line).to eq '<section><hr></section>'
83
- end
84
-
85
- describe 'with title' do
86
- it 'will return logged error' do'<section><hr></section>'
87
- expect(CustomLogger.error('ss saimon', 'my title')).to eq 'ss saimon'
88
- end
89
-
90
- it 'will return logged warning' do
91
- expect(CustomLogger.warning('ss saimon 123', 'my title')).to eq 'ss saimon 123'
92
- end
93
-
94
- it 'will return logged info' do
95
- expect(CustomLogger.info('ss saimon 123 abc', 'my title')).to eq 'ss saimon 123 abc'
96
- end
97
-
98
- it 'will return logged raw' do
99
- expect(CustomLogger.raw('saimon 123 abc', 'my title')).to eq 'saimon 123 abc'
100
- end
101
- end
102
-
103
- describe 'without title' do
104
- it 'will return logged error' do
105
- expect(CustomLogger.error = 'ss saimon').to eq 'ss saimon'
106
- end
107
-
108
- it 'will return logged warning' do
109
- expect(CustomLogger.warning = 'ss saimon 123').to eq 'ss saimon 123'
110
- end
111
-
112
- it 'will return logged info' do
113
- expect(CustomLogger.info = 'ss saimon 123 abc').to eq 'ss saimon 123 abc'
114
- end
115
-
116
- it 'will return logged raw' do
117
- expect(CustomLogger.raw = 'saimon 123 abc').to eq 'saimon 123 abc'
118
- end
119
- end
120
- end
121
-
122
- describe 'with loggin file' do
123
- before(:all) do
124
- CustomLogger.path = Dir.pwd
125
- CustomLogger.file = 'delete-me.html'
126
- @file_location = [ CustomLogger.path, CustomLogger.file ].join '/'
127
- end
128
-
129
- after(:all) { File.delete [ CustomLogger.path, CustomLogger.file ].join '/' }
130
-
131
- describe 'with error loggin' do
132
- before(:all) do
133
- CustomLogger.error('this is an error', 'hello')
134
- @data = read_file(@file_location)
135
- end
136
-
137
- it 'will add error message to the html file' do
138
- expect(@data).to include 'this is an error'
139
- end
140
-
141
- it 'will add error title to the html file' do
142
- expect(@data).to include '<header>hello</header>'
143
- end
144
- end
145
-
146
- describe 'with warning loggin' do
147
- before(:all) do
148
- CustomLogger.warning('this is an warning', 'hi there')
149
- @data = read_file(@file_location)
150
- end
151
-
152
- it 'will add error message to the html file' do
153
- expect(@data).to include 'this is an warning'
154
- end
155
-
156
- it 'will add error title to the html file' do
157
- expect(@data).to include '<header>hi there</header>'
158
- end
159
- end
160
-
161
- describe 'with debug loggin' do
162
- before(:all) do
163
- CustomLogger.debug('this is an debug', 'hi you')
164
- @data = read_file(@file_location)
165
- end
166
-
167
- it 'will add error message to the html file' do
168
- expect(@data).to include 'this is an debug'
169
- end
170
-
171
- it 'will add error title to the html file' do
172
- expect(@data).to include '<header>hi you</header>'
173
- end
174
- end
175
-
176
- describe 'with info loggin' do
177
- before(:all) do
178
- CustomLogger.info('this is an info', 'hello you')
179
- @data = read_file(@file_location)
180
- end
181
-
182
- it 'will add error message to the html file' do
183
- expect(@data).to include 'this is an info'
184
- end
185
-
186
- it 'will add error title to the html file' do
187
- expect(@data).to include '<header>hello you</header>'
188
- end
189
- end
190
-
191
- describe 'with raw loggin' do
192
- before(:all) do
193
- CustomLogger.raw('this is an raw', 'hello abc')
194
- @data = read_file(@file_location)
195
- end
196
-
197
- it 'will add error message to the html file' do
198
- expect(@data).to include 'this is an raw'
199
- end
200
-
201
- it 'will add error title to the html file' do
202
- expect(@data).to include '<header>hello abc</header>'
203
- end
204
- end
205
-
206
- describe 'with new_line' do
207
- before(:all) do
208
- CustomLogger.new_line
209
- @data = read_file(@file_location)
210
- end
211
-
212
- it 'will add a section' do
213
- expect(@data).to include '<section><hr></section>'
214
- end
215
- end
216
-
217
- describe 'with cleanup' do
218
- before(:all) do
219
- CustomLogger.clear
220
- @data = read_file(@file_location)
221
- end
222
-
223
- it 'will cleanup file log' do
224
- expect(@data).to_not include '<header>hello abc</header>'
225
- end
226
- end
227
-
228
- describe 'with no file' do
229
- before(:each) { File.delete([ CustomLogger.path, CustomLogger.file ].join('/')) }
230
-
231
- it 'will be able to create a file on the fly' do
232
- expect(CustomLogger.error = 'ss saimon').to eq 'ss saimon'
233
- end
35
+ CustomLogger.title = 'Custom Logger Saimon Lovell'
36
+ expect(CustomLogger.title).to eq 'Custom Logger Saimon Lovell'
234
37
  end
235
38
  end
236
39
 
data/spec/spec_helper.rb CHANGED
@@ -8,4 +8,10 @@ end
8
8
 
9
9
  RSpec.configure do |config|
10
10
  config.include Helper
11
+
12
+ config.after(:suite) do
13
+ if File.directory?([ Dir.pwd, 'log'].join('/'))
14
+ FileUtils.rm_rf([ Dir.pwd, 'log'].join('/'))
15
+ end
16
+ end
11
17
  end
data/tasks/rspec.rake CHANGED
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: customlogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saimon Lovell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-09 00:00:00.000000000 Z
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,9 @@ files:
86
86
  - lib/customlogger.rb
87
87
  - lib/customlogger/html_template.rb
88
88
  - lib/customlogger/version.rb
89
+ - spec/customlogger_color_spec.rb
90
+ - spec/customlogger_file_spec.rb
91
+ - spec/customlogger_messages_spec.rb
89
92
  - spec/customlogger_spec.rb
90
93
  - spec/spec_helper.rb
91
94
  - tasks/rspec.rake
@@ -114,5 +117,8 @@ signing_key:
114
117
  specification_version: 4
115
118
  summary: Log output in to a seperate html file.
116
119
  test_files:
120
+ - spec/customlogger_color_spec.rb
121
+ - spec/customlogger_file_spec.rb
122
+ - spec/customlogger_messages_spec.rb
117
123
  - spec/customlogger_spec.rb
118
124
  - spec/spec_helper.rb