alog 0.5.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -3
  3. data/lib/alog/version.rb +1 -1
  4. data/lib/alog.rb +43 -7
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb68bda881bc65ea41f76f45d895064fd657767ec5864aa0e480e6898b5e2de9
4
- data.tar.gz: f0c253638ba29c6c9bf2cb9a907a44ab67d05457a4d6f92d957bd1fbaeb1d1ce
3
+ metadata.gz: 43c7de3f9d98a68c65cabf1753dc625cc6c22ff67f949c597a59510e251c0535
4
+ data.tar.gz: 6ddad7d190c8b4af445bc0957673e9439b991cf62ea120b712c2f425a1b51eae
5
5
  SHA512:
6
- metadata.gz: 20819cf66b6adb5445b46daf7a41cc8fa6df89121ceb0e0af48580dc5599ec545f7cd44babd3878750d37118ad1d02bd21a6d555aece3fd7d7de0ac2a19ae5f7
7
- data.tar.gz: 28e749887907824ee69b429028fb523da81ace76f6f17f54ef1281fa3cbd38b566e63c9756371b3898d79f668cdf086668a94b7918a6d40874c8f6496fbf5b73
6
+ metadata.gz: f2d61ba517582eb874c8a79348f090b44fdc2cc3a729bc96879633b80f672a97fb27d4910b7c677bfcd9757f39b2fa937f114bc80c9c21c386bf2b281892bf42
7
+ data.tar.gz: 30d8ca5326ab13300f4c73b348fdf1a74e00e8ed00ff805fb82c2cc465117026002a4c9a54106dcb4109c6ac3552fa24ea44ebf9e03e5cbbca3bf95ca96edd7a
data/README.md CHANGED
@@ -50,6 +50,8 @@ class MyApp
50
50
  # Also multiple loggers can be configured by creating multiple keys
51
51
  LogFacts[:app_file] = ['app.log',10, 1024000]
52
52
  ...
53
+ # Or use the following method to add the log fact, which will check th existing key before adding
54
+ add_log_fact(:sys_file, ['sys.log', 10, 1024000])
53
55
 
54
56
  # STEP 2: Define which keys to activate
55
57
  # Any block/log output tagged by the key included in this array shall be printed
@@ -107,16 +109,23 @@ class MyApp
107
109
  def my_method2(p2)
108
110
  # Method 3 : Create the AOlogger object
109
111
  # AOlogger is meant to be proxy for standard Logger, with the tagging and multiple log engines included
110
- # The initialize parameter is an array containing key to the LogFacts above...
112
+ # The initialize parameter is an hash containing keys to configure the tagging and multi logging
113
+ #
111
114
  # In the following case, the AOlogger shall only configured to :stdout configuration (refers above)
112
- # and all logging shall be tagged with key :feature_m
113
- @log = AOlogger.new(:feature_m, [:stdout])
115
+ # and all logging shall be tagged with key :feature_m and active_tag is :global and :feature_m
116
+ # UNFORTUNATELY THIS WILL BREAK RELEASE VERSION < v0.6
117
+ @log = AOlogger.new({ key: :feature_m, logEng: [:stdout], active_tag: [:global, :feature_m] })
114
118
  ...
115
119
  ...
116
120
  # This behave like standard logging engine
117
121
  @log.debug "Code reached here..."
118
122
  @log.error "Oppss... We did it again!"
119
123
  ...
124
+ @log.deactivate_tag(:global) # disable :global tag from this point onwards
125
+ ...
126
+ ...
127
+ @log.activate_tag(:global) # enable :global tag from this point onwards
128
+ ...
120
129
  ...
121
130
  # this API is more explicit and replace all global values
122
131
  @log.log("this only shown if tag :feature_x is activated", :debug, :feature_x, [:app_file])
data/lib/alog/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Alog
2
- VERSION = "0.5.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/alog.rb CHANGED
@@ -16,6 +16,14 @@ module Alog
16
16
  # LogFacts entry given by application
17
17
  GLog = {}
18
18
 
19
+ def add_log_fact(key, conf)
20
+ # add new log fact to global if not defined
21
+ if LogFacts.include?(key)
22
+ else
23
+ LogFacts[key] = conf
24
+ end
25
+ end
26
+
19
27
  #
20
28
  # class Alogger
21
29
  # Inherited from standard library Logger
@@ -41,14 +49,36 @@ module Alog
41
49
  #
42
50
  class AOlogger
43
51
  attr_reader :logEng
44
- def initialize(key = :global, logEng = [])
45
- @myMethods = [:debug, :error, :warn, :warning]
46
- @defKey = key
47
- @logEng = logEng || []
52
+ # Major change on v1.0
53
+ #def initialize(key = :global, logEng = [], active_tag = LogTag)
54
+ def initialize(params = { key: :global, logEng: [], active_tag: LogTag } )
55
+ @myMethods = [:debug, :error, :warn, :warning, :info]
56
+ @defKey = params[:key]
57
+ @logEng = params[:logEng] || []
58
+ @activeTag = params[:active_tag] || []
59
+ end
60
+
61
+ def log(msg, ltype = :debug, key = :global, logEng = [], active_tag = [])
62
+ CondLog.call(msg, { key: (key == :global ? key : @defKey), type: ltype, logEng: (logEng == [] ? @logEng : logEng), active_tag: (active_tag == [] ? @active_tag : active_tag) })
63
+ end
64
+
65
+ def activate_tag(tag, &block)
66
+ @activeTag << tag
67
+ block.call if block
68
+ @activeTag.delete(tag)
69
+ end
70
+
71
+ def deactivate_tag(tag)
72
+ @activeTag.delete(tag)
48
73
  end
49
74
 
50
- def log(msg, ltype = :debug, key = :global, logEng = [])
51
- CondLog.call(msg, { key: key || @defKey, type: ltype, logEng: logEng || @logEng })
75
+ def ext_error(ex)
76
+ if ex.is_a?(Exception)
77
+ error(ex.message)
78
+ error(ex.backtrace.join("\n"))
79
+ else
80
+ error(ex)
81
+ end
52
82
  end
53
83
 
54
84
  def method_missing(mtd, *args, &block)
@@ -57,6 +87,7 @@ module Alog
57
87
  pa = args[1]
58
88
  params[:key] = @defKey
59
89
  params[:logEng] = @logEng
90
+ params[:active_tag] = @activeTag
60
91
  # TODO cases here may not be extensive to
61
92
  # the original Logger supported.
62
93
  case mtd
@@ -69,6 +100,9 @@ module Alog
69
100
  when :warn, :warning
70
101
  params[:type] = :warn
71
102
  CondLog.call(args[0], params, &block)
103
+ when :info
104
+ params[:type] = :info
105
+ CondLog.call(args[0], params, &block)
72
106
  end
73
107
 
74
108
  else
@@ -129,7 +163,9 @@ module Alog
129
163
  CondLog = Proc.new do |msg, params = {}, &block|
130
164
  key = params[:key] || :global
131
165
  type = params[:type] || :debug
132
- if defined?(:LogTag) and LogTag.is_a?(Array) and (LogTag.include?(key) or LogTag.include?(:all)) or type == :error
166
+ activeTag = params[:active_tag] || LogTag
167
+ #if defined?(:LogTag) and LogTag.is_a?(Array) and (LogTag.include?(key) or LogTag.include?(:all)) or type == :error
168
+ if (activeTag.include?(key) or activeTag.include?(:all)) or type == :error
133
169
  logEng = params[:logEng]
134
170
  if logEng == nil or (logEng != nil and logEng.empty?)
135
171
  logEng = (LogFacts.length > 0 ? [LogFacts.keys[0]] : [:default])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Liaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-20 00:00:00.000000000 Z
11
+ date: 2019-03-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler