syslog_client 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.rbc
2
+ *.sassc
3
+ .sass-cache
4
+ capybara-*.html
5
+ .rspec
6
+ /.bundle
7
+ /vendor/bundle
8
+ /log/*
9
+ /tmp/*
10
+ /db/*.sqlite3
11
+ /public/system/*
12
+ /coverage/
13
+ /spec/tmp/*
14
+ **.orig
15
+ rerun.txt
16
+ pickle-email-*.html
17
+ .*
18
+ *.gem
19
+ spec/*
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ syslog_client
2
+ =============
3
+
4
+ syslog_client with tuan800
@@ -0,0 +1,5 @@
1
+ require 'syslog_client/base'
2
+ require 'syslog_client/editor'
3
+ require 'syslog_client/match_shop'
4
+ require 'syslog_client/deal_flow'
5
+ require 'syslog_client/version'
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ require 'logglier'
3
+ module SyslogClient
4
+ class Base
5
+ cattr_accessor :logger
6
+ @@logger = Logglier.new('udp://192.168.2.180:8080', :format => :json)
7
+
8
+ class << self
9
+ def send_log(options)
10
+ infos = log_of_options(options)
11
+ infos = infos.is_a?(::Array) ? infos : [infos]
12
+
13
+ now = Time.now
14
+ infos.each do |info|
15
+ @@logger.info(info.reverse_merge(:operation_time => now))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ module SyslogClient
3
+ class DealFlow < Base
4
+ class << self
5
+ protected
6
+ def log_of_options(options)
7
+ _normalize_options(options)
8
+ options.slice(:deal_id, :operation, :operation_time, :operator, :result, :message).reverse_merge(:operator => get_operator(options[:operation])).merge(:type => 'deal_flow')
9
+ end
10
+
11
+ def _normalize_options(options)
12
+ raise ArgumentError, 'options should be instance of Hash' unless options.is_a?(::Hash)
13
+ options.symbolize_keys!
14
+ end
15
+
16
+ def get_operator(operation)
17
+ operations.map do |k, v|
18
+ return k.to_s if v.include?(operation.to_sym)
19
+ end
20
+ end
21
+
22
+ #和Java 爬虫相关的操作:
23
+ #operator --> java_crawler
24
+ #operations --> 操作流程名只有两个,为上面标为黄色的两个擦作。
25
+ #crawl_deal_page 为抓取页面流程,
26
+ #parse_deal_page 为解析、入库流程的名字
27
+ #和嘉伟相关的操作:
28
+ #operator --> ruby_crawler
29
+ #operations --> 操作流程名字一共有七个,为标为粉色部分
30
+ #create为新建流程、
31
+ #call_shop_match为调用商铺匹配接口流程、
32
+ #add_shop为关联Shop流程、
33
+ #push_fetch_job分配抓取任务的流程、
34
+ #receive_check_shop_match为接收到商铺匹配的Check请求的流程、
35
+ #receive_check_ext_info为接收到其他信息Check 请求的流程、
36
+ #receive_check_expire_time 为接收到Check过期时间请求的流程
37
+
38
+ #和国强相关的操作:
39
+ #operator --> ai(人工智能)
40
+ #operations --> 操作流程名一共有四个,为绿素部分
41
+ #receive_shop_match 为收到匹配商铺请求的流程
42
+ #check_shop_match 为发起Check商铺匹配的流程
43
+ #check_ext_info 为发起Check ext_info的流程
44
+ #check_expire_time 为发起Check expire_time的流程
45
+
46
+ #和文远相关的操作:
47
+ #operator --> classifier
48
+ #operation --> 操作流程名一共有两个,为蓝色部分
49
+ #push_classify_job 为分发分类任务的流程名
50
+ #classify 为设置分类的流程名
51
+ def operations
52
+ {
53
+ :java_crawler => [:crawl_deal_page, :parse_deal_page],
54
+ :ruby_crawler => [:create, :call_shop_match, :add_shop, :push_fetch_job, :receive_check_shop_match, :receive_check_ext_info, :receive_check_expire_time],
55
+ :ai => [:receive_shop_match, :check_shop_match, :check_ext_info, :check_expire_time],
56
+ :classifier => [:push_classify_job, :classify]
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module SyslogClient
3
+ class Editor < Base
4
+ class << self
5
+ protected
6
+ def log_of_options(options)
7
+ _normalize_options(options)
8
+ log_of_changes(options) if options[:changes]
9
+ end
10
+
11
+ def _normalize_options(options)
12
+ raise ArgumentError, 'options should be instance of Hash' unless options.is_a?(::Hash)
13
+ options.symbolize_keys!
14
+
15
+ if options[:changes]
16
+ _normalize_changes(options)
17
+ elsif obj = options[:object]
18
+ options.merge!({ :entry_class => obj.class.name, :entry_id => obj.id })
19
+ options[:changes] = obj.changes
20
+ end
21
+ end
22
+
23
+ def _normalize_changes(options)
24
+ raise ArgumentError, 'changes should be instance of Hash' unless options[:changes].is_a?(::Hash)
25
+ options[:changes].stringify_keys!
26
+ end
27
+
28
+ def log_of_changes(options)
29
+ options[:changes].inject([]) do |infos, change|
30
+ infos << {
31
+ :operation => change[0],
32
+ :value => change[1][0],
33
+ :value_was => change[1][1],
34
+ :type => 'editor'
35
+ }.merge(options.slice(:user_id, :reason, :entry_class, :entry_id, :operation_time))
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+ module SyslogClient
3
+ class MatchShop < Base
4
+ class << self
5
+ protected
6
+ def log_of_options(options)
7
+ _normalize_options(options)
8
+ options.slice(:reason, :source, :deal_id, :tuan_shop_id, :shop_info_id, :operation_time).merge(:type => 'match_shop')
9
+ end
10
+
11
+ def _normalize_options(options)
12
+ raise ArgumentError, 'options should be instance of Hash' unless options.is_a?(::Hash)
13
+ options.symbolize_keys!
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module SyslogClient
2
+ Version = VERSION = '0.1'
3
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift 'lib'
2
+ require 'syslog_client/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'syslog_client'
5
+ s.version = SyslogClient::Version
6
+ s.date = '2012-12-28'
7
+ s.summary = "syslog client!"
8
+ s.description = "syslog client with tuan800"
9
+ s.authors = ['tumayun']
10
+ s.email = 'tumayun.2010@gmail.com'
11
+ s.files = `git ls-files`.split($/)
12
+ s.require_paths = ["lib"]
13
+ s.homepage = 'https://github.com/tumayun/syslog_client'
14
+ s.add_dependency "logglier", "~> 0.2.8"
15
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: syslog_client
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - tumayun
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: logglier
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.2.8
30
+ description: syslog client with tuan800
31
+ email: tumayun.2010@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - README.md
38
+ - lib/syslog_client.rb
39
+ - lib/syslog_client/base.rb
40
+ - lib/syslog_client/deal_flow.rb
41
+ - lib/syslog_client/editor.rb
42
+ - lib/syslog_client/match_shop.rb
43
+ - lib/syslog_client/version.rb
44
+ - syslog_client.gemspec
45
+ homepage: https://github.com/tumayun/syslog_client
46
+ licenses: []
47
+ post_install_message:
48
+ rdoc_options: []
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ! '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: syslog client!
69
+ test_files: []