shlog 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/bin/shlog +12 -0
- data/lib/shlog.rb +18 -0
- data/lib/shlog/basic_cli.rb +100 -0
- data/lib/shlog/cli.rb +52 -0
- data/lib/shlog/commands/log.rb +84 -0
- data/lib/shlog/version.rb +4 -0
- data/shlog.gemspec +25 -0
- data/shlogrc +8 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 88d4f7c4779c663d196b5ab7dad8c4f61942a366
|
4
|
+
data.tar.gz: a1613136dd2cf415dc562fe2d8f8b08d1f997c1a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9805e79a7e801bc11c2afb795bc48a982de83e050832680c325059ed3c43cfc390d575e6510bac8521eb1c953139949081e1f7535ba314fe617e5ea895625919
|
7
|
+
data.tar.gz: 67e49a17d773f53d81ceb8669ab378a1d0a6d18f0e6b8bbc7bad938ea567cc474e126df5252f16c9b4f1bb5043d3c7d3757ae21123ed6de29ea99136d2fa2547
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Aziz Light
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
shlog
|
2
|
+
=====
|
3
|
+
|
4
|
+
A wrapper around [lumberjack](https://github.com/bdurand/lumberjack) to make logging on the command line easier.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
From the command-line:
|
10
|
+
|
11
|
+
```
|
12
|
+
> shlog help
|
13
|
+
```
|
14
|
+
|
15
|
+
Or from any shell script:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
shlog log "Ruby is Awesome!"
|
19
|
+
```
|
20
|
+
|
21
|
+
Configuration
|
22
|
+
-------------
|
23
|
+
|
24
|
+
TODO: Document this!
|
25
|
+
|
26
|
+
Contributing
|
27
|
+
------------
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
34
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/bin/shlog
ADDED
data/lib/shlog.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# Require dev shit
|
2
|
+
if ENV["DEV_MODE"] == "debug"
|
3
|
+
require "ap" rescue nil
|
4
|
+
end
|
5
|
+
|
6
|
+
# Require Standard Library shit
|
7
|
+
require "psych"
|
8
|
+
require "erb"
|
9
|
+
|
10
|
+
# Require gems shit
|
11
|
+
require "gli"
|
12
|
+
require "rainbow/ext/string"
|
13
|
+
require "lumberjack"
|
14
|
+
|
15
|
+
# Require personal shit
|
16
|
+
require_relative "./shlog/version"
|
17
|
+
require_relative "./shlog/basic_cli"
|
18
|
+
require_relative "./shlog/cli"
|
@@ -0,0 +1,100 @@
|
|
1
|
+
module Shlog
|
2
|
+
module BasicCLI
|
3
|
+
def self.included(mod)
|
4
|
+
mod.class_eval do
|
5
|
+
extend GLI::App
|
6
|
+
|
7
|
+
const_set(:CONFIG_FILE_NAME, "shlogrc")
|
8
|
+
|
9
|
+
const_set(:CONFIG_FILES, [
|
10
|
+
File.expand_path(File.join(File.dirname(File.realpath(__FILE__)), "..", "..", const_get(:CONFIG_FILE_NAME))),
|
11
|
+
File.join(ENV["HOME"], ".#{const_get(:CONFIG_FILE_NAME)}"),
|
12
|
+
File.join(Dir.getwd, ".#{const_get(:CONFIG_FILE_NAME)}")
|
13
|
+
])
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :cli_command
|
17
|
+
|
18
|
+
def cli_defaults
|
19
|
+
@cli_defaults ||= Hash.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def cli_defaults=(value)
|
23
|
+
@cli_defaults = value
|
24
|
+
end
|
25
|
+
|
26
|
+
def config_to_options_for(command, config)
|
27
|
+
self.cli_command ||= command
|
28
|
+
|
29
|
+
setup_cli!
|
30
|
+
|
31
|
+
config.each do |k, v|
|
32
|
+
base_option_name = base_option_name_for(k, @cli_options[:list])
|
33
|
+
|
34
|
+
@cli_options[:list][base_option_name].each do |f|
|
35
|
+
@cli_options[:values][f] = v
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@cli_options.fetch(:values)
|
40
|
+
end
|
41
|
+
|
42
|
+
def setup_cli!
|
43
|
+
raise RuntimeError, "Command not set!" unless cli_command
|
44
|
+
|
45
|
+
unless @cli_options
|
46
|
+
@cli_options = { list: Hash.new, values: Hash.new }
|
47
|
+
|
48
|
+
flags_array = cli_command.flags.map(&:last).map { |f| [f.name, f.aliases].flatten }
|
49
|
+
flags_array.each do |o|
|
50
|
+
@cli_options[:list][o.first.to_sym] = [o.map(&:to_sym), o.map(&:to_s)].flatten.compact unless @cli_options.fetch(:list).has_key?(o.first.to_sym)
|
51
|
+
|
52
|
+
o.each do |oo|
|
53
|
+
@cli_options[:values][oo.to_sym] = nil unless @cli_options.fetch(:values).has_key?(oo.to_sym)
|
54
|
+
@cli_options[:values][oo.to_s] = nil unless @cli_options.fetch(:values).has_key?(oo.to_s)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
switches_array = cli_command.switches.map(&:last).map { |s| [s.name, s.aliases].flatten.compact }
|
59
|
+
switches_array.each do |o|
|
60
|
+
@cli_options[:list][o.first.to_sym] = [o.map(&:to_sym), o.map(&:to_s)].flatten.compact unless @cli_options.fetch(:list).has_key?(o.first.to_sym)
|
61
|
+
|
62
|
+
o.each do |oo|
|
63
|
+
@cli_options[:values][oo.to_sym] = false unless @cli_options.fetch(:values).has_key?(oo.to_sym)
|
64
|
+
@cli_options[:values][oo.to_s] = false unless @cli_options.fetch(:values).has_key?(oo.to_s)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def base_option_name_for(option, option_list)
|
71
|
+
name = nil
|
72
|
+
|
73
|
+
option_list.each do |n, o|
|
74
|
+
if o.include?(option)
|
75
|
+
name = n
|
76
|
+
break
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
name
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def self.set_default_options!
|
87
|
+
config_file = const_get(:CONFIG_FILES).first
|
88
|
+
|
89
|
+
if File.exists?(config_file) && File.readable?(config_file)
|
90
|
+
config = Psych.load(ERB.new(IO.read(config_file)).result)
|
91
|
+
else
|
92
|
+
config = {}
|
93
|
+
end
|
94
|
+
|
95
|
+
self.cli_defaults = config["commands"]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
data/lib/shlog/cli.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
module Shlog
|
2
|
+
class CLI
|
3
|
+
include Shlog::BasicCLI
|
4
|
+
|
5
|
+
program_desc "Command-line logging made easy"
|
6
|
+
version Shlog::VERSION
|
7
|
+
|
8
|
+
desc "Path to the config file to use"
|
9
|
+
arg_name "FILE"
|
10
|
+
flag [:config]
|
11
|
+
|
12
|
+
set_default_options!
|
13
|
+
commands_from File.expand_path(File.join(File.dirname(File.realpath(__FILE__)), "commands"))
|
14
|
+
|
15
|
+
pre do |global, command, options, args|
|
16
|
+
config_files = CONFIG_FILES
|
17
|
+
default_config_file = config_files.shift
|
18
|
+
|
19
|
+
if global[:config]
|
20
|
+
# If a config file is explicitely specified, it MUST exist!
|
21
|
+
unless File.exists?(global[:config])
|
22
|
+
raise RuntimeError, "Unable to find config file: #{global[:config]}"
|
23
|
+
end
|
24
|
+
|
25
|
+
config_files << global[:config]
|
26
|
+
end
|
27
|
+
|
28
|
+
config_files.each do |cf|
|
29
|
+
begin
|
30
|
+
next unless File.exists?(cf) && File.readable?(cf)
|
31
|
+
|
32
|
+
config = Psych.load(ERB.new(IO.read(cf)).result)
|
33
|
+
options.merge!(config_to_options_for(command, config["commands"][command.name.to_sym]))
|
34
|
+
|
35
|
+
# TODO: Add a flag to skip other config files, maybe?
|
36
|
+
rescue => e
|
37
|
+
raise RuntimeError, "Unable to load config from '#{cf}': #{e.message}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
options.merge!(options[:cli])
|
42
|
+
|
43
|
+
true
|
44
|
+
end
|
45
|
+
|
46
|
+
on_error do |exception|
|
47
|
+
puts exception.message.color(:red)
|
48
|
+
|
49
|
+
false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Shlog
|
2
|
+
class CLI
|
3
|
+
desc "Add a log entry"
|
4
|
+
arg_name "MESSAGE"
|
5
|
+
command :log do |c|
|
6
|
+
c.desc "Name of the program that is logging the message"
|
7
|
+
c.arg_name "PROGNAME"
|
8
|
+
c.flag [:p, :progname], must_match: /\A[a-zA-Z0-9_.-]+\Z/
|
9
|
+
|
10
|
+
c.desc "Level of severity"
|
11
|
+
c.default_value self.cli_defaults[:log][:level]
|
12
|
+
c.arg_name "LEVEL"
|
13
|
+
c.flag [:l, :level], must_match: /\A[a-zA-Z0-9]+\Z/
|
14
|
+
|
15
|
+
c.desc "Path to the log file"
|
16
|
+
c.long_desc <<-DESC
|
17
|
+
Directory of the log file (without the name).
|
18
|
+
The directory does not have to exist.
|
19
|
+
DESC
|
20
|
+
c.default_value self.cli_defaults[:log][:directory]
|
21
|
+
c.arg_name "DIRECTORY"
|
22
|
+
c.flag [:d, :directory]
|
23
|
+
|
24
|
+
c.desc "Name of the log file"
|
25
|
+
c.long_desc <<-DESC
|
26
|
+
Name of the log file (without the path).
|
27
|
+
The file does not have to exist and the
|
28
|
+
`.log` extension is not required.
|
29
|
+
DESC
|
30
|
+
c.default_value self.cli_defaults[:log][:file]
|
31
|
+
c.arg_name "FILE"
|
32
|
+
c.flag [:f, :file]
|
33
|
+
|
34
|
+
c.desc "The maximum size of the log file"
|
35
|
+
c.long_desc <<-DESC
|
36
|
+
This size represents the number of log entries in the log file.
|
37
|
+
If the size of the log file has reached the maximum value, it will
|
38
|
+
be "archived" and a new log file will be created. The new log entry
|
39
|
+
will then go in the new log file.
|
40
|
+
DESC
|
41
|
+
c.default_value self.cli_defaults[:log][:"max-size"]
|
42
|
+
c.arg_name "SIZE"
|
43
|
+
c.flag [:s, :"max-size"], must_match: /\A[0-9]+\Z/
|
44
|
+
|
45
|
+
c.desc "Enable colors"
|
46
|
+
c.switch :colors, default: false
|
47
|
+
|
48
|
+
c.desc "Vebose mode"
|
49
|
+
c.switch :v, :verbose, default: false
|
50
|
+
|
51
|
+
c.desc "Get the path to the log file"
|
52
|
+
c.switch :g, :"get-logfile", default: false, negatable: false
|
53
|
+
|
54
|
+
c.action do |global_options, options, args|
|
55
|
+
file = File.join(File.expand_path(options[:directory]), options[:file])
|
56
|
+
|
57
|
+
if options[:"get-logfile"]
|
58
|
+
# NOTE: All the options are ignored when the '--get-logfile' options is passed
|
59
|
+
|
60
|
+
puts file
|
61
|
+
else
|
62
|
+
if args.empty?
|
63
|
+
raise ArgumentError, "Cannot add a log entry without a message"
|
64
|
+
end
|
65
|
+
|
66
|
+
template = lambda do |e|
|
67
|
+
t = "[#{e.time} #{e.severity_label}"
|
68
|
+
t << " (#{e.progname})" if e.progname
|
69
|
+
t << "] #{e.message}"
|
70
|
+
t
|
71
|
+
end
|
72
|
+
|
73
|
+
logger = Lumberjack::Logger.new(file, time_format: "%m/%d/%Y %H:%M:%S", template: template, max_size: options[:"max-size"])
|
74
|
+
logger.progname = options[:progname]
|
75
|
+
logger.send(options[:level].to_s.downcase, args.join(" "))
|
76
|
+
|
77
|
+
if options[:verbose]
|
78
|
+
puts "Log entry added".color(:green)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/shlog.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative "./lib/shlog/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "shlog"
|
5
|
+
spec.version = Shlog::VERSION
|
6
|
+
spec.authors = ["Aziz Light"]
|
7
|
+
spec.email = ["aziz@azizlight.me"]
|
8
|
+
spec.description = %q{A wrapper around lumberjack (https://github.com/bdurand/lumberjack) to make logging on the command line easier.}
|
9
|
+
spec.summary = %q{Command-line logging made easy}
|
10
|
+
spec.homepage = "https://github.com/AzizLight/shlog"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files`.split($/)
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.bindir = "bin"
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
19
|
+
spec.add_development_dependency "rake"
|
20
|
+
spec.add_development_dependency "awesome_print"
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "gli_aziz_light"
|
23
|
+
spec.add_runtime_dependency "rainbow"
|
24
|
+
spec.add_runtime_dependency "lumberjack"
|
25
|
+
end
|
data/shlogrc
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shlog
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aziz Light
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-12 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.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: awesome_print
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: gli_aziz_light
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rainbow
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: lumberjack
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: A wrapper around lumberjack (https://github.com/bdurand/lumberjack) to
|
98
|
+
make logging on the command line easier.
|
99
|
+
email:
|
100
|
+
- aziz@azizlight.me
|
101
|
+
executables:
|
102
|
+
- shlog
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- .gitignore
|
107
|
+
- Gemfile
|
108
|
+
- LICENSE
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- VERSION
|
112
|
+
- bin/shlog
|
113
|
+
- lib/shlog.rb
|
114
|
+
- lib/shlog/basic_cli.rb
|
115
|
+
- lib/shlog/cli.rb
|
116
|
+
- lib/shlog/commands/log.rb
|
117
|
+
- lib/shlog/version.rb
|
118
|
+
- shlog.gemspec
|
119
|
+
- shlogrc
|
120
|
+
homepage: https://github.com/AzizLight/shlog
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.0.14
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Command-line logging made easy
|
144
|
+
test_files: []
|