log_ranger 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.idea/.gitignore +2 -0
- data/.idea/log_ranger.iml +9 -0
- data/.idea/misc.xml +6 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/Gemfile +6 -0
- data/README.md +65 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/log-ranger.rb +6 -0
- data/lib/log_ranger/log_ranger/USAGE +27 -0
- data/lib/log_ranger/log_ranger/log_ranger_generator.rb +11 -0
- data/lib/log_ranger/log_ranger/templates/config/initializers/log_ranger.rb +22 -0
- data/lib/log_ranger/log_ranger/templates/config/initializers/mongo.rb +7 -0
- data/lib/log_ranger/log_ranger/templates/config/mongoid.yml +50 -0
- data/lib/log_ranger/log_ranger/templates/models/application.rb +8 -0
- data/lib/log_ranger/log_ranger/templates/models/application_log.rb +10 -0
- data/lib/log_ranger/railtie.rb +13 -0
- data/lib/log_ranger/version.rb +3 -0
- data/log_ranger.gemspec +36 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3138053471d68098084c2e32facb6fb49118cbd4808eaef37b7bb5d46c090dd8
|
4
|
+
data.tar.gz: b3049414e8a02f580afbe2d10469625a9bbbfdf235e5241acddc2eb70c0fb939
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2ed8fbb5470822cb1ec15a6d8271641843c3f5a17cbb4d8deec9981e94bf9c7cc7ee4747de01f51f40212aead4e8bf7b03c99a06f16cf0643f52d5c2fa21f551
|
7
|
+
data.tar.gz: ff2a7456523d1b0291e014c56ec1b56b1fac5838426af871fe4e6ef36e5919b49626497739bfd3ffdb0e53722ce422e86045c36171292f98654bb2152e1a8e19
|
data/.idea/.gitignore
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="JAVA_MODULE" version="4">
|
3
|
+
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
4
|
+
<exclude-output />
|
5
|
+
<content url="file://$MODULE_DIR$" />
|
6
|
+
<orderEntry type="inheritedJdk" />
|
7
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
8
|
+
</component>
|
9
|
+
</module>
|
data/.idea/misc.xml
ADDED
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/log_ranger.iml" filepath="$PROJECT_DIR$/.idea/log_ranger.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# LogRanger
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/log_ranger`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "log-ranger"
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install log-ranger
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
After installation, run `rails g log-ranger` to generate file needed.
|
26
|
+
|
27
|
+
This will create:
|
28
|
+
- app/models/application_log.rb
|
29
|
+
- config/mongoid.yml
|
30
|
+
- config/initializers/log_ranger.rb
|
31
|
+
- config/initializers/mongo.rb
|
32
|
+
|
33
|
+
Then add this gem to your Gemfile and run `bundle install`
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
gem "grape_logging"
|
37
|
+
gem "mongoid"
|
38
|
+
```
|
39
|
+
|
40
|
+
To use this logger as default logger, add following lines to your init.rb.
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
insert_after Grape::Middleware::Formatter, GrapeLogging::Middleware::RequestLogger,
|
44
|
+
logger: Logger.new(GrapeLogging::MultiIO.new($log_file, STDERR), formatter: CustomFormatter.new),
|
45
|
+
include: [ GrapeLogging::Loggers::Response.new,
|
46
|
+
GrapeLogging::Loggers::FilterParameters.new,
|
47
|
+
GrapeLogging::Loggers::ClientEnv.new,
|
48
|
+
GrapeLogging::Loggers::RequestHeaders.new ]
|
49
|
+
```
|
50
|
+
|
51
|
+
Last, add this following lines to your .env.
|
52
|
+
|
53
|
+
```env
|
54
|
+
LOG_APP_CODE=
|
55
|
+
MONGO_DB_NAME=
|
56
|
+
MONGO_DB_HOST=
|
57
|
+
MONGO_DB_USERNAME=
|
58
|
+
MONGO_DB_PASSWORD=
|
59
|
+
```
|
60
|
+
|
61
|
+
## Development
|
62
|
+
|
63
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
64
|
+
|
65
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "log-ranger"
|
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(__FILE__)
|
data/bin/setup
ADDED
data/lib/log-ranger.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Description:
|
2
|
+
Generate logger file
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate log_ranger
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
- app/models/application_log.rb
|
9
|
+
- config/mongoid.yml
|
10
|
+
- config/initializers/log_ranger.rb
|
11
|
+
- config/initializers/mongo.rb
|
12
|
+
|
13
|
+
Additional Gem:
|
14
|
+
Add this gem to your Gemfile and run `bundle install`
|
15
|
+
|
16
|
+
gem "grape_logging"
|
17
|
+
gem "mongoid"
|
18
|
+
|
19
|
+
To use this logger as default logger, add following lines to your init.rb.
|
20
|
+
insert_after Grape::Middleware::Formatter, GrapeLogging::Middleware::RequestLogger,
|
21
|
+
logger: Logger.new(GrapeLogging::MultiIO.new($log_file, STDERR), formatter: CustomFormatter.new),
|
22
|
+
include: [ GrapeLogging::Loggers::Response.new,
|
23
|
+
GrapeLogging::Loggers::FilterParameters.new,
|
24
|
+
GrapeLogging::Loggers::ClientEnv.new,
|
25
|
+
GrapeLogging::Loggers::RequestHeaders.new ]
|
26
|
+
|
27
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class LogRangerGenerator < Rails::Generators::Base
|
2
|
+
source_root File.expand_path('templates', __dir__)
|
3
|
+
|
4
|
+
def copy_initializer_file
|
5
|
+
copy_file "models/application.rb", "app/models/application.rb"
|
6
|
+
copy_file "models/application_log.rb", "app/models/application_log.rb"
|
7
|
+
copy_file "config/mongoid.yml", "config/mongoid.yml"
|
8
|
+
copy_file "config/initializers/log_ranger.rb", "config/initializers/log_ranger.rb"
|
9
|
+
copy_file "config/initializers/mongo.rb", "config/initializers/mongo.rb"
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
class CustomFormatter
|
3
|
+
def call(severity, datetime, _, data)
|
4
|
+
res = {
|
5
|
+
severity: severity,
|
6
|
+
type: data.class == String ? "query" : "response",
|
7
|
+
date: datetime,
|
8
|
+
data: JSON.parse(data.to_json)
|
9
|
+
}
|
10
|
+
|
11
|
+
application = Application.find_by(code: ENV['LOG_APP_CODE'])
|
12
|
+
application.application_logs.create(res)
|
13
|
+
"#{res.to_json}\n"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
Rails.application.configure do
|
18
|
+
$log_file = File.open("log/#{ENV['RAILS_ENV']}.log", 'a')
|
19
|
+
$log_file.sync = true
|
20
|
+
|
21
|
+
ActiveRecord::Base.logger = Logger.new(GrapeLogging::MultiIO.new($log_file, STDERR), formatter: CustomFormatter.new)
|
22
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
|
2
|
+
development:
|
3
|
+
clients:
|
4
|
+
default:
|
5
|
+
database: <%= ENV['MONGO_DB_NAME'] %>
|
6
|
+
hosts:
|
7
|
+
- <%= ENV['MONGO_DB_HOST'] %>
|
8
|
+
options:
|
9
|
+
user: <%= ENV['MONGO_DB_USERNAME'] %>
|
10
|
+
password: <%= ENV['MONGO_DB_PASSWORD'] %>
|
11
|
+
auth_source: admin
|
12
|
+
ssl: true
|
13
|
+
options:
|
14
|
+
|
15
|
+
production:
|
16
|
+
clients:
|
17
|
+
default:
|
18
|
+
database: <%= ENV['MONGO_DB_NAME'] %>
|
19
|
+
hosts:
|
20
|
+
- <%= ENV['MONGO_DB_HOST'] %>
|
21
|
+
options:
|
22
|
+
user: <%= ENV['MONGO_DB_USERNAME'] %>
|
23
|
+
password: <%= ENV['MONGO_DB_PASSWORD'] %>
|
24
|
+
auth_source: admin
|
25
|
+
ssl: true
|
26
|
+
options:
|
27
|
+
|
28
|
+
staging:
|
29
|
+
clients:
|
30
|
+
default:
|
31
|
+
database: <%= ENV['MONGO_DB_NAME'] %>
|
32
|
+
hosts:
|
33
|
+
- <%= ENV['MONGO_DB_HOST'] %>
|
34
|
+
options:
|
35
|
+
user: <%= ENV['MONGO_DB_USERNAME'] %>
|
36
|
+
password: <%= ENV['MONGO_DB_PASSWORD'] %>
|
37
|
+
auth_source: admin
|
38
|
+
ssl: true
|
39
|
+
options:
|
40
|
+
|
41
|
+
test:
|
42
|
+
clients:
|
43
|
+
default:
|
44
|
+
database: <%= ENV['MONGO_DB_NAME'] %>
|
45
|
+
hosts:
|
46
|
+
- <%= ENV['MONGO_DB_HOST'] %>
|
47
|
+
options:
|
48
|
+
read:
|
49
|
+
mode: :primary
|
50
|
+
max_pool_size: 1
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module LogRanger
|
2
|
+
def self.root
|
3
|
+
File.dirname __dir__
|
4
|
+
end
|
5
|
+
|
6
|
+
class MyRailtie < Rails::Railtie
|
7
|
+
log_ranger_generator_path = LogRanger::root.+'/lib/log_ranger/log_ranger/log_ranger_generator.rb'
|
8
|
+
|
9
|
+
config.app_generators do
|
10
|
+
require log_ranger_generator_path
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/log_ranger.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "log_ranger/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "log_ranger"
|
8
|
+
spec.version = LogRanger::VERSION
|
9
|
+
spec.authors = ["Dhian Alyusi"]
|
10
|
+
spec.email = ["developer@dcindonesia.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Used to generate file needed to store log}
|
13
|
+
spec.description = %q{Using default logger and store the log both in file and mongodb.}
|
14
|
+
spec.homepage = "https://gitlab.com/dcindonesia/lumberjack-gem"
|
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
|
+
# Specify which files should be added to the gem when it is released.
|
26
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
27
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
28
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
29
|
+
end
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: log_ranger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dhian Alyusi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-09 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.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
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
|
+
description: Using default logger and store the log both in file and mongodb.
|
42
|
+
email:
|
43
|
+
- developer@dcindonesia.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".idea/.gitignore"
|
49
|
+
- ".idea/log_ranger.iml"
|
50
|
+
- ".idea/misc.xml"
|
51
|
+
- ".idea/modules.xml"
|
52
|
+
- ".idea/vcs.xml"
|
53
|
+
- Gemfile
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- bin/console
|
57
|
+
- bin/setup
|
58
|
+
- lib/log-ranger.rb
|
59
|
+
- lib/log_ranger/log_ranger/USAGE
|
60
|
+
- lib/log_ranger/log_ranger/log_ranger_generator.rb
|
61
|
+
- lib/log_ranger/log_ranger/templates/config/initializers/log_ranger.rb
|
62
|
+
- lib/log_ranger/log_ranger/templates/config/initializers/mongo.rb
|
63
|
+
- lib/log_ranger/log_ranger/templates/config/mongoid.yml
|
64
|
+
- lib/log_ranger/log_ranger/templates/models/application.rb
|
65
|
+
- lib/log_ranger/log_ranger/templates/models/application_log.rb
|
66
|
+
- lib/log_ranger/railtie.rb
|
67
|
+
- lib/log_ranger/version.rb
|
68
|
+
- log_ranger.gemspec
|
69
|
+
homepage: https://gitlab.com/dcindonesia/lumberjack-gem
|
70
|
+
licenses: []
|
71
|
+
metadata:
|
72
|
+
allowed_push_host: https://rubygems.org/
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
requirements: []
|
88
|
+
rubygems_version: 3.0.8
|
89
|
+
signing_key:
|
90
|
+
specification_version: 4
|
91
|
+
summary: Used to generate file needed to store log
|
92
|
+
test_files: []
|