oh_my_log 1.0.4 → 1.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d38cf6c6258aaa07963ca2d81d7856fbeddf171002d421816b44b60ef8300278
4
- data.tar.gz: 9cdf4c4a912f38677cff0891dbfb13456c43b608415a7077fc7e878589ed6ab5
3
+ metadata.gz: ea12189e28a7ff710bee96c376acea0797c7530612cd294878e6da28f1b5e896
4
+ data.tar.gz: 0c0b2163cfd7f3c4dc48a04f5a165d52c8c87a0b1f6447fe8be8acc7632860e6
5
5
  SHA512:
6
- metadata.gz: d4c1d022e32dd410ee0ca905368dbfcfefa0101f780005b89b1c6f5597d8a6742dfc0f051b54da2de8dc162b0eccd0e1c122980f1a416bb204a5336b3c540137
7
- data.tar.gz: c2043882304ab9ac77926480e2e9eb5ec08c7ed808ce2a3c051bf2c5864699b42b28f628bfa9a18d3d53d18740e7a48df7ee76bd8f2196f2930c41387d6a060a
6
+ metadata.gz: 27b8c2c5ba7b0f16a7e6f9b761dcb344f59225e152b714d1c7129b11782b9b0526186f739cabc035a938706de64f92eeadfba096324fe1884c780a0c11502509
7
+ data.tar.gz: 5a7e4cdff1395cb3621b1c3a019357fe7a74552d153016174572cbf88a9552973cce152f17a4ef7aeeedf4455071c4bb531bb2958551f852f6523768dceb4ce2
data/README.md CHANGED
@@ -64,6 +64,8 @@ bundle exec rake oh_my_log:generate_observers
64
64
 
65
65
  >selectors Selector[] (instance list of all the selectors)
66
66
 
67
+ >user_fields String[]/Symbol[] (fallback fields used to log an user)
68
+
67
69
  ###### Instance methods:
68
70
 
69
71
  >add_selector(selector ->Selector) (use this to add a new selector inside the configuration,
@@ -109,11 +111,12 @@ Complex initializer example:
109
111
  OhMyLog::Log.configure do |config|
110
112
  config.print_log = true
111
113
  selector = OhMyLog::Log::Selector.new
112
- selector.set_controllers("EXCEPT" =>["ApplicationController"])
114
+ selector.set_controllers("EXCEPT" =>["Application","Hotel"])
113
115
  selector.set_actions("ONLY" =>["index","create","destroy"])
114
116
  selector.set_status_codes("ONLY" =>[(0..200)])
115
117
  selector.set_methods("EXCEPT" =>["GET"])
116
118
  selector.set_ips("EXCEPT"=>["192.168.0.1"])
119
+ config.user_fields = ["email", "full_name"]
117
120
  config.add_selector(selector)
118
121
  #put your configs here
119
122
  end
@@ -1,7 +1,7 @@
1
1
  module OhMyLog
2
2
  module Log
3
3
  class Configuration
4
- attr_accessor :models, :print_log, :record_history, :log_instance, :syslog
4
+ attr_accessor :models, :print_log, :record_history, :log_instance, :syslog, :user_fields
5
5
  attr_reader :selectors, :log_path
6
6
 
7
7
  def initialize(*args)
@@ -12,6 +12,7 @@ module OhMyLog
12
12
  @log_instance = Logger.new(File.join(Rails.root, 'log/oh_my_log.log')) unless @log_path
13
13
  @log_path = nil
14
14
  @syslog = nil
15
+ @user_fields = PrintableUser::DEFAULT_FIELDS
15
16
  #do we wanna keep track of all the actions?
16
17
  @record_history = false
17
18
  end
@@ -0,0 +1,32 @@
1
+ class PrintableUser
2
+ DEFAULT_FIELDS = ["email", "full_name", ["first_name", "last_name"], "id"].freeze
3
+
4
+ def initialize(user, accepted_values)
5
+ raise "DIO" unless accepted_values
6
+ raise ArgumentError unless user || !accepted_values.is_a?(Array)
7
+ @user = user
8
+ @accepted_values = accepted_values
9
+ end
10
+
11
+ def to_s
12
+ try_val = ->(val) do
13
+ user.send(val.to_sym) rescue nil
14
+ end
15
+ accepted_values.each do |val|
16
+ if val.is_a?(Array)
17
+ tmp_val = val.map {|field| try_val.call(field)}.join(" ")
18
+ return tmp_val if tmp_val.present?
19
+ elsif [String, Symbol].include?(val.class)
20
+ return try_val.call(val) if try_val.call(val)
21
+ else
22
+ raise ArgumentError
23
+ end
24
+ end
25
+ raise "No values was found"
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :user, :accepted_values
31
+
32
+ end
@@ -14,7 +14,7 @@ module OhMyLog
14
14
  end
15
15
 
16
16
  def to_s
17
- user_info = @sender.email rescue nil
17
+ user_info = PrintableUser.new(@sender, OhMyLog::Log.configuration.user_fields) rescue nil
18
18
  sender = user_info || Thread.current["remote_ip"]
19
19
  "#{@date}, #{sender}, #{@method}, #{@params}, #{@status}"
20
20
  end
@@ -61,7 +61,11 @@ module OhMyLog
61
61
  # end
62
62
 
63
63
  def retrive_public_ip
64
- Net::HTTP.get(URI("http://checkip.amazonaws.com")).gsub("\n", "") rescue nil
64
+ if Rails.env.test?
65
+ "127.0.0.1"
66
+ else
67
+ Net::HTTP.get(URI("http://checkip.amazonaws.com")).gsub("\n", "") rescue nil
68
+ end
65
69
  end
66
70
 
67
71
  def retrive_hostname
@@ -11,7 +11,7 @@ module SyslogProcessors
11
11
  def message_text(ip:, user:, url:, m:, s:, p:)
12
12
  text = "#{@tag.upcase}:"
13
13
  text += "ip=#{ip};"
14
- text += "u=#{user};"
14
+ text += "u=#{PrintableUser.new(user, OhMyLog::Log.configuration.user_fields) rescue "anonymous"};"
15
15
  text += "url=#{url};"
16
16
  text += "m=#{m};"
17
17
  text += "s=#{s};"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OhMyLog
4
- VERSION = '1.0.4'
4
+ VERSION = '1.0.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oh_my_log
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fabrizio Spadaro
@@ -202,6 +202,7 @@ files:
202
202
  - lib/oh_my_log/observer_factory.rb
203
203
  - lib/oh_my_log/orm/active_record.rb
204
204
  - lib/oh_my_log/orm/mongoid.rb
205
+ - lib/oh_my_log/printable_user.rb
205
206
  - lib/oh_my_log/request.rb
206
207
  - lib/oh_my_log/result.rb
207
208
  - lib/oh_my_log/selector.rb