smarter_logging 1.0.4 → 1.1.0

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
- SHA1:
3
- metadata.gz: e793102aedb16d70480b3b012d9a220973f7ae4d
4
- data.tar.gz: 11d8c0d59dc0797adfb334a54f21615bd127eb14
2
+ SHA256:
3
+ metadata.gz: d3368892de277de3a81c961012a6d51d6a6d30f468b6916598bd8e2fa2564ef7
4
+ data.tar.gz: a0ed247b94a028dff86e853d3da83bcbec5b6118dcf311cce3e1e06fa57d08b6
5
5
  SHA512:
6
- metadata.gz: 16d8b4cb389c2b97fd84fffb14ba0dc70b2daca77510b76eae75aa9eb2d3a71ddcbf5e81982ce50ac48531a100c477ea12453185ced00ab887a4b5711926d3fd
7
- data.tar.gz: f2e0972a840b18c442270632f4601b798a8752bd2308cebd74bba1fcea767f0ae83dd7a5936437b502abfb109ad326c302ea78905d8d8a42dd7d7180994ef372
6
+ metadata.gz: f0371cb577efc53fec5f04b2821c9316968218c57265ac2e4244e1a924c1b82395b68e792b7db06bd5d86d1125e2ed32ed49177d6149196bf40beb9b83d2da81
7
+ data.tar.gz: 5b2cf5f99c35084d7a86398274946bfe707da8b238936a3eec29b64c7e27c5d6cc184016522af845c452bc732452b26e7f9c68e5ae8b41c1f38cb0ab69bc71ee
data/CHANGELOG.md ADDED
@@ -0,0 +1,28 @@
1
+ # SmarterLogging Change Log
2
+
3
+ ## 1.1.0 (2026-11-19)
4
+
5
+ ### New feature
6
+
7
+ - The request ID header is configurable: `SmarterLogging.request_id_header = 'X-Request-Id'`. Default: `'X-RQID'`. ([#2](https://github.com/tilo/smarter_logging/issues/2))
8
+
9
+ ### Bug fixes
10
+
11
+ - **Security:** `filter_parameters` are now matched like Rails does (partial, case-insensitive, Regexp and Proc entries). With the Rails 7+ defaults, keys like `password` and `api_key` were not filtered before.
12
+ - Fixed `NoMethodError` on Ruby 3.2+ when logging non-String values such as Integer, Float, Date or Time. ([#5](https://github.com/tilo/smarter_logging/issues/5))
13
+ - The request ID from an incoming `X-RQID` header is now used. Before, every request got a new request ID. ([#2](https://github.com/tilo/smarter_logging/issues/2))
14
+ - Fixed `NoMethodError` on Rails 5.1+ when a controller includes `SmarterLogging::ControllerHelper`.
15
+ - `error=` now contains the exception class and message, e.g. `error="ArgumentError : bad input"`. Before, it was empty.
16
+ - Fixed `NoMethodError` when the logged data contains an exception that was never raised.
17
+ - Creating loggers and logging now work without Rails. The `env` key is then not written.
18
+
19
+ ### Changes in the log output
20
+
21
+ - Values are quoted when they contain whitespace or `"`, for all types, e.g. `started_at="2014-09-15 10:00:00 UTC"`. Before, only Strings with whitespace were quoted.
22
+ - Inside quoted values, `\`, `"`, newline and carriage return are escaped as `\\`, `\"`, `\n` and `\r`, e.g. `msg="say \"hi\" now"`. Each log entry is now always one line.
23
+ - When an exception in an activity block is logged to the anomaly log, `anomaly=` now comes right after the standard keys.
24
+
25
+ ### Compatibility
26
+
27
+ - Rails 3.x is no longer supported.
28
+ - Added a dependency on the `logger` gem.
data/README.md CHANGED
@@ -1,24 +1,27 @@
1
1
  # SmarterLogging
2
2
 
3
- SmarterLogging helps you log mission critical data in key=value and single-line format, so it can be easily analyzed.
3
+ SmarterLogging helps you standardize the log format for your mission critical data in a single-line format, using either key=value format or JSON format, so it can be easily ingested for data analytics.
4
4
  The format lends itself to being easily importable by SumoLogic and Splunk.
5
5
 
6
+ Ingesting the Rails logger format in Splunk or Sumologic can be painful, because it is a multi-line format, and what you log from Rails is typically not standardized.
7
+
8
+ This gem is opinionated and adds standard fields, such at the UTC timestamp, durations, and a request ID, and helps separate "anomalies" from "activities".
6
9
  The main idea is to have dedicated log files for `activities` which happen during normal operations, as well as `anomalies` which happen when something unexpected happens.
7
10
 
8
- Each log line starts with a UTC timestamp in [ISO8601 format](https://en.wikipedia.org/wiki/ISO_8601), and contains space-separated key=value pairs. If a value contains spaces, it is quoted: `key="value"`.
11
+ When using the key=value format, each log line starts with a UTC timestamp in [ISO8601 format](https://en.wikipedia.org/wiki/ISO_8601), and contains space-separated key=value pairs. If a value contains spaces, it is quoted: `key="value"`.
9
12
  The advantage of ISO6801 timestamps is that they are both standardized / easy to parse, as well as human readable.
10
13
 
11
14
  time=2017-01-30T21:21:04.013Z activity=some_unique_name key1=value1 key2="value 2"
12
-
13
- The only place where this gem is opinionated is that UTC time is used for logging.
14
15
 
15
- **Tip:** If you are currently not using UTC time in your application, you should seriously consider doing that - it makes it much easier analyzing logs and errors when dealing with clients which can be anywhere in the world.
16
+ The only place where this gem is very opinionated is that UTC time is used for logging.
17
+
18
+ **Tip:** If you are currently not using UTC time in your application, you should seriously consider doing that - it makes it much easier analyzing logs and errors when dealing with clients and servers which can be anywhere in the world.
16
19
 
17
20
  Key goals:
18
21
 
19
22
  * get average call durations
20
23
  * get activity and anomaly logs
21
- * help forensics on any calls / trace incidents
24
+ * help forensics on any calls / trace incidents
22
25
  * quickly identify top anomalies
23
26
  * get timings for blocks of code
24
27
 
@@ -32,7 +35,7 @@ Add this line to your application's Gemfile:
32
35
 
33
36
  And then execute:
34
37
 
35
- $ bundle
38
+ $ bundle install
36
39
 
37
40
  Or install it yourself as:
38
41
 
@@ -40,12 +43,12 @@ Or install it yourself as:
40
43
 
41
44
  ## Usage
42
45
 
43
- When included in a Rails project, two default loggers are defined:
46
+ When included in a Rails project, two default loggers are defined:
44
47
 
45
48
  SmarterLogging.anomaly_logger
46
49
  SmarterLogging.activity_logger
47
50
 
48
- Each of them provides a `log()` method.
51
+ Each of them provides a `log()` method.
49
52
 
50
53
  As a shortcut, you can `include SmarterLogging` and do this:
51
54
 
@@ -54,6 +57,16 @@ As a shortcut, you can `include SmarterLogging` and do this:
54
57
 
55
58
  You can either use the above two functioncalls throughout your code, or include the module `SmarterLogging` and use the methods directly throughout your code.
56
59
 
60
+ ### Request ID (RQID)
61
+
62
+ When a controller includes `SmarterLogging::ControllerHelper`, each log line gets a `rqid` key. The RQID is read from the request header `X-RQID`, so services which call each other can pass on the RQID of the first call. If the header is missing or empty, a new random RQID is generated (`SecureRandom.hex(24)`).
63
+
64
+ To read the RQID from a different request header, set it in an initializer:
65
+
66
+ ```ruby
67
+ SmarterLogging.request_id_header = 'X-Request-Id'
68
+ ```
69
+
57
70
  ## Examples
58
71
 
59
72
  **Tip:** make sure that you use a globally unique naming convention for your anomaly and activity names -- this way you can pin-point what went wrong, and where it went wrong.
@@ -61,53 +74,53 @@ You can either use the above two functioncalls throughout your code, or include
61
74
  ### Logging Anomalies
62
75
  
Anomaly logs are meant to be used for errors, exceptions and caught unexpected behavior.
63
76
 
64
- include SmarterLogging
65
- 
 # you can use a single-line log statement, with a hash of all key=value pairs
66
- log_anomaly( :invalid_parameter , {key1: 'value 1', key2: 'value 2'}
67
-
68
- # or you can use a block - this will add a key `duration` to the log line.
69
-
70
-
71
- if parameters_valid?(params)
72
-
73
- # do something useful
74
-
75
- log_activity( :user_parameters, params )
76
-
77
- else
78
- log_anomaly( :user_invalid_parameters ) do |logdata|
79
- log_data.merge( invalid_parameter_hash )
80
-
81
- # some other code
82
-
83
- end
84
- end
85
-
86
-
87
-
77
+ ```ruby
78
+ 
 #require 'smarter_logging'
79
+ include SmarterLogging
80
+
81
+ # you can use a single-line log statement, with a hash of all key=value pairs
82
+ log_anomaly( :invalid_parameter , {key1: 'value 1', key2: 'value 2'}
83
+
84
+ if parameters_valid?(params)
85
+ # do something useful
86
+
87
+ log_activity( :user_parameters, params )
88
+
89
+ else
90
+ # or you can use a block - this will add a key `duration` to the log line.
91
+ log_anomaly( :user_invalid_parameters ) do |log_data|
92
+ log_data.merge( invalid_parameter_hash )
93
+
94
+ # some other code
95
+ end
96
+ end
97
+ ```
98
+
99
+
88
100
  ### Logging Activities
89
101
 
90
102
  Anomaly logs are meant to be used for reporting on expected behavior.
91
103
 
92
- include SmarterLogging
93
-
94
- # you can use a single-line log statement, with a hash of all key=value pairs
95
- log_activity( :user_signed_up, {user_id: current_user.id} )
96
- => time=2017-01-30T23:15:20.689Z env=development activity=user_signed_up user_id=123
97
-
98
- # or you can use a block - this will add a key `duration` to the log line.
99
- log_activity( :user_updated ) do |logdata|
100
- begin
101
-
102
- # update some values in user record here
103
-
104
- logdata[:result] = :sucess
105
- 
 rescue => e
106
- log_data[:error_message] = e.message
107
-
108
- logdata[:result] = :failure
109
- end
110
- end
104
+ ```ruby
105
+ require 'smarter_logging'
106
+ include SmarterLogging
107
+
108
+ # you can use a single-line log statement, with a hash of all key=value pairs
109
+ log_activity( :user_signed_up, {user_id: current_user.id} )
110
+ #=> time=2017-01-30T23:15:20.689Z env=development activity=user_signed_up user_id=123
111
+
112
+ # or you can use a block - this will add a key `duration` to the log line.
113
+ log_activity( :user_updated ) do |log_data|
114
+ begin
115
+ # update some values in user record here
116
+
117
+ 
 rescue log_data[:result] = :sucess
118
+ rescue => e
119
+ log_data[:error_message] = e.message
120
+ log_data[:result] = :failure
121
+ end
122
+ end
123
+ ```
111
124
 
112
125
  ## Development
113
126
 
@@ -9,7 +9,8 @@ module SmarterLogging
9
9
 
10
10
  def _log(data)
11
11
  # If activity logging broke, make sure we log it as an anomaly:
12
- data[:anomaly] = data.delete(:activity) if data[:activity]
12
+ # (keep anomaly= in the position of activity=, right after the standard keys)
13
+ data = {:anomaly => data.delete(:activity)}.merge( data ) if data[:activity]
13
14
  super
14
15
  end
15
16
  end
@@ -1,13 +1,16 @@
1
1
  require 'fileutils'
2
+ require 'logger'
2
3
 
3
4
  module SmarterLogging
4
5
  class BaseLogger
6
+ # characters which are escaped inside a quoted value, so each log entry stays on one line and can be parsed
7
+ ESCAPES = { '\\' => '\\\\', '"' => '\\"', "\n" => '\\n', "\r" => '\\r' }.freeze
5
8
 
6
9
  def initialize(log_filename)
7
10
  if defined?(Rails)
8
11
  log_filename = "#{Rails.root}/log/#{log_filename}"
9
12
  else
10
- FilUtils.mkdir './log'
13
+ FileUtils.mkdir_p './log'
11
14
  log_filename = "./log/#{log_filename}"
12
15
  end
13
16
  @logger = Logger.new(log_filename)
@@ -50,14 +53,14 @@ module SmarterLogging
50
53
  # lowest-level logging method:
51
54
  def _log(data)
52
55
  if exception = data.delete(:exception)
53
- data[:error] = [exception.class, exception.message].join[' : ']
54
- data[:backtrace] = exception.backtrace[0..5].join(' | ')
56
+ data[:error] = [exception.class, exception.message].join(' : ')
57
+ data[:backtrace] = exception.backtrace[0..5].join(' | ') if exception.backtrace
55
58
  end
56
59
 
57
60
  extra_data = {
58
61
  :time => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.%LZ"),
59
- :env => Rails.env,
60
62
  }
63
+ extra_data[:env] = Rails.env if defined?(Rails)
61
64
  SmarterLogging::ControllerHelper::KEYS.each do |key|
62
65
  extra_data[key] = Thread.current[key] if Thread.current[key]
63
66
  end
@@ -70,13 +73,10 @@ module SmarterLogging
70
73
  private
71
74
  # reformat incoming values, and make sure they are not listed in the Rails Filter Parameters
72
75
  def reformat(data)
73
- filtered_keys = Rails.application.config.filter_parameters.map{|x| x.to_s}
74
76
  result = []
75
- data.each do |k,v|
76
- if filtered_keys.include?(k.to_s)
77
- v = '[FILTERED]'
78
- elsif v =~ /\s/ # quote values with spaces
79
- v = "\"#{v}\""
77
+ filter(data).each do |k,v|
78
+ if v.to_s =~ /[\s"]/ # quote values with whitespace or double quotes
79
+ v = "\"#{v.to_s.gsub(/[\\"\n\r]/, ESCAPES)}\""
80
80
  end
81
81
 
82
82
  result << "#{k}=#{v}"
@@ -84,6 +84,19 @@ module SmarterLogging
84
84
  result.join(' ')
85
85
  end
86
86
 
87
+ # replace values of keys listed in Rails.application.config.filter_parameters with '[FILTERED]',
88
+ # using the same matching rules as Rails (partial, case-insensitive matches; Regexps; Procs)
89
+ def filter(data)
90
+ return data unless defined?(Rails)
91
+
92
+ filters = Rails.application.config.filter_parameters
93
+ if defined?(ActiveSupport::ParameterFilter)
94
+ ActiveSupport::ParameterFilter.new(filters).filter(data)
95
+ else # Rails < 6.0
96
+ ActionDispatch::Http::ParameterFilter.new(filters).filter(data)
97
+ end
98
+ end
99
+
87
100
  end
88
101
 
89
102
  end
@@ -3,13 +3,21 @@ module SmarterLogging
3
3
  module ControllerHelper
4
4
  KEYS = [:rqid, :ip, :user_agent]
5
5
 
6
+ # returns the request ID from the header named in SmarterLogging.request_id_header, or a new random one
7
+ # Rack stores a request header 'X-RQID' in the env as 'HTTP_X_RQID'
8
+ def self.request_id(request)
9
+ env_key = 'HTTP_' + SmarterLogging.request_id_header.to_s.upcase.tr('-', '_')
10
+ rqid = request.env[env_key]
11
+ (rqid.nil? || rqid.empty?) ? SecureRandom.hex(24) : rqid
12
+ end
13
+
6
14
  def self.included(base)
7
15
  base.class_eval do
8
- before_filter do
16
+ before_action do
9
17
  # Get some basic info from the current thread, and add it to the log parameters:
10
18
  # The RequestID RQID can be passed-in on subsequent API-calls,
11
19
  # so if several APIs call each other, they can be traced with the initial call's RQID
12
- Thread.current[:rqid] = request.headers['X_RQID'] || ::SmarterLogging::Extensions::String.random(24)
20
+ Thread.current[:rqid] = SmarterLogging::ControllerHelper.request_id(request)
13
21
  Thread.current[:ip] = request.remote_ip || request.ip
14
22
  Thread.current[:user_agent] = request.user_agent
15
23
  end
@@ -1,3 +1,3 @@
1
1
  module SmarterLogging
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -1,7 +1,5 @@
1
1
  require 'smarter_logging/version'
2
2
 
3
- require 'smarter_logging/extensions/string'
4
-
5
3
  require 'smarter_logging/base_logger'
6
4
  require 'smarter_logging/anomaly_logger'
7
5
  require 'smarter_logging/activity_logger'
@@ -9,7 +7,12 @@ require 'smarter_logging/controller_helper'
9
7
 
10
8
  require 'smarter_logging/railtie' if defined?(Rails)
11
9
 
10
+ require 'securerandom'
12
11
 
13
12
  module SmarterLogging
14
- # Your code goes here...
13
+ class << self
14
+ # name of the HTTP request header which carries the request ID (RQID) from a calling service
15
+ attr_accessor :request_id_header
16
+ end
17
+ self.request_id_header = 'X-RQID'
15
18
  end
@@ -14,6 +14,8 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/tilo/smarter_logging"
15
15
  spec.license = "MIT"
16
16
 
17
+ spec.metadata["changelog_uri"] = "https://github.com/tilo/smarter_logging/blob/master/CHANGELOG.md"
18
+
17
19
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
20
  f.match(%r{^(test|spec|features)/})
19
21
  end
@@ -21,7 +23,10 @@ Gem::Specification.new do |spec|
21
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
24
  spec.require_paths = ["lib"]
23
25
 
24
- spec.add_development_dependency "bundler", "~> 1.14"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_dependency "logger"
27
+
28
+ spec.add_development_dependency "bundler"
29
+ spec.add_development_dependency "activesupport", ">= 6.0"
30
+ spec.add_development_dependency "rake", ">= 12.3.3"
26
31
  spec.add_development_dependency "rspec", "~> 3.0"
27
32
  end
metadata CHANGED
@@ -1,104 +1,141 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smarter_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Tilo Sloboda
8
- autorequire:
7
+ - Tilo Sloboda
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2017-02-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  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.14'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.14'
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: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.0'
12
+ - !ruby/object:Gem::Dependency
13
+ name: logger
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "0"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: "0"
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ -
33
+ - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: "0"
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ -
41
+ - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ - !ruby/object:Gem::Dependency
45
+ name: activesupport
46
+ requirement: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ -
49
+ - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "6.0"
52
+ type: :development
53
+ prerelease: false
54
+ version_requirements: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ -
57
+ - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "6.0"
60
+ - !ruby/object:Gem::Dependency
61
+ name: rake
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ -
65
+ - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 12.3.3
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ -
73
+ - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 12.3.3
76
+ - !ruby/object:Gem::Dependency
77
+ name: rspec
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ -
81
+ - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: "3.0"
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ -
89
+ - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: "3.0"
55
92
  description: Ruby Gem for smarter logging of key=value data in single-line format
56
93
  email:
57
- - tilo.sloboda@gmail.com
94
+ - tilo.sloboda@gmail.com
58
95
  executables: []
59
96
  extensions: []
60
97
  extra_rdoc_files: []
61
98
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".travis.yml"
65
- - Gemfile
66
- - LICENSE.txt
67
- - README.md
68
- - Rakefile
69
- - bin/console
70
- - bin/setup
71
- - lib/smarter_logging.rb
72
- - lib/smarter_logging/activity_logger.rb
73
- - lib/smarter_logging/anomaly_logger.rb
74
- - lib/smarter_logging/base_logger.rb
75
- - lib/smarter_logging/controller_helper.rb
76
- - lib/smarter_logging/extensions/string.rb
77
- - lib/smarter_logging/railtie.rb
78
- - lib/smarter_logging/version.rb
79
- - smarter_logging.gemspec
80
- homepage: https://github.com/tilo/smarter_logging
99
+ - .gitignore
100
+ - .rspec
101
+ - .travis.yml
102
+ - CHANGELOG.md
103
+ - Gemfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - bin/console
108
+ - bin/setup
109
+ - lib/smarter_logging.rb
110
+ - lib/smarter_logging/activity_logger.rb
111
+ - lib/smarter_logging/anomaly_logger.rb
112
+ - lib/smarter_logging/base_logger.rb
113
+ - lib/smarter_logging/controller_helper.rb
114
+ - lib/smarter_logging/railtie.rb
115
+ - lib/smarter_logging/version.rb
116
+ - smarter_logging.gemspec
117
+ homepage: "https://github.com/tilo/smarter_logging"
81
118
  licenses:
82
- - MIT
83
- metadata: {}
84
- post_install_message:
119
+ - MIT
120
+ metadata:
121
+ changelog_uri: "https://github.com/tilo/smarter_logging/blob/master/CHANGELOG.md"
85
122
  rdoc_options: []
86
123
  require_paths:
87
- - lib
124
+ - lib
88
125
  required_ruby_version: !ruby/object:Gem::Requirement
89
126
  requirements:
90
- - - ">="
91
- - !ruby/object:Gem::Version
92
- version: '0'
127
+ -
128
+ - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: "0"
93
131
  required_rubygems_version: !ruby/object:Gem::Requirement
94
132
  requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: '0'
133
+ -
134
+ - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: "0"
98
137
  requirements: []
99
- rubyforge_project:
100
- rubygems_version: 2.5.2
101
- signing_key:
138
+ rubygems_version: 4.1.0
102
139
  specification_version: 4
103
140
  summary: Ruby Gem for smarter logging of key=value data
104
141
  test_files: []
@@ -1,36 +0,0 @@
1
- module SmarterLogging
2
- module Extensions
3
-
4
- module String # adding functionality without monkey patching String
5
-
6
- # Create a random String of given length, using given character set
7
- #
8
- # Character set is an Array which can contain Ranges, Arrays, Characters
9
- #
10
- # Examples
11
- #
12
- # String.random
13
- # String.random(10, ['0'..'9','A'..'F'] )
14
- # => "3EBF48AD3D"
15
- #
16
- # BASE64_CHAR_SET = ["A".."Z", "a".."z", "0".."9", '_', '-']
17
- # String.random(10, BASE64_CHAR_SET)
18
- # => "xM_1t3qcNn"
19
- #
20
- # SPECIAL_CHARS = ["!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "|", "/", "?", ".", ",", ";", ":", "~", "`", "[", "]", "{", "}", "<", ">"]
21
- # BASE91_CHAR_SET = ["A".."Z", "a".."z", "0".."9", SPECIAL_CHARS]
22
- # String.random(10, BASE91_CHAR_SET)
23
- # => "S(Z]z,J{v;"
24
- #
25
- # CREDIT: Tilo Sloboda
26
- #
27
- # SEE: https://gist.github.com/tilo/3ee8d94871d30416feba
28
-
29
- def self.random(len=32, character_set = ["A".."Z", "a".."z", "0".."9"])
30
- chars = character_set.map{|x| x.is_a?(Range) ? x.to_a : x }.flatten
31
- Array.new(len){ chars.sample }.join
32
- end
33
-
34
- end
35
- end
36
- end