mojo_logger 0.1.2-java → 0.1.3-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +89 -3
- data/lib/mojo_logger/mojo_logger.rb +14 -8
- data/lib/mojo_logger/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: 89bc4925d6e1a37712cbc30f39e6a1fc828841b4
|
4
|
+
data.tar.gz: 7fc83948413cd2e371582e19e219ca3d281f1692
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7bd80e290202c5c9dd544198850f32a8ae58083dcf6f0f1836ce51bafe36b243eda537e5a6474b3252486f6275462c7de9e06b62ff288a4bcb48ec1e11573771
|
7
|
+
data.tar.gz: dbe16c3f70e848ba3a73bac0b1140cf082a3ade7ead5fbbf686f4f10e7b0839bb77b9c23a05f98ea230209d05cac41c797a5f795b75ce980375515efc5eaab36
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# MojoLogger
|
2
2
|
|
3
|
-
|
3
|
+
This gem is a wrapper around log4j and is primarily meant to be used in the Mojo framework. It will standardize logs accross Mojo applications and provide a single location to edit the Mojo Logger code base. It comes with a few benefits:
|
4
4
|
|
5
|
-
|
5
|
+
* **JSON** Logs will be printed for nice splunk logging when the mojo_* methods are called.
|
6
|
+
* No need for a log4j.properties file (although you can use one if you prefer). You can configure the logger on the fly and this gem will build a StringIO object to mock the log4j.properties file
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -22,7 +23,92 @@ Or install it yourself as:
|
|
22
23
|
|
23
24
|
## Usage
|
24
25
|
|
25
|
-
|
26
|
+
#### Simple access to a CONSOLE appender:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'mojo_logger'
|
30
|
+
|
31
|
+
MojoLogger.logger.debug "This is a message"
|
32
|
+
#=> This is a message
|
33
|
+
|
34
|
+
```
|
35
|
+
|
36
|
+
#### Mojo Formatted JSON logs
|
37
|
+
```ruby
|
38
|
+
require 'mojo_logger'
|
39
|
+
|
40
|
+
api_request = {
|
41
|
+
session_id: '111111-11111',
|
42
|
+
reference_id: 'client',
|
43
|
+
api: 'get-user-info'
|
44
|
+
}
|
45
|
+
|
46
|
+
MojoLogger.mojo_warn(api_request, "Oops", "Some Warn Message")
|
47
|
+
#=> {"time":"08-25-2015 19:22:59.940 +0000","app":"Mojo","session_id":"111111-11111","reference_id":"client","api":"get-user-info","category":"Oops","message":"Some Warn Message"}
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
#### Mojo Formatted JSON logs with cusom keys
|
52
|
+
```ruby
|
53
|
+
require 'mojo_logger'
|
54
|
+
|
55
|
+
api_request = {
|
56
|
+
session_id: '111111-11111',
|
57
|
+
reference_id: 'client',
|
58
|
+
api: 'get-user-info'
|
59
|
+
}
|
60
|
+
|
61
|
+
MojoLogger.mojo_warn(api_request, "Oops", "Some Warn Message", {my_key: "Some value", my_other_key: :another_val})
|
62
|
+
#=> {"time":"08-25-2015 19:24:57.575 +0000","app":"Mojo","session_id":"111111-11111","reference_id":"client","api":"get-user-info","category":"Oops","message":"Some Warn Message","my_key":"Some value","my_other_key":"another_val"}
|
63
|
+
|
64
|
+
```
|
65
|
+
|
66
|
+
|
67
|
+
## Configuration
|
68
|
+
|
69
|
+
#### CONSOLE appender with "WARN" log level
|
70
|
+
```ruby
|
71
|
+
require 'mojo_logger'
|
72
|
+
|
73
|
+
MojoLogger.config do |config|
|
74
|
+
config.default_log_level = :warn
|
75
|
+
end
|
76
|
+
|
77
|
+
MojoLogger.logger.debug "This won't show up"
|
78
|
+
#=> nil
|
79
|
+
|
80
|
+
MojoLogger.logger.warn "This will show up"
|
81
|
+
#=> This will show up
|
82
|
+
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
#### Rolling File appender
|
87
|
+
This will create a rolling file logger rather than a console logger with the following settings:
|
88
|
+
Max File Size = 10MB
|
89
|
+
Max Backup Index = 10
|
90
|
+
Pattern = '%n %m %n' (I need to change this but this is what it is for now.)
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
require 'mojo_logger'
|
94
|
+
|
95
|
+
MojoLogger.config do |config|
|
96
|
+
config.log_file = '/var/log/my_log.log'
|
97
|
+
end
|
98
|
+
|
99
|
+
```
|
100
|
+
|
101
|
+
#### Add Custom lines to the generated log4j.properties 'file'
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
require 'mojo_logger'
|
105
|
+
|
106
|
+
MojoLogger.config do |config|
|
107
|
+
config.custom_line("log4j.logger.org.apache.zookeeper.ClientCnxn=INFO")
|
108
|
+
end
|
109
|
+
|
110
|
+
```
|
111
|
+
|
26
112
|
|
27
113
|
## Development
|
28
114
|
|
@@ -64,23 +64,29 @@ module MojoLogger
|
|
64
64
|
logger.error(mojo_msg(*args))
|
65
65
|
end
|
66
66
|
|
67
|
+
def default_log_level
|
68
|
+
configurator.default_log_level
|
69
|
+
end
|
67
70
|
|
68
71
|
def config
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
+
if block_given?
|
73
|
+
@@config = MojoLogger::Configurator.new
|
74
|
+
yield(@@config)
|
75
|
+
@@logger = configure_logger
|
76
|
+
end
|
72
77
|
|
73
|
-
|
74
|
-
@@config
|
78
|
+
configurator
|
75
79
|
end
|
76
80
|
|
77
81
|
|
78
|
-
|
82
|
+
private
|
79
83
|
|
80
|
-
def
|
84
|
+
def configurator
|
81
85
|
@@config ||= MojoLogger::Configurator.new
|
86
|
+
end
|
82
87
|
|
83
|
-
|
88
|
+
def configure_logger
|
89
|
+
stringio = StringIO.new(configurator.generate_properties_string)
|
84
90
|
java_stringio = org.jruby.util.IOInputStream.new(stringio)
|
85
91
|
|
86
92
|
Java::org.apache.log4j.PropertyConfigurator.configure(java_stringio)
|
data/lib/mojo_logger/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojo_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- John Thomas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|