logzomg 0.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 +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +77 -0
- data/Rakefile +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/formatters/text_formatter.rb +81 -0
- data/lib/logzomg/version.rb +3 -0
- data/lib/logzomg.rb +84 -0
- data/logzomg.gemspec +35 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c62b72556a339925393753589f92925d63347584
|
4
|
+
data.tar.gz: 11dedeeb8b5f4bc2d36c821aeff053228ab66497
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d029c7328cc8ea4373fc1b1bc2c143cd6018a87f4ed10a4e53a963ceb0eccbd0c6d11c02348636f0e1c857fce4b32305b0bbfd842cbdd7480cde596de0de158
|
7
|
+
data.tar.gz: 43d4917e4f3df95db18d322e672aed5c095d76489bf485e8e0a6b79be654ed3c68253eda029beedba49dc4c18f27d7d8a429de64e98f2113fd694f124830879e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Rasmus
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Logzomg
|
2
|
+
|
3
|
+
**Logzomg is still in development. Do not expect crazy functionality yet :)**
|
4
|
+
|
5
|
+
An easy to use and lightweight logging gem for Ruby.
|
6
|
+
|
7
|
+

|
8
|
+
|
9
|
+
Logzomg currently supports varying levels of severity.
|
10
|
+
|
11
|
+
`
|
12
|
+
Debug
|
13
|
+
`
|
14
|
+
`
|
15
|
+
Info
|
16
|
+
`
|
17
|
+
`
|
18
|
+
Warn
|
19
|
+
`
|
20
|
+
`
|
21
|
+
Error
|
22
|
+
`
|
23
|
+
`
|
24
|
+
Fatal
|
25
|
+
`
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
You can instantiate the logger and use it like so:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
def log
|
33
|
+
l = Logzomg::Logger.new
|
34
|
+
l.log({
|
35
|
+
"msg": "Frank took the last coffee and forgot to make some new. Fire him?",
|
36
|
+
"level": "info", # Optional. Sets log level. Default is warning
|
37
|
+
"file": "frank.txt" # Optional. Sets name of file to log to. Default is log.txt
|
38
|
+
})
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
By default Logzomg color codes the logging levels when viewed in a terminal. If you want to turn this off you can instead pass a TextFormatter when instantiating the logger.
|
43
|
+
|
44
|
+
The TextFormatter takes a hash of options.
|
45
|
+
|
46
|
+
`
|
47
|
+
Logzomg::Logger.new(TextFormatter.new({with_colors: false}))
|
48
|
+
`
|
49
|
+
|
50
|
+
Currently Logzomg only supports logging as plaintext. Soon it will support logging as JSON as well.
|
51
|
+
|
52
|
+
|
53
|
+
## Installation
|
54
|
+
|
55
|
+
Add this line to your application's Gemfile:
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
gem 'logzomg'
|
59
|
+
```
|
60
|
+
|
61
|
+
And then execute:
|
62
|
+
|
63
|
+
$ bundle
|
64
|
+
|
65
|
+
Or install it yourself as:
|
66
|
+
|
67
|
+
$ gem install logzomg
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Evilbits/logzomg
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "logzomg"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'date'
|
2
|
+
|
3
|
+
# Default TextFormatter for logzomg.rb
|
4
|
+
# Allows color output to logfile
|
5
|
+
|
6
|
+
class TextFormatter
|
7
|
+
|
8
|
+
def initialize(init_hash = Hash.new)
|
9
|
+
@color = init_hash.has_key?(:with_color) ? init_hash[:with_color] : true
|
10
|
+
puts "Init color: " + @color.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
# Split the message into 145 char chunks.
|
14
|
+
# Prepend level. Append DateTime
|
15
|
+
def format_msg(msg, level)
|
16
|
+
@level = level
|
17
|
+
str = ""
|
18
|
+
s_msg = split_msg(msg) # Split message incase it's 150+ chars
|
19
|
+
count = 0 # Use to indent on 2nd+ iteration
|
20
|
+
|
21
|
+
s_msg.each do |n|
|
22
|
+
str += add_msg_identifier(str)
|
23
|
+
text = count >= 1 ? " " + n : n # Indent if 2nd+ iteration
|
24
|
+
str += text
|
25
|
+
indented = count >= 1 # Set indented to determine space amount
|
26
|
+
str += right_align_date(n, indented)
|
27
|
+
str += " | " + DateTime.now.to_s + "\n"
|
28
|
+
count += 1
|
29
|
+
end
|
30
|
+
|
31
|
+
str
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
private
|
36
|
+
# Adds spaces to right align date depending on str length and row number
|
37
|
+
def right_align_date(msg, indented)
|
38
|
+
indented ? s = 60 : s = 58
|
39
|
+
" " * (s - msg.length)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Adds log level to start of log
|
43
|
+
# Add color if color is true
|
44
|
+
def add_msg_identifier(str)
|
45
|
+
if @level == 'debug'
|
46
|
+
str += "DBUG"
|
47
|
+
elsif @level == 'info'
|
48
|
+
str += "INFO"
|
49
|
+
elsif @level == 'warning'
|
50
|
+
str += "WARN"
|
51
|
+
elsif @level == 'error'
|
52
|
+
str += "ERRO"
|
53
|
+
elsif @level == 'fatal'
|
54
|
+
str += "FATA"
|
55
|
+
end
|
56
|
+
str = add_color(str) if @color
|
57
|
+
str += + " | "
|
58
|
+
end
|
59
|
+
|
60
|
+
# Adds color if color is true
|
61
|
+
def add_color(str)
|
62
|
+
colors = {debug: "\e[34m", info: "\e[96m", warning: "\e[33m", error: "\e[91m", fatal: "\e[31m"}
|
63
|
+
close_color = "\e[0m"
|
64
|
+
str.prepend(colors[@level.to_sym])
|
65
|
+
str += close_color
|
66
|
+
end
|
67
|
+
|
68
|
+
# Splits the message every 150 chars to make everything look prettier
|
69
|
+
def split_msg(msg)
|
70
|
+
arr = []
|
71
|
+
start = 0
|
72
|
+
ending = 145
|
73
|
+
c = msg.length > 150 ? ((msg.length).to_f/150.00).ceil : 1
|
74
|
+
(1..c).each do |n|
|
75
|
+
arr << msg[start,ending]
|
76
|
+
start += 146
|
77
|
+
ending += 145
|
78
|
+
end
|
79
|
+
arr
|
80
|
+
end
|
81
|
+
end
|
data/lib/logzomg.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
require_relative 'formatters/text_formatter'
|
2
|
+
require "logzomg/version"
|
3
|
+
|
4
|
+
module Logzomg
|
5
|
+
class Logger
|
6
|
+
# TODO change this to proper file path
|
7
|
+
LOG_PATH = File.expand_path('../../logs/', __FILE__)
|
8
|
+
LEVELS = ['debug','info','warning','error','fatal']
|
9
|
+
|
10
|
+
UnsupportedType = Class.new(StandardError)
|
11
|
+
UnsupportedLevel = Class.new(StandardError)
|
12
|
+
|
13
|
+
def initialize(formatter=TextFormatter.new)
|
14
|
+
@level = 'warning'
|
15
|
+
@formatter = formatter
|
16
|
+
end
|
17
|
+
|
18
|
+
# First set level ->
|
19
|
+
# Format message ->
|
20
|
+
# Write message to file
|
21
|
+
def log(hash)
|
22
|
+
raise UnsupportedType, "Must be of type Hash" unless valid_hash?(hash)
|
23
|
+
level(hash[:level]) if hash.has_key?(:level) # Use default if not included
|
24
|
+
msg = @formatter.format_msg(hash[:msg], @level)
|
25
|
+
write(hash, msg)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Sets the log level
|
29
|
+
def level(level)
|
30
|
+
raise UnsupportedLevel, "Level " + level + " is not a valid level" unless valid_level?(level)
|
31
|
+
@level = level
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
# REMOVE AFTER DONE CODING
|
36
|
+
def test
|
37
|
+
l = Logzomg::Logger.new
|
38
|
+
l.log({
|
39
|
+
"msg": "Something is on the horizon!",
|
40
|
+
"level": "debug"
|
41
|
+
})
|
42
|
+
#l.log({
|
43
|
+
# "msg": "This is a really really really really really really really really really " +
|
44
|
+
# "really really really really really really really really really really really " +
|
45
|
+
# "really really really really really really debug message",
|
46
|
+
# "level": "debug"
|
47
|
+
# })
|
48
|
+
l.log({
|
49
|
+
"msg": "Three wild acro-yoga enthusiasts have been spotted!",
|
50
|
+
"level": "info"
|
51
|
+
})
|
52
|
+
l.log({
|
53
|
+
"msg": "They are coming closer!",
|
54
|
+
"level": "warning"
|
55
|
+
})
|
56
|
+
l.log({
|
57
|
+
"msg": "I don\'t know how to handle them!!",
|
58
|
+
"level": "error"
|
59
|
+
})
|
60
|
+
l.log({
|
61
|
+
"msg": "You have died",
|
62
|
+
"level": "fatal"
|
63
|
+
})
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
# Writes the log message to the logfile
|
68
|
+
# If given one in hash[:file] use that
|
69
|
+
def write(hash, msg)
|
70
|
+
file = hash.has_key?(:file) ? "/" + hash[:file] : '/log.txt'
|
71
|
+
File.open(LOG_PATH + file, 'a') {|f| f.write(msg) }
|
72
|
+
end
|
73
|
+
|
74
|
+
# Checks if message is hash
|
75
|
+
def valid_hash?(hash)
|
76
|
+
return hash.class == Hash
|
77
|
+
end
|
78
|
+
|
79
|
+
# Checks if the level value is valid (part of LEVELS)
|
80
|
+
def valid_level?(level)
|
81
|
+
return !level.nil? && LEVELS.any? { |l| l == level.downcase }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/logzomg.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'logzomg/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "logzomg"
|
8
|
+
spec.version = Logzomg::VERSION
|
9
|
+
spec.authors = ["Rasmus"]
|
10
|
+
spec.email = ["Rasmusbreiler@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Logging gem with Asana API integration}
|
13
|
+
spec.homepage = "https://github.com/Evilbits/logzomg"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
22
|
+
"public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logzomg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rasmus
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
12
|
+
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.13'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.13'
|
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'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- Rasmusbreiler@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
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/formatters/text_formatter.rb
|
72
|
+
- lib/logzomg.rb
|
73
|
+
- lib/logzomg/version.rb
|
74
|
+
- logzomg.gemspec
|
75
|
+
homepage: https://github.com/Evilbits/logzomg
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata:
|
79
|
+
allowed_push_host: https://rubygems.org
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.4.8
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Logging gem with Asana API integration
|
100
|
+
test_files: []
|