bixby-common 0.6.6 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bixby-common.gemspec +3 -3
- data/lib/bixby-common/util/log.rb +81 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89822f2ea4d08e7cbb1ae43e46f272c4d2604de2
|
4
|
+
data.tar.gz: 3ac4db2fee93fd1047a3d24512d31b5fdc211648
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c23a2ef1014f94b75f235180ab0bd5c266370e23f453d7ec4cb6263022e338271432bb3b60ee043d5164b1fb1c7e4eb92f56de56d3390203f599a4a93567339c
|
7
|
+
data.tar.gz: 4aedbf8ff1db64ac4f2011c4229b99b8b4e348ecb41e2438ff3dc704e1d3a2e1886e1fe2c1ff5d8dda67b13ee90d520fceaa5530e20e7e4589e98d602d21aec9
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
data/bixby-common.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: bixby-common 0.
|
5
|
+
# stub: bixby-common 0.7.0 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "bixby-common"
|
9
|
-
s.version = "0.
|
9
|
+
s.version = "0.7.0"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Chetan Sarva"]
|
14
|
-
s.date = "2015-06-
|
14
|
+
s.date = "2015-06-29"
|
15
15
|
s.description = "Bixby Common files/libs"
|
16
16
|
s.email = "chetan@pixelcop.net"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -10,6 +10,87 @@ module Bixby
|
|
10
10
|
# A simple logging mixin
|
11
11
|
module Log
|
12
12
|
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def gems_regex
|
16
|
+
return @gems_regex if @gems_regex
|
17
|
+
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
|
18
|
+
@gems_regex = %r{(#{gems_paths.join('|')})/gems/([^/]+)-([\w.]+)/(.*)}
|
19
|
+
end
|
20
|
+
|
21
|
+
def ruby_regex
|
22
|
+
@ruby_regex ||= %r{^#{ENV["MY_RUBY_HOME"]}/lib(/.*?)?/ruby/[\d.]+/(.*)$}
|
23
|
+
end
|
24
|
+
|
25
|
+
# Check whether the given logger is configured to append to the console (STDOUT)
|
26
|
+
#
|
27
|
+
# @param [Logging::Logger] logger
|
28
|
+
#
|
29
|
+
# @return [Boolean] true if writing to STDOUT
|
30
|
+
def console_appender?(logger)
|
31
|
+
logger.appenders.each do |a|
|
32
|
+
if a.kind_of? Logging::Appenders::Stdout then
|
33
|
+
return true
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
if logger.parent then
|
38
|
+
return console_appender?(logger.parent)
|
39
|
+
end
|
40
|
+
|
41
|
+
false # at root
|
42
|
+
end
|
43
|
+
alias_method :console?, :console_appender?
|
44
|
+
alias_method :stdout?, :console_appender?
|
45
|
+
|
46
|
+
def clean_ex_for_console(ex, logger)
|
47
|
+
console?(logger) ? clean_ex(ex) : ex
|
48
|
+
end
|
49
|
+
|
50
|
+
# Created a cleaned up exception, suitable for printing to the console
|
51
|
+
#
|
52
|
+
# This method should generally only be used for debugging as it can be quite slow.
|
53
|
+
#
|
54
|
+
# @param [Exception] ex
|
55
|
+
# @param [Boolean] exclude_gems Whether or not to exclude all gems from the stacktrace (default: true)
|
56
|
+
# @param [Boolean] exclude_dupes When exclude_gems is set to false, omits duplicate gems from the stacktrace (default: true)
|
57
|
+
#
|
58
|
+
# @return [String]
|
59
|
+
def clean_ex(ex, exclude_gems=true, exclude_dupes=true)
|
60
|
+
puts self
|
61
|
+
s = []
|
62
|
+
s << "<#{ex.class}> #{ex.message}"
|
63
|
+
|
64
|
+
last_gem = nil
|
65
|
+
ex.backtrace.each do |e|
|
66
|
+
if e =~ Log.gems_regex then
|
67
|
+
next if exclude_gems
|
68
|
+
gem_name = $2
|
69
|
+
gem_ver = $3
|
70
|
+
trace = $4
|
71
|
+
gem_str = "#{gem_name} (#{gem_ver})"
|
72
|
+
if !exclude_dupes || (last_gem.nil? || last_gem != gem_name) then
|
73
|
+
s << " #{gem_str} #{trace}"
|
74
|
+
elsif exclude_dupes && last_gem == gem_name then
|
75
|
+
# s << " " + (" "*(gem_str.size+1)) + "..."
|
76
|
+
end
|
77
|
+
last_gem = gem_name
|
78
|
+
|
79
|
+
elsif e =~ Log.ruby_regex then
|
80
|
+
next if exclude_gems
|
81
|
+
last_gem = nil
|
82
|
+
trace = $2
|
83
|
+
s << " ruby (#{RUBY_VERSION}) #{trace}"
|
84
|
+
|
85
|
+
else
|
86
|
+
s << " #{e}"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
s.join("\n")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
13
94
|
# Get a log instance for this class
|
14
95
|
#
|
15
96
|
# @return [Logger]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bixby-common
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chetan Sarva
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bixby-auth
|