uniq_logger 0.1.1 → 0.1.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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uniq_logger (0.1.0)
4
+ uniq_logger (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -9,9 +9,9 @@ module UniqLogger
9
9
  end
10
10
 
11
11
  def create(uniq_id, data_to_save=[])
12
- if config[:logfile_destination] == "local"
12
+ if config["logfile_destination"] == "local"
13
13
  create_local_log_entry(uniq_id, data_to_save)
14
- elsif config[:logfile_destination] == "remote"
14
+ elsif config["logfile_destination"] == "remote"
15
15
  create_remote_log_entry(uniq_id, data_to_save)
16
16
  else
17
17
  puts "logfile_destination is not set to [local,ftp]"
@@ -22,9 +22,9 @@ module UniqLogger
22
22
 
23
23
  def create_local_log_entry(uniq_id, data_to_save)
24
24
  #Use global Logger
25
- if config[:global_logger] == true
26
- raise "Directory of 'path_to_local_logfiles' '#{config[:path_to_local_logfiles]}' does not exist!" unless File.directory?(config[:path_to_local_logfiles])
27
- logfilename = File.join(config[:path_to_local_logfiles], config[:global_log_file_name])
25
+ if config["global_logger"] == true
26
+ raise "Directory of 'path_to_local_logfiles' '#{config["path_to_local_logfiles"]}' does not exist!" unless File.directory?(config["path_to_local_logfiles"])
27
+ logfilename = File.join(config["path_to_local_logfiles"], config["global_log_file_name"])
28
28
  logfile = File.open( File.expand_path(logfilename), "a" )
29
29
 
30
30
  if is_uniq_id_in_log_hostory?(uniq_id,logfile)
@@ -32,16 +32,16 @@ module UniqLogger
32
32
  end
33
33
 
34
34
  #write Data to Logfile File
35
- logfile.puts [uniq_id,data_to_save].flatten.join(config[:csv][:col_sep])
35
+ logfile.puts [uniq_id,data_to_save].flatten.join(config["csv"]["col_sep"])
36
36
  logfile.close
37
37
  end
38
38
 
39
39
  #Use Log Rotator?
40
- if ['day','month','year'].include?(config[:global_logger])
40
+ if ['day','month','year'].include?(config["global_logger"])
41
41
  logger_prefix = get_current_logger_prefix()
42
- rotator_logfilename = File.join(config[:path_to_local_logfiles], "#{config[:log_rotator_prefix]}#{logger_prefix}.log")
42
+ rotator_logfilename = File.join(config["path_to_local_logfiles"], "#{config['log_rotator_prefix']}#{logger_prefix}.log")
43
43
  rotator_logfile = File.open( File.expand_path(rotator_logfilename), "a" )
44
- rotator_logfile.puts [uniq_id,data_to_save].flatten.join(config[:csv][:col_sep])
44
+ rotator_logfile.puts [uniq_id,data_to_save].flatten.join(config["csv"]["col_sep"])
45
45
  rotator_logfile.close
46
46
  end
47
47
 
@@ -50,8 +50,8 @@ module UniqLogger
50
50
 
51
51
 
52
52
  def is_uniq_id_in_log_hostory?(uniq_id,logfile)
53
- if config[:validates_uniqness_of_id] == true
54
- data = CSV.read(logfile, {:col_sep => config[:csv][:col_sep], :encoding => config[:csv][:encoding] })
53
+ if config["validates_uniqness_of_id"] == true
54
+ data = CSV.read(logfile, {:col_sep => config["csv"]["col_sep"], :encoding => config["csv"]["encoding"] })
55
55
  list_of_ids = data.map{ |a| a[0]}
56
56
  #puts data
57
57
  if list_of_ids.include?(uniq_id)
@@ -62,7 +62,7 @@ module UniqLogger
62
62
  end
63
63
 
64
64
  def get_current_logger_prefix
65
- case config[:global_logger]
65
+ case config["global_logger"]
66
66
  when "day"
67
67
  filename_prefix = Time.now.strftime("%d-%m-%Y")
68
68
  when "month"
@@ -78,11 +78,11 @@ module UniqLogger
78
78
 
79
79
  def create_remote_log_entry(uniq_id, data_to_save)
80
80
  begin
81
- auth_token = config[:remote][:auth_token]
82
- server_name = config[:remote][:server]
83
- endpoint = config[:remote][:endpoint]
84
- param_id = config[:remote][:url_param_for_id]
85
- param_data = config[:remote][:url_param_for_data]
81
+ auth_token = config["remote"]["auth_token"]
82
+ server_name = config["remote"]["server"]
83
+ endpoint = config["remote"]["endpoint"]
84
+ param_id = config["remote"]["url_param_for_id"]
85
+ param_data = config["remote"]["url_param_for_data"]
86
86
 
87
87
  uri = URI.parse("#{server_name}#{endpoint}?auth_token=#{auth_token}")
88
88
  puts "URI: #{uri.inspect}"
@@ -90,8 +90,8 @@ module UniqLogger
90
90
  http = Net::HTTP.new(uri.host, uri.port)
91
91
  request = Net::HTTP::Post.new(uri.request_uri)
92
92
 
93
- if !config[:remote][:basic_auth][:username].nil? && !config[:remote][:basic_auth][:password].nil? && !config[:remote][:basic_auth][:username].empty? && !config[:remote][:basic_auth][:password].empty?
94
- request.basic_auth config[:remote][:basic_auth][:username], config[:remote][:basic_auth][:password]
93
+ if !config["remote"]["basic_auth"]["username"].nil? && !config["remote"]["basic_auth"]["password"].nil? && !config["remote"]["basic_auth"][:username].empty? && !config["remote"]["basic_auth"]["password"].empty?
94
+ request.basic_auth(config["remote"]["basic_auth"]["username"], config["remote"]["basic_auth"]["password"])
95
95
  end
96
96
 
97
97
  request.body = { param_id.to_sym => uniq_id, param_data.to_sym => data_to_save }.to_s
@@ -1,27 +1,27 @@
1
1
  module UniqLogger
2
2
  class Configuration
3
3
  @config = {
4
- :log_rotator => "none",
5
- :log_rotator_prefix => "uniq_logger-",
6
- :global_logger => true,
7
- :global_log_file_name => "uniq_logger.log",
8
- :validates_uniqness_of_id => true,
9
- :logfile_destination => "local",
10
- :path_to_local_logfiles => "log",
11
- :remote => {
12
- :auth_token => "xyz123abc",
13
- :server => "http://www.server.de",
14
- :endpoint => "/api/v1/logger",
15
- :url_param_for_id => "id",
16
- :url_param_for_data => "data",
17
- :basic_auth => {
18
- :username => "",
19
- :password => ""
4
+ "log_rotator" => "none",
5
+ "log_rotator_prefix" => "uniq_logger-",
6
+ "global_logger" => true,
7
+ "global_log_file_name" => "uniq_logger.log",
8
+ "validates_uniqness_of_id" => true,
9
+ "logfile_destination" => "local",
10
+ "path_to_local_logfiles" => "log",
11
+ "remote" => {
12
+ "auth_token" => "xyz123abc",
13
+ "server" => "http://www.server.de",
14
+ "endpoint" => "/api/v1/logger",
15
+ "url_param_for_id" => "id",
16
+ "url_param_for_data" => "data",
17
+ "basic_auth" => {
18
+ "username" => "",
19
+ "password" => ""
20
20
  }
21
21
  },
22
- :csv => {
23
- :encoding => "UTF8",
24
- :col_sep => ";"
22
+ "csv" => {
23
+ "encoding" => "UTF8",
24
+ "col_sep" => ";"
25
25
  }
26
26
  }
27
27
 
@@ -1,3 +1,3 @@
1
1
  module UniqLogger
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -10,20 +10,20 @@ end
10
10
  describe UniqLogger::Base do
11
11
  before(:each) do
12
12
  @logger = UniqLogger.new
13
- @logger.config[:global_log_file_name] = "rspec_logger.log"
13
+ @logger.config["global_log_file_name"] = "rspec_logger.log"
14
14
  #reset local Logfile
15
- @logfilename = File.join(@logger.config[:path_to_local_logfiles], @logger.config[:global_log_file_name])
15
+ @logfilename = File.join(@logger.config["path_to_local_logfiles"], @logger.config["global_log_file_name"])
16
16
  if File.exists?(@logfilename)
17
17
  File.delete( File.expand_path(@logfilename) )
18
18
  end
19
19
  end
20
20
 
21
21
  it 'has a valid configuration' do
22
- expect(@logger.config[:log_rotator]).to eq("none")
23
- expect(@logger.config[:global_logger]).to eq(true)
24
- expect(@logger.config[:csv][:encoding]).to eq("UTF8")
25
- expect(@logger.config[:csv][:col_sep]).to eq(";")
26
- expect(@logger.config[:logfile_destination]).to eq("local")
22
+ expect(@logger.config["log_rotator"]).to eq("none")
23
+ expect(@logger.config["global_logger"]).to eq(true)
24
+ expect(@logger.config["csv"]["encoding"]).to eq("UTF8")
25
+ expect(@logger.config["csv"]["col_sep"]).to eq(";")
26
+ expect(@logger.config["logfile_destination"]).to eq("local")
27
27
  end
28
28
 
29
29
  it 'should write a log to a logfile with validation of ID true' do
@@ -33,38 +33,38 @@ describe UniqLogger::Base do
33
33
  end
34
34
 
35
35
  it 'should write a log to a logfile with validation of ID false' do
36
- @logger.config[:validates_uniqness_of_id] = false
36
+ @logger.config["validates_uniqness_of_id"] = false
37
37
  expect(@logger.create("12345", ["Vorname", "Nachname", "Strasse"])).to eq(true)
38
38
  expect(@logger.create("12346", ["Vorname2", "Nachname2", "Strasse2"])).to eq(true)
39
39
  expect(@logger.create("12346", ["Vorname3", "Nachname3", "Strasse3"])).to eq(true)
40
40
  end
41
41
 
42
42
  it 'should write a log rotator to a logfile per day' do
43
- @logger.config[:global_logger] = "day"
43
+ @logger.config["global_logger"] = "day"
44
44
  expect(@logger.create("12345", ["Vorname", "Nachname", "Strasse"])).to eq(true)
45
45
  expect(@logger.create("12346", ["Vorname2", "Nachname2", "Strasse2"])).to eq(true)
46
46
  expect(@logger.create("12346", ["Vorname3", "Nachname3", "Strasse3"])).to eq(true)
47
47
  end
48
48
 
49
49
  it 'should write a log rotator to a logfile per month' do
50
- @logger.config[:global_logger] = "month"
50
+ @logger.config["global_logger"] = "month"
51
51
  expect(@logger.create("12345", ["Vorname", "Nachname", "Strasse"])).to eq(true)
52
52
  expect(@logger.create("12346", ["Vorname2", "Nachname2", "Strasse2"])).to eq(true)
53
53
  expect(@logger.create("12346", ["Vorname3", "Nachname3", "Strasse3"])).to eq(true)
54
54
  end
55
55
 
56
56
  it 'should write a log rotator to a logfile per year' do
57
- @logger.config[:global_logger] = "year"
57
+ @logger.config["global_logger"] = "year"
58
58
  expect(@logger.create("12345", ["Vorname", "Nachname", "Strasse"])).to eq(true)
59
59
  expect(@logger.create("12346", ["Vorname2", "Nachname2", "Strasse2"])).to eq(true)
60
60
  expect(@logger.create("12346", ["Vorname3", "Nachname3", "Strasse3"])).to eq(true)
61
61
  end
62
62
 
63
63
  it 'sould send data to remote api' do
64
- @logger.config[:logfile_destination] = "remote"
65
- @logger.config[:remote][:auth_token] = "QviQAtx1mq1ZCWC12RUy"
66
- @logger.config[:remote][:server] = "http://localhost:3000"
67
- @logger.config[:remote][:endpoint] = "/crm/api/v1/loggers.json"
64
+ @logger.config["logfile_destination"] = "remote"
65
+ @logger.config["remote"]["auth_token"] = "QviQAtx1mq1ZCWC12RUy"
66
+ @logger.config["remote"]["server"] = "http://localhost:3000"
67
+ @logger.config["remote"]["endpoint"] = "/crm/api/v1/loggers.json"
68
68
  expect(@logger.create("1111", ["Remote", "Server", "Strasse3"])).to eq(true)
69
69
  end
70
70
 
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uniq_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -114,6 +114,7 @@ files:
114
114
  - spec/lib/uniq_logger_spec.rb
115
115
  - spec/spec_helper.rb
116
116
  - template/uniq_logger.yml
117
+ - uniq_logger-0.1.1.gem
117
118
  - uniq_logger.gemspec
118
119
  homepage: https://github.com/ikuseiGmbH/uniq_logger
119
120
  licenses: