log_wrapper 0.0.1 → 0.0.2

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 (2) hide show
  1. data/lib/log_wrapper.rb +46 -0
  2. metadata +3 -3
@@ -62,6 +62,52 @@ class Log_Wrapper
62
62
  end
63
63
  end
64
64
 
65
+ def web_grep(guid)
66
+
67
+ log_lines, start_time, end_time, duration = nil
68
+ if guid && guid.length>0
69
+ log_lines = grep(guid)
70
+ user, system, elapsed = 0.0, 0.0, 0.0
71
+ slowest_duration = -1.0
72
+ timings = false
73
+
74
+ if log_lines.length > 0
75
+ start_time = end_time = log_lines[0]['date']
76
+ log_lines.each do |e|
77
+ date = e['date']
78
+ start_time = date if date < start_time
79
+ end_time = date if date > end_time
80
+ if e['times']
81
+ user += e['times']['user']
82
+ system += e['times']['system']
83
+ elapsed += e['times']['elapsed']
84
+ timings = true
85
+ slowest_duration = e['times']['elapsed'] if e['times']['elapsed'] > slowest_duration
86
+ end
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ t = {}
93
+ if timings
94
+ t['times'] = { 'user' => user, 'system' => system, 'elapsed' => elapsed }
95
+ end
96
+
97
+ duration = (end_time - start_time) if end_time
98
+
99
+ t.merge(
100
+ {
101
+ 'guid' => guid,
102
+ 'log_lines' => log_lines,
103
+ 'start_time' => start_time,
104
+ 'end_time' => end_time,
105
+ 'duration' => duration,
106
+ 'slowest_duration' => slowest_duration
107
+ }
108
+ )
109
+
110
+ end
65
111
 
66
112
  private
67
113
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-29 00:00:00.000000000 Z
12
+ date: 2012-10-09 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A trivial wrapper for the Ruby Logger that adds convenience methods for
15
15
  timing execution, for logging in json, and for grep'ing the current log.
@@ -19,7 +19,7 @@ extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
21
  - lib/log_wrapper.rb
22
- homepage: http://rubygems.org/gems/log_wrapper
22
+ homepage: https://github.com/renenw/log_wrapper
23
23
  licenses: []
24
24
  post_install_message:
25
25
  rdoc_options: []