rotozipper 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 63527da537d574aced414d7e36c022b3936a76798fed10e00cc124fbbfc27a4a
4
+ data.tar.gz: 1e904b2778d018deded7678d5a0d20dd642ccbcc39c86a945d0284601fa77afa
5
+ SHA512:
6
+ metadata.gz: e6a38d2628870f8c5a36b2328caf3f339d50c358926f43ed1919529c788977b886295a3228b8a0a46b02efeb4c99e3870a808a0f97fc8f36f0d435cc55161438
7
+ data.tar.gz: ff02fe2a50d7ff1a26e1987cb5360fc5ccca4fee698940657c1405c6e72ccf383eab2d2e03c82ebecaf7f31c8c067363a16c229ca91aa1e0fac053b5f6a30dfb
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rotozipper.gemspec
4
+ gemspec
@@ -0,0 +1,55 @@
1
+ # Rotozipper
2
+
3
+ Rotozipper is a simple Ruby gem which aims to simplify log rotation and zipping.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'rotozipper'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install rotozipper
20
+
21
+ ## Usage
22
+
23
+ Usage is simple.
24
+ The gem provides a method `launch` of the `Rotozipper` module which takes three arguments:
25
+
26
+ * `glob_path` (required): the path in glob form of the folder where your logs are stored. For example, in a Rails application, you can set it to `log/*.log`.
27
+ * `output_path` (optional): the path where you want to save the rotozipped logs. Defaults to a relative `history` folder.
28
+ * `logger_path` (optional): the path of a log file where you want to store Rotozipper's operative logs. Defaults to `STDOUT`.
29
+
30
+ For example, to rotozip logs of a Rails application, you can execute:
31
+
32
+ ```ruby
33
+ Rotozipper.launch 'log/*.log', 'log/history'
34
+ ```
35
+
36
+ This command will compress all the `*.log` files in the `log` folder, and the move them to `log/history` folder, adding a timestamp to keep track of the moment. The original files will be truncated to 0 bytes.
37
+
38
+ ## Scheduling - Rails
39
+
40
+ Rotozipper has `whenever` as a gem dependency, so if you need to schedule the rotozipping of your logs, you can simply create a file named `config/schedule.rb` in your Rails application, and then add the following lines:
41
+
42
+ ```ruby
43
+ # config/schedule.rb
44
+
45
+ every :week, at: '00:00' do
46
+ runner %{ Rotozipper.launch 'log/*.log', 'log/history' }
47
+ end
48
+ ```
49
+
50
+ And then schedule it by running the command `whenever --update-crontab`.
51
+ Please refer to [whenever](https://github.com/javan/whenever) documentation to know more about it features.
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Pluve/ruby-rotozipper.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rotozipper"
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__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,60 @@
1
+ require "zlib"
2
+ require "active_support/core_ext/array"
3
+ require "rotozipper/version"
4
+ require "rotozipper/rainbow"
5
+
6
+ module Rotozipper
7
+ class Error < StandardError; end
8
+
9
+ class Logger
10
+
11
+ attr_accessor :logger
12
+
13
+ def initialize(logger_path)
14
+ @logger = ::Logger.new logger_path
15
+ end
16
+
17
+ def puts(message)
18
+ @logger.info message
19
+ end
20
+
21
+ end
22
+
23
+ ##
24
+ # Rotates and zips each file in specified directory.
25
+ #
26
+ # @param [String] glob_path source directory glob path.
27
+ # @param [String] output_path directory which contains zipped and rotates files.
28
+ # @param [String] logger_path an optional logger file as output.
29
+ #
30
+ # @return [nil]
31
+ def self.launch(glob_path, output_path = 'history', logger_path = nil)
32
+ logger = logger_path.present? ? Rotozipper::Logger.new(logger_path) : $stdout
33
+ logger.puts "Beginning to rotozip folder #{glob_path}..".darkorchid
34
+ unless Dir.exists? output_path
35
+ logger.puts "Creating output folder '#{output_path}'..".darkorchid
36
+ FileUtils.mkdir_p output_path
37
+ end
38
+
39
+ log_files = Dir.glob(glob_path)
40
+ logger.puts "Found #{log_files.count} files.".darkorchid
41
+ log_files.each do |log_file|
42
+ unless File.file? log_file
43
+ logger.puts "Skipping resource '#{log_file}' as it is not a file.".darkorchid
44
+ next
45
+ end
46
+ log_file_basename = File.basename log_file, File.extname(log_file)
47
+ zipped_file = "#{output_path}/#{log_file_basename}-#{Time.current.strftime('%Y%m%d-%H%M%S-%L')}.gz"
48
+ Zlib::GzipWriter.open(zipped_file) do |gz|
49
+ gz.mtime = File.mtime(log_file)
50
+ gz.orig_name = log_file
51
+ gz.write IO.binread(log_file)
52
+ end
53
+ File.truncate(log_file, 0)
54
+ logger.puts "Rotozipped file '#{log_file}' to '#{zipped_file}'.".darkorchid
55
+ end
56
+
57
+ logger.puts "Rotozip completed!".darkorchid
58
+ end
59
+
60
+ end
@@ -0,0 +1,25 @@
1
+ ##
2
+ # Crea un metodo per ogni colore da poter chiamare su un'istanza di una stringa.
3
+
4
+ class String
5
+
6
+ %i( aliceblue antiquewhite aqua aquamarine azure beige bisque blanchedalmond blue blueviolet brown burlywood
7
+ cadetblue chartreuse chocolate coral cornflower cornsilk crimson cyan darkblue darkcyan darkgoldenrod
8
+ darkgray darkgreen darkkhaki darkmagenta darkolivegreen darkorange darkorchid darkred darksalmon
9
+ darkseagreen darkslateblue darkslategray darkturquoise darkviolet deeppink deepskyblue dimgray
10
+ dodgerblue firebrick floralwhite forestgreen fuchsia gainsboro ghostwhite gold goldenrod gray
11
+ green greenyellow honeydew hotpink indianred indigo ivory khaki lavender lavenderblush lawngreen
12
+ lemonchiffon lightblue lightcoral lightcyan lightgoldenrod lightgray lightgreen lightpink lightsalmon
13
+ lightseagreen lightskyblue lightslategray lightsteelblue lightyellow lime limegreen linen magenta maroon
14
+ mediumaquamarine mediumblue mediumorchid mediumpurple mediumseagreen mediumslateblue mediumspringgreen
15
+ mediumturquoise mediumvioletred midnightblue mintcream mistyrose moccasin navajowhite navyblue oldlace
16
+ olive olivedrab orange orangered orchid palegoldenrod palegreen paleturquoise palevioletred papayawhip
17
+ peachpuff peru pink plum powderblue purple rebeccapurple red rosybrown royalblue saddlebrown salmon sandybrown
18
+ seagreen seashell sienna silver skyblue slateblue slategray snow springgreen steelblue tan teal
19
+ thistle tomato turquoise violet webgray webgreen webmaroon webpurple wheat whitesmoke yellow yellowgreen ).each do |color|
20
+ self.define_method color do
21
+ Rainbow(self).send(:color, color)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module Rotozipper
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rotozipper/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rotozipper"
8
+ spec.version = Rotozipper::VERSION
9
+ spec.authors = ["Francesco Ballardin"]
10
+ spec.email = ["francesco.ballardin@gmail.com"]
11
+
12
+ spec.summary = %q{A tool to help you rotate and zip your ruby app logs.}
13
+ spec.description = %q{A tool to help you rotate and zip your ruby app logs.}
14
+ spec.homepage = "https://github.com/Pluvie/ruby-rotozipper"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "activesupport"
26
+ spec.add_dependency "whenever"
27
+
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rotozipper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Francesco Ballardin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: whenever
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: A tool to help you rotate and zip your ruby app logs.
84
+ email:
85
+ - francesco.ballardin@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - README.md
95
+ - Rakefile
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/rotozipper.rb
99
+ - lib/rotozipper/rainbow.rb
100
+ - lib/rotozipper/version.rb
101
+ - rotozipper.gemspec
102
+ homepage: https://github.com/Pluvie/ruby-rotozipper
103
+ licenses: []
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.7.6
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: A tool to help you rotate and zip your ruby app logs.
125
+ test_files: []