yajl 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +15 -3
- data/lib/yajl.rb +25 -11
- data/lib/yajl/version.rb +1 -1
- 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: 0327491bc27eb0abf90a26e1b8b7ad4c7b08add1
|
4
|
+
data.tar.gz: 619fa6addc48fe00a9267462aae1c99856bcb36b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 663acd9158d78ee0951a28b33aafdeefd981d08d63e09f3a0083d7714f2cc18d69f3b5bed285f67b0af14094ac1be1f2178659b2be256096f0d88529b0bd82a2
|
7
|
+
data.tar.gz: 3dd908fdaf1c372b3bd7848ea7a7b068e2a4afc9eeeb150968742ef1dc6d8b709494e7f3ba1e4d47962a1660ac143b6151c62f44e4615990eba4e880853c0ff4
|
data/README.markdown
CHANGED
@@ -4,6 +4,9 @@ Yet another JSON logger. I like Ruby's logger, but it's annoying to
|
|
4
4
|
always set it up. I like flexible, machine and human readable logs.
|
5
5
|
I want simplicity and brevity. I want to dump JSON in my logs
|
6
6
|
without screwing around, and I want to be able to easily log text.
|
7
|
+
I don't want to be constantly setting `progname`. I want to be able
|
8
|
+
to override the right things (like progrname) but I also always want
|
9
|
+
UTC and overriding id's is overkill.
|
7
10
|
|
8
11
|
## TODOs
|
9
12
|
|
@@ -29,6 +32,12 @@ Or install it yourself as:
|
|
29
32
|
|
30
33
|
## Usage
|
31
34
|
|
35
|
+
Yajl relies on `git` to determine what the root filepath is.
|
36
|
+
Since every single project that I have uses `git`, I decided
|
37
|
+
to just make it mandatory.
|
38
|
+
|
39
|
+
`cd [git repo] && irb`
|
40
|
+
|
32
41
|
```ruby
|
33
42
|
require 'yajl'
|
34
43
|
|
@@ -44,13 +53,16 @@ Will produce the following
|
|
44
53
|
"id": "44fa7a8f0186092d849ac1ea263ceb3f",
|
45
54
|
"severity": "WARN",
|
46
55
|
"datetime": "2015-08-24 18:22:12 UTC",
|
47
|
-
"progname":
|
56
|
+
"progname": "(irb)",
|
48
57
|
"message": {
|
49
58
|
"text": "danger"
|
50
59
|
}
|
51
60
|
}
|
52
61
|
```
|
53
62
|
|
63
|
+
Note that progname is normally set from the context of the root
|
64
|
+
git directory. E.g., `lib/yajl/version.rb`.
|
65
|
+
|
54
66
|
You can also log data structures:
|
55
67
|
|
56
68
|
```ruby
|
@@ -71,7 +83,7 @@ Which produces:
|
|
71
83
|
"banana_count": 2345,
|
72
84
|
"text": "So many bananas!"
|
73
85
|
},
|
74
|
-
"progname":
|
86
|
+
"progname": "(irb)",
|
75
87
|
"severity": "INFO"
|
76
88
|
}
|
77
89
|
```
|
@@ -85,7 +97,7 @@ logger = Yajl.create_logger
|
|
85
97
|
logger.fatal("deathstar") { "Nooooo" }
|
86
98
|
```
|
87
99
|
|
88
|
-
Which
|
100
|
+
Which overrides the `progname` attribute.
|
89
101
|
|
90
102
|
```json
|
91
103
|
{
|
data/lib/yajl.rb
CHANGED
@@ -16,7 +16,10 @@ class YajlLogger < Logger
|
|
16
16
|
|
17
17
|
%w{ warn info debug fatal error unknown }
|
18
18
|
.each do |method_name|
|
19
|
-
define_method(method_name) do |message|
|
19
|
+
define_method(method_name) do |message, &block|
|
20
|
+
|
21
|
+
return super(message, &block) if block
|
22
|
+
|
20
23
|
sender = caller[0].split(":")[0]
|
21
24
|
path = sender.split("/")
|
22
25
|
project_depth = project.split("/").size
|
@@ -40,16 +43,12 @@ module Yajl
|
|
40
43
|
|
41
44
|
def self.create_logger(log_directory=nil)
|
42
45
|
|
43
|
-
log_directory
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
project_name = project.split("/")[-1]
|
50
|
-
|
51
|
-
filename = File.expand_path("#{log_directory}/#{user}@#{hostname}.#{project_name}.log")
|
52
|
-
logger = YajlLogger.new(filename)
|
46
|
+
unless log_directory == STDOUT || log_directory == false
|
47
|
+
filename = Yajl.create_log_directory log_directory
|
48
|
+
logger = YajlLogger.new(filename)
|
49
|
+
else
|
50
|
+
logger = YajlLogger.new(STDOUT)
|
51
|
+
end
|
53
52
|
|
54
53
|
logger.level = Logger::INFO
|
55
54
|
logger.formatter = proc do |severity, datetime, progname, message|
|
@@ -66,4 +65,19 @@ module Yajl
|
|
66
65
|
return logger
|
67
66
|
|
68
67
|
end
|
68
|
+
|
69
|
+
def self.create_log_directory(log_directory)
|
70
|
+
|
71
|
+
log_directory ||= "~/logs"
|
72
|
+
|
73
|
+
user = `whoami`.chomp
|
74
|
+
hostname = `hostname`.chomp
|
75
|
+
|
76
|
+
`mkdir -p #{log_directory}`
|
77
|
+
project_name = project.split("/")[-1]
|
78
|
+
|
79
|
+
File.expand_path("#{log_directory}/#{user}@#{hostname}.#{project_name}.log")
|
80
|
+
|
81
|
+
end
|
82
|
+
|
69
83
|
end
|
data/lib/yajl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yajl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zach Aysan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|