logzomg 0.1.0.3.1 → 0.1.0.4

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
  SHA1:
3
- metadata.gz: 3edce9006c7d9c5d0fb96daa8671efffd8693819
4
- data.tar.gz: 177c2829fa844c7ce3cd52288b309281e34e183e
3
+ metadata.gz: 21f2c7611f4c1c92b251072d7e87d31d0cfae6fd
4
+ data.tar.gz: cdb1b149bd728805bab77d0e8b7aeb7247ce0f40
5
5
  SHA512:
6
- metadata.gz: e79975670e86e61d65629da16c9bc4c85971e111ccf469e756a38873c0b4a1b6a8037eabd9fdebda2b18c72b571efa4fc705038dc29de5c9fb54251d6893b69d
7
- data.tar.gz: 4f6872fa4d8085c88a5164cc64e62590fc578cf0dfe6588a9e086df0803b89628a1881452a743010b3c52b8df6dae853674424c413a29aa9c7b9e90a3acbc268
6
+ metadata.gz: 223066806ccaad8d66b95bd351f7dad256d30a34eb376de2d200b51c91caaf8aa7bf8f11d0b95f2da2edde044713def5ebfc6d8711905e2d40bf02a2ac10e7e3
7
+ data.tar.gz: 26adc2ac570d79416e88c36f853f0a34f7c5eb7e3e0e955dbd6346b50346697b810e2bb9d63d5a327e56633064bb78f78b48e6eadd01684308a7b3909b884406
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /logs/
11
+
12
+ /logzomg-*/
@@ -1,8 +1,5 @@
1
1
  require 'date'
2
2
 
3
- # Default TextFormatter for logzomg.rb
4
- # Allows color output to logfile
5
-
6
3
  class TextFormatter
7
4
  MAX_CHAR = 150
8
5
  MAX_CHAR_FLOAT = 145.00 # There's some problems with float decimal precision. Keep this 5 below MAX_CHAR
@@ -26,90 +23,49 @@ class TextFormatter
26
23
  # Prepend level. Append DateTime
27
24
  def format_msg(hash, level)
28
25
  @level = level # Log level
29
- str = "" # Final String we return. This is the one we add to
30
- str_keys_values = "" # One long String in format "key: value | key2: value2"
31
- s_msg = [] # Each index in this Array is the maximum allowed amount of chars on the screen
32
-
33
- str_keys_values += hash[:msg].to_s + " | " # Add msg first
34
-
35
- # We loop over every key in the hash and format the key/value in the string format we want
36
- hash.each do |key, value|
37
- if !key.to_s.eql?("level") && !key.to_s.eql?("msg") && !key.to_s.eql?("file")
38
- key = "#{add_color_key(key)} :" if with_color # Add color to keys if with_color is set to true
39
- str_keys_values += "#{key}: #{value} "
40
- end
41
- end
42
-
43
- s_msg = split_msg(str_keys_values) # Split message incase it's MAX_CHAR+ chars
44
-
26
+ str = "" # Final String we return. We keep appending to this
45
27
  count = 0 # Use to indent on 2nd+ iteration
46
28
 
29
+ str_keys_values = add_key_values_to_str(hash)
30
+ s_msg = split_msg(str_keys_values) # Split message incase it's MAX_CHAR+ chars
31
+
47
32
  s_msg.each do |n|
48
- str += add_msg_identifier(str)
49
- text = count >= 1 ? " " + n : n # Indent if 2nd+ iteration
50
- str += text
51
- indented = count >= 1 # Set indented to determine space amount
52
- str += right_align_date(n, hash, count+1, s_msg)
53
- str += " | " + add_date(count) + "\n"
33
+ str += count == 0 ? "#{add_log_level(str)}#{get_date} | " : "#{add_log_level(str)}"
34
+ str += count == 0 ? "#{n}\n" : " " * (get_date.length) + " | #{n}\n" # Indent if 2nd+ iteration
54
35
  count += 1
55
36
  end
56
-
57
37
  str
58
38
  end
59
39
 
60
-
61
40
  private
62
- def add_date(count)
41
+ def get_date
63
42
  date = short_date ? DateTime.now.strftime('%b-%e %H:%M:%S') : DateTime.now.to_s
64
- count > 0 ? "" : date
65
43
  end
66
44
 
67
- # Adds spaces to right align date depending on str length and row number
68
- #
69
- # Since we add colouring to each key we're adding invisible characters
70
- # Each colour adds 9 extra characters so we have to handle this
71
- def right_align_date(msg, hash, itr, full_msgs)
72
- extra = 0
73
- # If msg is first don't right_align since there's always a line 2
74
- if with_color
75
- if msg == full_msgs.first && full_msgs.size > 1 # Triggers on first line of multiline
76
- extra = 0
77
- elsif itr == 1 # Triggers on first itr if it's one-line with args
78
- extra = 9 * get_size(hash)
79
- elsif itr == full_msgs.length && get_size(hash) > 0 # Triggers on last line of multiline msg
80
- extra = 9
81
- end
82
- end
83
-
84
- s = itr > 1 ? MAX_CHAR - 2 : MAX_CHAR - 1
85
- " " * (s - msg.length + extra)
86
- end
45
+ # Creates a string with format "msg: "Blabla" | key: value key2: value2" we can split into array indices afterwards
46
+ def add_key_values_to_str(hash)
47
+ str_keys_values = "" # One long String in format
87
48
 
88
- # Returns size but without certain keys that wont be displayed
89
- def get_size(hash)
90
- size = 0
91
- hash.keys.each do |n|
92
- size += 1 unless n.to_s.eql?("file") || n.to_s.eql?("level") || n.to_s.eql?("msg")
49
+ str_keys_values += hash[:msg].to_s + " | " # Add msg first
50
+ # We loop over every key in the hash and format the key/value in the string format we want
51
+ hash.each do |key, value|
52
+ if !key.to_s.eql?("level") && !key.to_s.eql?("msg") && !key.to_s.eql?("file")
53
+ key = "#{add_color_key(key)}" if with_color # Add color to keys if with_color is set to true
54
+ str_keys_values += "#{key}: #{value} "
55
+ end
93
56
  end
94
- size
57
+ str_keys_values
95
58
  end
96
59
 
97
60
  # Adds log level to start of log
98
61
  # Add color if color is true
99
- def add_msg_identifier(str)
62
+ def add_log_level(str)
100
63
  # Need a check since debug has a different identifier than the rest
101
64
  str = @level == 'debug' ? 'DBUG' : @level[0..3].upcase
102
- str = add_color_level(str) if with_color
65
+ str = add_color_key(str) if with_color
103
66
  str += + " | "
104
67
  end
105
68
 
106
- # Adds color to level if color is true
107
- def add_color_level(str)
108
- close_color = "\e[0m"
109
- str.prepend("\033[" + COLORS[@level.to_sym] + "m")
110
- str += close_color
111
- end
112
-
113
69
  # Adds color to hash key
114
70
  def add_color_key(key)
115
71
  "\033[" + COLORS[@level.to_sym] + "m" + key.to_s + "\e[0m"
@@ -120,6 +76,6 @@ class TextFormatter
120
76
  def split_msg(msg)
121
77
  sub_end = MAX_CHAR - 5
122
78
  # Goes back to start of word if matches inside a word. If it matches inside a coloured key go back to start of word before colour
123
- msg.scan(/.{0,#{Regexp.escape(sub_end.to_s)}}[^\\033\[33m\]a-z\\e\[0m$a-z.!?,;](?:\b|$)/mi)
79
+ msg.scan(/.{0,#{Regexp.escape(sub_end.to_s)}}[^\\033\[0-90-9m\]\w\\e\[0m:\$](?:\ |$)/mi)
124
80
  end
125
81
  end
@@ -1,3 +1,3 @@
1
1
  module Logzomg
2
- VERSION = "0.1.0.3.1"
2
+ VERSION = "0.1.0.4"
3
3
  end
data/lib/logzomg.rb CHANGED
@@ -12,8 +12,7 @@ module Logzomg
12
12
  attr_accessor :log_path
13
13
 
14
14
  def initialize(**args, &block)
15
- # Set some default values
16
- @log_path = File.expand_path(get_path + '/log/')
15
+ @log_path = File.expand_path('../../logs/', __FILE__)
17
16
  @level = args[:level] ? args[:level] : "warning"
18
17
  @formatter = args[:formatter] ? args[:formatter] : TextFormatter.new {|f| f.with_color = true}
19
18
  if block_given?
@@ -60,6 +59,9 @@ module Logzomg
60
59
  "felis sit amet luctus vehicula, sapien est dictum lorem, nec blandit nunc mi id enim. Curabitur quis laoreet erat. Maecenas varius cursus blandit." +
61
60
  "Aliquam eleifend mauris ut nisl mollis, quis placerat nisi bibendum.",
62
61
  long: true,
62
+ what: true,
63
+ bugged: false,
64
+ nigga: "what",
63
65
  level: "debug"
64
66
  })
65
67
  self.log({
Binary file
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logzomg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.3.1
4
+ version: 0.1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rasmus
@@ -73,6 +73,8 @@ files:
73
73
  - lib/logzomg/version.rb
74
74
  - logzomg-0.1.0.1.gem
75
75
  - logzomg-0.1.0.2.gem
76
+ - logzomg-0.1.0.3.1.gem
77
+ - logzomg-0.1.0.3.gem
76
78
  - logzomg-0.1.0.gem
77
79
  - logzomg.gemspec
78
80
  homepage: https://github.com/Evilbits/logzomg