tag_logger 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1383db345a0b72da2a66bb213a7b66c3222d513b25b2c45077e3a1b28f3a8427
4
+ data.tar.gz: 18f14e9667504e9862abffb897d356e76b5ed0384e2629c2a135743c309e6b1f
5
+ SHA512:
6
+ metadata.gz: a4a0d4410c1086f3a24e6b1bc948b8f214915823fb92f17504cc23e5f025093e4f6067df6db237fd1e7d9544d835a795fe592e59b4d476ecbc1ef8bec103def3
7
+ data.tar.gz: 41a821b4c21315e5c4266ef73899b6ad4cddf3633a8e75771b3a815b0603d634d0bedec046efbcd8e8cd608d393de0ba6b85dc455bb74b5c21d2423928c0313f
@@ -0,0 +1,38 @@
1
+ TagLogger
2
+ ===========
3
+
4
+ TagLogger is a simple tool for tag logging.
5
+
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+ ```ruby
9
+ gem 'tag_logger'
10
+ ```
11
+
12
+ Or install it yourself as:
13
+ ```bash
14
+ $ gem install sample_filter
15
+ ```
16
+
17
+ ## Usage
18
+ First need to add configuration:
19
+ ```ruby
20
+ TagLogger.configure do |config|
21
+ config.output_path = "log/tag_logger.log"
22
+ end
23
+ ```
24
+
25
+ and then use logger:
26
+ ```ruby
27
+ class MyClass
28
+ include TagLogger
29
+
30
+ def my_method
31
+ # start logging with tags
32
+ tag_logger 'tag_name'
33
+
34
+ # then log with levels: [:warn, :info, :debug, :fatal, :error]
35
+ log :info, 'Log information'
36
+ end
37
+ end
38
+ ```
@@ -0,0 +1,16 @@
1
+ require 'tag_logger/helper_logger'
2
+ require 'tag_logger/configuration'
3
+
4
+ module TagLogger
5
+ def tag_logger(*tags)
6
+ @tag_logger ||= HelperLogger.new(tags)
7
+ end
8
+
9
+ def log(type, text)
10
+ if @tag_logger.nil?
11
+ raise 'Initialize `tag_logger` method with tags name'
12
+ else
13
+ @tag_logger.write_log(type, text)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module TagLogger
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Configuration.new
8
+ yield(configuration)
9
+ end
10
+
11
+ class Configuration
12
+ attr_accessor :output_path
13
+ end
14
+ end
@@ -0,0 +1,74 @@
1
+ module TagLogger
2
+ class HelperLogger
3
+ attr_reader :tags, :logger
4
+
5
+ def initialize(tags)
6
+ if tags.blank?
7
+ raise 'Tags for `tag_logger` are empty!'
8
+ else
9
+ @tags = tags
10
+ end
11
+
12
+ if TagLogger.configuration&.output_path.blank?
13
+ raise 'TagLogger configuration `output_path` is blank!'
14
+ else
15
+ @logger ||= Logger.new(TagLogger.configuration.output_path)
16
+ end
17
+ end
18
+
19
+ def write_log(type, text)
20
+ types = {
21
+ warn: WarnLogger,
22
+ info: InfoLogger,
23
+ debug: DebugLogger,
24
+ fatal: FatalLogger,
25
+ error: ErrorLogger
26
+ }
27
+
28
+ log_text = prepared_text(text)
29
+ logger_class = types.fetch(type)
30
+ logger_class.log(logger, log_text)
31
+ end
32
+
33
+ private
34
+
35
+ def prepared_text(text)
36
+ ''.tap do |s|
37
+ tags.each do |t|
38
+ s << ("[#{t}]" + ' ')
39
+ s << text if tags.last == t
40
+ end
41
+ end
42
+ end
43
+
44
+ class ErrorLogger
45
+ def self.log(logger, text)
46
+ logger.error(text)
47
+ end
48
+ end
49
+
50
+ class InfoLogger
51
+ def self.log(logger, text)
52
+ logger.info(text)
53
+ end
54
+ end
55
+
56
+ class WarnLogger
57
+ def self.log(logger, text)
58
+ logger.warn(text)
59
+ end
60
+ end
61
+
62
+ class DebugLogger
63
+ def self.log(logger, text)
64
+ logger.debug(text)
65
+ end
66
+ end
67
+
68
+ class FatalLogger
69
+ def self.log(logger, text)
70
+ logger.fatal(text)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module TagLogger
2
+ VERSION = '1.0.0'
3
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tag_logger
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - ilia_kg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: piryazevilia@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/tag_logger.rb
21
+ - lib/tag_logger/configuration.rb
22
+ - lib/tag_logger/helper_logger.rb
23
+ - lib/tag_logger/version.rb
24
+ homepage: https://github.com/iliakg/tag_logger
25
+ licenses:
26
+ - MIT
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubygems_version: 3.0.6
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Simple gem for tag logging
47
+ test_files: []