custom_logs 0.0.3 → 0.0.4

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
- MjliY2M4Mjg4MGEwZjg3MDE2NWM0MmQ3NTIxYmUxYTk1MjM0MDAyOA==
4
+ NGVkMzU3Y2YxMDY1OWVkMTBkNDcwYjMzODU3YTU2NTU4NGI4YTFiMA==
5
5
  data.tar.gz: !binary |-
6
- MWJjNTU3NjJlYmYwZWZkNWU2ZWYyM2I5YWZlMDgyNWM2MzcxNjQ3NA==
6
+ OTZkMWIxMGI3ZTdmNjNiZGY0ZWQ3MWYwMjg0OWRkZmNmYmJkMzZlNw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ODc3YzkxYTU0NzgwMTczNzE2MjNlZDlkOTllYTEwMDcyOGEzODg5MjI1Mzll
10
- MzY4MjJmM2M1N2E5NWYyYjNmZGQ3Njg3NGNkMzk0MjU5YzVlMDg4MmYxN2Q0
11
- YzZlMjI0ZDA0NTU4OTgyMTVlZjQ2OGJhZjA5ZDdmOTA3YmU4N2I=
9
+ NGUyMDkxOTllODdkMGQwNjQyMWU1NTlmZTk0M2ZiYWYwZTQ3OGQ4NDU3NzFi
10
+ NWZiZDA2NzlhOTgzZDM2OGZmMTVmODJmZGIzOTE1ZjExZjhjMzJmN2VhMmVj
11
+ YTFjMDljNGY0ZGVhNzViY2QwYThjNmMzN2ZlMDc5MTBhMGU5N2Y=
12
12
  data.tar.gz: !binary |-
13
- ZTBlM2RjMTBmNzU3NDQ3ZTM0ZWY2MWIzYTg5Nzc5NGFiMzZkOTBjZGY4ZTY0
14
- OTY5NzNmMDdkYzI2NGRjOWQ3YTVjMDgxNzYxOWE3Njk2ZmFlMjdkYTAyMmZi
15
- YjFjMmZiMjU0YTc0YzU4MDM5MjU5ZjA1ZDFjODAwYzA4OGMwMGM=
13
+ MzRhZDVlZTZhNTYyZDVlNTkzMDJmMmMwYWJmNGFiNWQxZDc3ZWExMmFjYjUz
14
+ NzZiZjU5NzhkODc5OTgzYTYzMmNlODk4ZjA4YmQwODE2MmFlMDdkYmIxMDJj
15
+ NjgyMjQ3ZjlmYmNlNjg5NWEzZTBhNmYzYTU3Y2Q4YzEyZDE0NTE=
data/README.md CHANGED
@@ -6,7 +6,7 @@ TODO: Write a gem description
6
6
 
7
7
  Add this line to your application's Gemfile:
8
8
 
9
- gem 'custom_logs'
9
+ gem 'custom_logs', '0.0.4'
10
10
 
11
11
  And then execute:
12
12
 
@@ -14,14 +14,20 @@ And then execute:
14
14
 
15
15
  Generate config file:
16
16
 
17
- $ rails g custom_logs
17
+ $ rails g custom_logs or rails g custom_logs syslog
18
18
 
19
- Or install it yourself as:
20
-
21
- $ gem install custom_logs
22
19
 
23
20
  ## Usage
24
21
 
22
+ You can log your users data with this command:
23
+
24
+ $ bundle exec rake custom_logs:dump_users #for User class
25
+
26
+ or
27
+
28
+ $ bundle exec rake custom_logs:dump_users dump_class=Admin #for your custom class
29
+
30
+
25
31
  TODO: Write usage instructions here
26
32
 
27
33
  ## Contributing
data/custom_logs.gemspec CHANGED
@@ -20,4 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.5"
22
22
  spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "remote_syslog_logger"
25
+
23
26
  end
@@ -17,7 +17,7 @@ module CustomLogs
17
17
  hash.delete(:params)
18
18
  end
19
19
 
20
- "[CUSTOM-LOGS]#{hash.to_json}"
20
+ "#{hash.to_json}"
21
21
 
22
22
  end
23
23
 
@@ -44,6 +44,10 @@ module CustomLogs
44
44
  new_hash
45
45
  end
46
46
 
47
+ def dump_users(resource)
48
+ Socket.write({users: resource.all}.to_json)
49
+ end
50
+
47
51
  end
48
52
  end
49
53
  end
@@ -1,16 +1,41 @@
1
+ require 'remote_syslog_logger'
2
+
1
3
  module CustomLogs
2
4
  class Socket
3
5
 
4
6
  @@socket = nil
7
+ @@socket_type = nil
5
8
 
6
9
  class << self
7
10
  def get
8
- @@socket ||= ::Logger.new(STDOUT)
11
+ @@socket if @@socket
12
+ if (syslog_config = ParseConfig.get[:syslog]).present?
13
+ @@socket = RemoteSyslogLogger.new(syslog_config[:host], syslog_config[:port])
14
+ @@socket_type = :syslog
15
+ else
16
+ @@socket = ::Logger.new(STDOUT)
17
+ @@socket_type = :stdout
18
+ end
19
+ @@socket
9
20
  end
10
21
 
11
22
  def write(message)
12
- get.unknown(message)
23
+ get.unknown("[CUSTOM-LOGS]#{message}")
24
+ end
25
+
26
+ def socket_type
27
+ get unless @@socket
28
+ @@socket_type
29
+ end
30
+
31
+ def syslog?
32
+ socket_type == :syslog
33
+ end
34
+
35
+ def stdout?
36
+ socket_type == :stdout
13
37
  end
38
+
14
39
  end
15
40
 
16
41
  end
@@ -1,3 +1,3 @@
1
1
  module CustomLogs
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/custom_logs.rb CHANGED
@@ -6,4 +6,10 @@ require 'custom_logs/action_controller_ext'
6
6
 
7
7
 
8
8
  ActionController::Base.send :include, CustomLogs::ActionControllerExt
9
- ActionController::Base.send :around_filter, :custom_logs
9
+ ActionController::Base.send :around_filter, :custom_logs
10
+
11
+ class CustomLogsDumpUsers < Rails::Railtie
12
+ rake_tasks do
13
+ Dir[File.join(File.dirname(__FILE__),'..','tasks/*.rake')].each { |f| load f }
14
+ end
15
+ end
@@ -1,6 +1,7 @@
1
1
  class CustomLogsGenerator < Rails::Generators::Base
2
2
 
3
3
  source_root File.expand_path("../templates", __FILE__)
4
+ argument :syslog, type: :string, default: 'false'
4
5
 
5
6
  desc 'Creating config file for redis logstash'
6
7
  def config
@@ -13,5 +14,9 @@ class CustomLogsGenerator < Rails::Generators::Base
13
14
  user_methods = ApplicationController.new.methods.select{|m| m.to_s.starts_with?('current_')}
14
15
  end
15
16
 
17
+ def syslog?
18
+ return true if syslog == true || syslog =~ (/(true|t|yes|y|1|syslog)$/i)
19
+ return false
20
+ end
16
21
 
17
22
  end
@@ -6,6 +6,12 @@ defaults: &defaults
6
6
  <% user_methods.each do |method| -%>
7
7
  <%= " - #{method}" %>
8
8
  <% end -%>
9
+ <% if syslog? -%>
10
+ syslog:
11
+ host: 'localhost'
12
+ port: '514'
13
+ <% end -%>
14
+
9
15
 
10
16
  development:
11
17
  <<: *defaults
@@ -0,0 +1,18 @@
1
+ namespace :custom_logs do
2
+
3
+ desc "dump users to custom logs"
4
+ task :dump_users => :environment do
5
+
6
+ logger = Logger.new(STDOUT)
7
+ my_dump_class_string = (ENV['dump_class'] || 'User').classify
8
+ my_dump_class = my_dump_class_string.safe_constantize
9
+
10
+ if my_dump_class
11
+ CustomLogs::Logger.dump_users(my_dump_class)
12
+ else
13
+ logger.error "Error: Your dump class '#{my_dump_class_string}' doesn't exists"
14
+ end
15
+
16
+ end
17
+
18
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Piechocki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-15 00:00:00.000000000 Z
11
+ date: 2014-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: remote_syslog_logger
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
  description: Add your logs to standard output
42
56
  email:
43
57
  - work@marek-piechocki.pl
@@ -59,6 +73,7 @@ files:
59
73
  - lib/custom_logs/version.rb
60
74
  - lib/generators/custom_logs_generator.rb
61
75
  - lib/generators/templates/custom_logs.yml
76
+ - tasks/dump_users.rake
62
77
  homepage: https://github.com/mapiech/custom_logs
63
78
  licenses:
64
79
  - MIT