splog 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGQ5MTc5ZGUwMGJjNGE0NDBiZWViMWIzYmY3M2JkODZhNDMzMGJiOQ==
4
+ N2IwOThhNGYzZTI5MzVmYTk0YjNhOGFkMzgwOGJhM2JlOTYyMzUzNw==
5
5
  data.tar.gz: !binary |-
6
- NmIxNDZjZDdjYTlkMDU3NmQ2YzQzOGRjYWExNjUyY2IzNDg2YWJhNw==
6
+ NTkyNGQ3NWM3NWVhNWU3Nzc4NWE1MThiYjYyZDEwYjRmYmY1MTk2OA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NTk2OTlhOWU0ZTJlNzQxOTkxYTg4NTNmOWZiNTQyNzYyMzY5ODg1MzFjYjFl
10
- YzVjMzVlMTE4YTM3N2M5ZGVmZDVkZTQ1YTRjNmYyNjRiZGMzYmYzMDZmMDlk
11
- MjMxY2U5OTZlODZkN2VkZmZmYWI1MzY5ZWE4NDk2NDE0NjY0OGI=
9
+ ZmRkMTFlZGY2MjZkNWJmYjczOTJkYTQ1MzYzNDg4ZWMyMzlmMGE0NDA4ZDIw
10
+ ZTdlYzAzZjFmYzM1MzcxYzFmYmZkYmU0YjlkYTkzYTgyY2ZmMTU0YTQ4Mjk2
11
+ OWFiYjZlMDIxNTA3NjhhODE5ZTBmZDI3NmIyYjM1NWVjOTI1MjA=
12
12
  data.tar.gz: !binary |-
13
- ZDk3ZjQxZTA3YWZlOWZkYzc1OWEzNWVhZjAxMzc4Yjg4NzE2NGQ1MGZlNjQz
14
- YWMzY2NhMGM0MjBmNzY0Y2M1MDMyZGI0ZGNlMjdhMjlhYTkzMmMyYWIxNjhh
15
- ZDdmOGE3OWMzNDhiZjNjYTdjMzBkNjQxMjk5MTkwN2IyMTk1YTk=
13
+ YjNkODBmOTQ1YzgyMjBiM2UyYjA4NTdlNjQwMzhhZWFiNmYyMTc5ZDE4NWYx
14
+ NjYzMjZmNDBkMTQyNWRlY2I5NGU1YzlhYjU3MmRiYWI5ZDdjYTZlYjljZDlj
15
+ ZjY5ZGRmMjA0NTY1Yjg5ZTliYWQ5NDhjNjBhMGQ2Mzk4YjBkZjU=
data/README.md CHANGED
@@ -113,7 +113,7 @@ Persisting the log to mongo. Set -o with no arg so that no output to stdout. T
113
113
  ## Building Splog in Development
114
114
 
115
115
  `rake build`
116
- `rake release`
116
+ `rake release` or `gem push`
117
117
 
118
118
  #### Examples of executing the bin/splog in development
119
119
 
@@ -148,3 +148,13 @@ Parsing a 45m Apache access log:
148
148
  ## Dependencies
149
149
 
150
150
  Splog is compatible with Ruby 1.9+
151
+
152
+ ## Changelog
153
+
154
+ #### 0.0.3 -- Oct 2013
155
+
156
+ * Added verbose logging using the ruby progress bar to give clear visual progress
157
+
158
+ #### 0.0.2 -- Oct 2013
159
+
160
+ * Initial release
data/lib/splog/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Splog
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/splog.rb CHANGED
@@ -7,6 +7,7 @@ require 'yaml'
7
7
  require 'json'
8
8
  require 'enumerator'
9
9
  require 'mongo'
10
+ require 'ruby-progressbar'
10
11
 
11
12
  include Mongo
12
13
 
@@ -22,6 +23,10 @@ module Splog
22
23
  # Yaml config options
23
24
  @config = {}
24
25
 
26
+ # Progress bar to create if in verbose mode
27
+ @progress_bar = nil
28
+ @line_count = nil
29
+
25
30
  # Command line options
26
31
  @options = {
27
32
  :append => true
@@ -335,6 +340,20 @@ module Splog
335
340
  File.open(file_name).to_enum
336
341
  end
337
342
 
343
+ def update_progress_bar
344
+ if options[:verbose] and not @progress_bar
345
+ if @line_count.nil?
346
+ @progress_bar = ProgressBar.create(:starting_at => 0, :total => @line_count)
347
+ else
348
+ @progress_bar = ProgressBar.create(:title => 'Lines Read', :format => '[%a] %c Completed |%b>>%i| %p%% %t [%e]', :total => @line_count)
349
+ end
350
+ end
351
+
352
+ if @options[:verbose] and @progress_bar
353
+ @progress_bar.increment
354
+ end
355
+ end
356
+
338
357
  def cli(args=nil)
339
358
  options = {
340
359
  :append => true,
@@ -383,11 +402,18 @@ module Splog
383
402
  options[:mongo_coll] = ext || nil
384
403
  end
385
404
 
405
+ parser.on('--line-count N', Integer, 'If reading from STDIN (using pipes) Setting the line count will allow splog to better log th progress in verbose mode. Ex. --line-count `wc -l some.log`') do |ext|
406
+ options[:line_count] = ext || nil
407
+ end
408
+
386
409
  parser.on('--[no-]md5', 'When saving to mongo md5 the hash and set that to the _id. This means repeated parses of the same log file should be idempotent. Otherwise there will be duplicated lines in the database.') do |ext|
387
- p ext
388
410
  options[:md5] = ext # if -m then == true
389
411
  end
390
412
 
413
+ parser.on('-v', 'Verbose logging, recommended in conjunction with -o without any arguments.') do |ext|
414
+ options[:verbose] = ext # if -m then == true
415
+ end
416
+
391
417
  parser.on_tail('-h', '--help', '--usage', 'Show this usage message and quit.') do |setting|
392
418
  puts parser.help
393
419
  exit
@@ -422,13 +448,22 @@ module Splog
422
448
  set_pattern(options)
423
449
  set_mapping(options)
424
450
 
451
+ # Total line count, if file input we can easily do wc -l on the file. If $stdin we can allow allow a user defined
452
+ # input from --line-count `wc -l <filename>`
453
+
425
454
  # Get the enum from the file
426
455
  e = nil
427
456
  if options[:file_name] and options[:pattern_name]
428
457
  e = read_log_file(options[:file_name])
458
+ @line_count = %x{wc -l #{options[:file_name]}}.split.first.to_i
459
+
460
+ # Set the progress bar total
461
+ #update_progress_bar_total(line_count)
462
+
429
463
  # Or stdin otherwise
430
464
  elsif not $stdin.tty?
431
465
  e = $stdin.to_enum
466
+ @line_count = options[:line_count]
432
467
  else
433
468
  $stderr.print 'Please either specify a -f FILENAME or pipe content to splog.'
434
469
  exit
@@ -479,6 +514,8 @@ module Splog
479
514
  if options[:db_ref_name]
480
515
  persist_log_entry(parsed_line)
481
516
  end
517
+
518
+ update_progress_bar
482
519
  end
483
520
  rescue => detail
484
521
  nil
data/splog.gemspec CHANGED
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  # Add runtime dependencies
22
22
  spec.add_runtime_dependency 'mongo'
23
23
  spec.add_runtime_dependency 'bson_ext'
24
+ spec.add_runtime_dependency 'ruby-progressbar'
24
25
 
25
26
  # Add development dependencies
26
27
  spec.add_development_dependency 'bundler', '~> 1.3'
data/test/splog_spec.rb CHANGED
@@ -282,6 +282,19 @@ describe Splog::LogParser do
282
282
  pe = parser.parse(e)
283
283
  parsed_lines = pe.to_a
284
284
  parsed_lines.length.should eql(2)
285
+ end
286
+
287
+ it 'should output verbose logging' do
288
+ # Match subsequent lines and add them to a previous line
289
+ test_dir = Dir.pwd.match(/.*?splog$/) ? 'test/' : ''
290
+ dot_file_path = File.expand_path("#{test_dir}examples/apache/.splog.yml")
291
+ server_log_name = File.expand_path("#{test_dir}examples/apache/simple_access_log")
285
292
 
293
+ parser = Splog::LogParser.new
294
+ parser.cli(['-p', 'apache_common','-f', server_log_name, '-c', dot_file_path, '-o', '-v'])
295
+ e = parser.read_log_file(parser.options[:file_name])
296
+ # Get an enumerable from the parser
297
+ pe = parser.parse(e)
298
+ parsed_lines = pe.to_a
286
299
  end
287
300
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: splog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Mendenhall
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-progressbar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement