groonga-log 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.travis.yml +9 -0
- data/Gemfile +4 -0
- data/README.md +44 -0
- data/Rakefile +14 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/groonga-log.gemspec +52 -0
- data/lib/groonga-log.rb +19 -0
- data/lib/groonga-log/parser.rb +75 -0
- data/lib/groonga-log/statistic.rb +39 -0
- data/lib/groonga-log/version.rb +3 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7e5760b5a5c27945a6f07959e7232ef365afc423
|
4
|
+
data.tar.gz: 1d653394e6f75b28326290af218e4abd620992c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3390b385703b14e31cb33d972b43b327b3fa57d8bdbcc69e2580ee0ce90e178a6250a54e5363032c8526b82889e50699750c3780bf81f9d47fa720a41692253f
|
7
|
+
data.tar.gz: 5bfeb0af6f5c3cee534cdab7fbe1317ecc8b002ae6944c56e98ef5ecedb6d1362c09b2e0bf29757d03959b4df7e29ef59c7a94edf2e422daf1b0d3ecb0d97065
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# README
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/groonga/groonga-log.png?branch=master)](https://travis-ci.org/groonga/groonga-log)
|
4
|
+
|
5
|
+
## Name
|
6
|
+
|
7
|
+
groonga-log
|
8
|
+
|
9
|
+
## Description
|
10
|
+
|
11
|
+
Groonga-log is a collection of library and tools to
|
12
|
+
process [Groonga](http://groonga.org/)'s log.
|
13
|
+
|
14
|
+
Groonga's log is logged when `--log-path` option is specified. You can
|
15
|
+
write a program to process Groonga log by using groonga-log as a
|
16
|
+
library.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
Add this line to your application's Gemfile:
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
gem 'groonga-log'
|
24
|
+
```
|
25
|
+
|
26
|
+
And then execute:
|
27
|
+
|
28
|
+
$ bundle
|
29
|
+
|
30
|
+
Or install it yourself as:
|
31
|
+
|
32
|
+
$ gem install groonga-log
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
TODO: Write usage instructions here
|
37
|
+
|
38
|
+
## Dependencies
|
39
|
+
|
40
|
+
TODO:
|
41
|
+
|
42
|
+
## License
|
43
|
+
|
44
|
+
LGPLv2.1 or later. See doc/text/lgpl-2.1.txt for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
task :default => :test
|
3
|
+
|
4
|
+
desc "Run tests"
|
5
|
+
task :test do
|
6
|
+
task_index = ARGV.index("test")
|
7
|
+
if task_index
|
8
|
+
run_test_options = ARGV[(task_index + 1)..-1]
|
9
|
+
else
|
10
|
+
run_test_options = []
|
11
|
+
end
|
12
|
+
tests_exit_status = ruby("test/run-test.rb", *run_test_options)
|
13
|
+
exit(tests_exit_status)
|
14
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "groonga/log"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/groonga-log.gemspec
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# -*- mode: ruby; coding: utf-8 -*-
|
2
|
+
#
|
3
|
+
# Copyright (C) 2017 Yasuhiro Horimoto <horimoto@clear-code.com>
|
4
|
+
#
|
5
|
+
# This library is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU Lesser General Public
|
7
|
+
# License as published by the Free Software Foundation; either
|
8
|
+
# version 2.1 of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This library is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
13
|
+
# Lesser General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU Lesser General Public
|
16
|
+
# License along with this library; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
18
|
+
|
19
|
+
lib = File.expand_path('../lib', __FILE__)
|
20
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
21
|
+
require 'groonga-log/version'
|
22
|
+
|
23
|
+
clean_white_space = lambda do |entry|
|
24
|
+
entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
Gem::Specification.new do |spec|
|
28
|
+
spec.name = "groonga-log"
|
29
|
+
spec.version = GroongaLog::VERSION
|
30
|
+
|
31
|
+
spec.authors = ["Horimoto Yasuhiro"]
|
32
|
+
spec.email = ["horimoto@clear-code.com"]
|
33
|
+
|
34
|
+
readme = File.read("README.md", :encoding => "UTF-8")
|
35
|
+
entries = readme.split(/^\#\#\s(.*)$/)
|
36
|
+
description = clean_white_space.call(entries[entries.index("Description") + 1])
|
37
|
+
spec.summary, spec.description, = description.split(/\n\n+/, 3)
|
38
|
+
|
39
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
40
|
+
f.match(%r{^(test|spec|features)/})
|
41
|
+
end
|
42
|
+
|
43
|
+
spec.homepage = "https://github.com/groonga/groonga-log"
|
44
|
+
spec.licenses = ["LGPLv2.1+"]
|
45
|
+
spec.require_paths = ["lib"]
|
46
|
+
|
47
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
48
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
49
|
+
|
50
|
+
spec.add_development_dependency("test-unit")
|
51
|
+
spec.add_development_dependency("test-unit-notify")
|
52
|
+
end
|
data/lib/groonga-log.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
require "groonga-log/parser"
|
18
|
+
require "groonga-log/statistic"
|
19
|
+
require "groonga-log/version"
|
@@ -0,0 +1,75 @@
|
|
1
|
+
# Copyright (C) 2017 Yasuhiro Horimoto <horimoto@clear-code.com>
|
2
|
+
# Copyright (C) 2017 Kentaro Hayashi <hayashi@clear-code.com>
|
3
|
+
#
|
4
|
+
# This library is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU Lesser General Public
|
6
|
+
# License as published by the Free Software Foundation; either
|
7
|
+
# version 2.1 of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This library is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
# Lesser General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU Lesser General Public
|
15
|
+
# License along with this library; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
17
|
+
|
18
|
+
require "groonga-log/statistic"
|
19
|
+
|
20
|
+
module GroongaLog
|
21
|
+
class Parser
|
22
|
+
PATTERN =
|
23
|
+
/\A(?<year>\d{4})-(?<month>\d\d)-(?<day>\d\d)
|
24
|
+
\ (?<hour>\d\d):(?<minute>\d\d):(?<second>\d\d)\.(?<micro_second>\d+)
|
25
|
+
\|(?<log_level>.)
|
26
|
+
\|(?<context_id>.+?)
|
27
|
+
\|(?<message>.*)/x
|
28
|
+
|
29
|
+
def parse(input)
|
30
|
+
return to_enum(:parse, input) unless block_given?
|
31
|
+
|
32
|
+
input.each_line do |line|
|
33
|
+
next unless line.valid_encoding?
|
34
|
+
m = PATTERN.match(line)
|
35
|
+
|
36
|
+
statistic = Statistic.new
|
37
|
+
statistic.year = m['year'].to_i
|
38
|
+
statistic.month = m['month'].to_i
|
39
|
+
statistic.day = m['day'].to_i
|
40
|
+
statistic.hour = m['hour'].to_i
|
41
|
+
statistic.minute = m['minute'].to_i
|
42
|
+
statistic.second = m['second'].to_i
|
43
|
+
statistic.micro_second = m['micro_second'].to_i
|
44
|
+
statistic.log_level = log_level_to_symbol(m['log_level'])
|
45
|
+
statistic.context_id = m['context_id']
|
46
|
+
statistic.message = m['message']
|
47
|
+
yield statistic
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
private
|
52
|
+
def log_level_to_symbol(level_text)
|
53
|
+
case level_text
|
54
|
+
when "E"
|
55
|
+
:emergency
|
56
|
+
when "A"
|
57
|
+
:alert
|
58
|
+
when "C"
|
59
|
+
:critical
|
60
|
+
when "e"
|
61
|
+
:error
|
62
|
+
when "w"
|
63
|
+
:warning
|
64
|
+
when "n"
|
65
|
+
:notice
|
66
|
+
when "i"
|
67
|
+
:information
|
68
|
+
when "d"
|
69
|
+
:debug
|
70
|
+
when "-"
|
71
|
+
:dump
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Copyright (C) 2017 Kouhei Sutou <kou@clear-code.com>
|
2
|
+
#
|
3
|
+
# This library is free software; you can redistribute it and/or
|
4
|
+
# modify it under the terms of the GNU Lesser General Public
|
5
|
+
# License as published by the Free Software Foundation; either
|
6
|
+
# version 2.1 of the License, or (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This library is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
11
|
+
# Lesser General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU Lesser General Public
|
14
|
+
# License along with this library; if not, write to the Free Software
|
15
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
16
|
+
|
17
|
+
module GroongaLog
|
18
|
+
class Statistic < Struct.new(:timestamp,
|
19
|
+
:year,
|
20
|
+
:month,
|
21
|
+
:day,
|
22
|
+
:hour,
|
23
|
+
:minute,
|
24
|
+
:second,
|
25
|
+
:micro_second,
|
26
|
+
:log_level,
|
27
|
+
:context_id,
|
28
|
+
:message)
|
29
|
+
def timestamp
|
30
|
+
super || Time.local(year, month, day, hour, minute, second, micro_second)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_h
|
34
|
+
hash = super
|
35
|
+
hash[:timestamp] ||= timestamp
|
36
|
+
hash
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: groonga-log
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Horimoto Yasuhiro
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit-notify
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: |
|
70
|
+
Groonga's log is logged when `--log-path` option is specified. You can
|
71
|
+
write a program to process Groonga log by using groonga-log as a
|
72
|
+
library.
|
73
|
+
email:
|
74
|
+
- horimoto@clear-code.com
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- ".gitignore"
|
80
|
+
- ".travis.yml"
|
81
|
+
- Gemfile
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- doc/text/news.md
|
87
|
+
- groonga-log.gemspec
|
88
|
+
- lib/groonga-log.rb
|
89
|
+
- lib/groonga-log/parser.rb
|
90
|
+
- lib/groonga-log/statistic.rb
|
91
|
+
- lib/groonga-log/version.rb
|
92
|
+
homepage: https://github.com/groonga/groonga-log
|
93
|
+
licenses:
|
94
|
+
- LGPLv2.1+
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.5
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Groonga-log is a collection of library and tools to process [Groonga](http://groonga.org/)'s
|
116
|
+
log.
|
117
|
+
test_files: []
|