├── .rspec ├── .travis.yml ├── lib ├── super_awesome_print │ ├── version.rb │ └── configuration.rb └── super_awesome_print.rb ├── Gemfile ├── .gitignore ├── Rakefile ├── bin ├── setup └── console ├── LICENSE.txt ├── super_awesome_print.gemspec ├── CODE_OF_CONDUCT.md └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | --format documentation 2 | --color 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.2.3 4 | before_install: gem install bundler -v 1.10.6 5 | -------------------------------------------------------------------------------- /lib/super_awesome_print/version.rb: -------------------------------------------------------------------------------- 1 | module SuperAwesomePrint 2 | VERSION = '0.2.6'.freeze 3 | end 4 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in super_awesome_print.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.bundle/ 2 | /.yardoc 3 | /Gemfile.lock 4 | /_yardoc/ 5 | /coverage/ 6 | /doc/ 7 | /pkg/ 8 | /spec/reports/ 9 | /tmp/ 10 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rspec/core/rake_task' 3 | 4 | RSpec::Core::RakeTask.new(:spec) 5 | 6 | task default: :spec 7 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | 5 | bundle install 6 | 7 | # Do any other automated setup that you need to do here 8 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'bundler/setup' 4 | require 'super_awesome_print' 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 15 | -------------------------------------------------------------------------------- /lib/super_awesome_print/configuration.rb: -------------------------------------------------------------------------------- 1 | class Configuration 2 | attr_accessor :caller_lines, :blank_lines_top, :blank_lines_bottom, :root_path, :log_file_path 3 | 4 | def initialize 5 | @caller_lines = 1 6 | @blank_lines_top = 0 7 | @blank_lines_bottom = 0 8 | @root_path = defined?(Rails) ? Rails.root.to_s : '' 9 | @log_file_path = @root_path.empty? ? Dir.pwd + '/sapf.log' : @root_path + '/log/sapf.log' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Oleg Antonyan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /super_awesome_print.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'super_awesome_print/version' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = 'super_awesome_print' 8 | spec.version = SuperAwesomePrint::VERSION 9 | spec.authors = ['Oleg Antonyan'] 10 | spec.email = ['oleg.b.antonyan@gmail.com'] 11 | 12 | spec.summary = 'Simple wrapper around awesome_print for easier look in long log' 13 | spec.description = "Add colored '*********', time and line number around printed value" 14 | spec.homepage = 'http://github.com/olegantonyan/super_awesome_print' 15 | spec.license = 'MIT' 16 | 17 | spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 18 | spec.bindir = 'exe' 19 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 20 | spec.require_paths = ['lib'] 21 | 22 | spec.add_development_dependency 'bundler' 23 | spec.add_development_dependency 'rake' 24 | 25 | if RUBY_VERSION < '1.9.3' 26 | spec.add_runtime_dependency 'awesome_print', '1.2.0' 27 | else 28 | spec.add_runtime_dependency 'awesome_print' 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Code of Conduct 2 | 3 | As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. 4 | 5 | We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. 6 | 7 | Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. 8 | 9 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. 10 | 11 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers. 12 | 13 | This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/) 14 | -------------------------------------------------------------------------------- /lib/super_awesome_print.rb: -------------------------------------------------------------------------------- 1 | require 'super_awesome_print/version' 2 | require 'super_awesome_print/configuration' 3 | require 'awesome_print' 4 | 5 | module Kernel 6 | def sap(msg) 7 | SuperAwesomePrint.blank_lines_top 8 | ap "*** #{Time.now} ***", :color => { :string => :green } 9 | ap msg.class if msg.respond_to?(:class) 10 | SuperAwesomePrint.print_caller_lines(caller) 11 | ap msg 12 | ap '*** END ***', :color => { :string => :green } 13 | SuperAwesomePrint.blank_lines_bottom 14 | msg 15 | end 16 | 17 | def sapf(msg) 18 | file = File.open(SuperAwesomePrint.config.log_file_path , 'a') 19 | file.puts("*** #{Time.now} ***") 20 | file.puts(" class: #{msg.class}") if msg.respond_to?(:class) 21 | lines = caller[0...SuperAwesomePrint.config.caller_lines].map do |line| 22 | root_path = SuperAwesomePrint.config.root_path 23 | if root_path.empty? 24 | line 25 | else 26 | line.gsub(root_path + '/', '') 27 | end 28 | end 29 | lines.each { |l| file.puts(' trace: ' + l) } 30 | file.puts(msg.inspect) 31 | file.puts('*** END ***') 32 | ensure 33 | file.close 34 | end 35 | end 36 | 37 | module SuperAwesomePrint 38 | class << self 39 | attr_writer :configuration 40 | end 41 | 42 | def self.print_caller_lines(caller_array) 43 | number_of_lines = config.caller_lines 44 | lines = caller_array[0...number_of_lines].map do |line| 45 | line.gsub(config.root_path + '/', '') 46 | end 47 | lines.each { |line| ap line, :color => { :string => :purpleish } } 48 | end 49 | 50 | def self.blank_lines_top 51 | # The first puts has no visible effect 52 | # So we want to puts once regardless of config 53 | puts 54 | config.blank_lines_top.times { puts } 55 | end 56 | 57 | def self.blank_lines_bottom 58 | config.blank_lines_bottom.times { puts } 59 | end 60 | 61 | def self.config 62 | SuperAwesomePrint.configuration 63 | end 64 | 65 | def self.configuration 66 | @configuration ||= Configuration.new 67 | end 68 | 69 | def self.configure 70 | yield configuration 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SuperAwesomePrint 2 | 3 | Add colored '*********', time and line number around printed value. It's easier to find such output in a long console output. 4 | 5 | ![alt tag](https://cloud.githubusercontent.com/assets/2301579/12552398/45e9fa4c-c37a-11e5-8113-a9014d153ebb.png) 6 | ```ruby 7 | def index 8 | @posts = Post.all 9 | sap @posts 10 | end 11 | ``` 12 | 13 | ## Installation 14 | 15 | Add this line to your application's Gemfile: 16 | 17 | ```ruby 18 | gem 'super_awesome_print' 19 | ``` 20 | 21 | And then execute: 22 | 23 | $ bundle install 24 | 25 | Or install it yourself as: 26 | 27 | $ gem install super_awesome_print 28 | 29 | You can optionally customize configuration in an initializer.
30 | In Rails, you can add the following to `config/initializers/super_awesome_print.rb`: 31 | 32 | ```ruby 33 | SuperAwesomePrint.configure do |config| 34 | config.caller_lines = 3 # defaults to 1 35 | config.blank_lines_top = 2 # defaults to 0 36 | config.blank_lines_bottom = 2 # defaults to 0 37 | config.root_path = Rails.root.to_s # this path will be removed from caller's files path, defaults to Rails.root.to_s 38 | config.log_file_path = '/some/path/to/log/file' # override default log file for `sapf` 39 | end 40 | ``` 41 | 42 | ## Usage 43 | 44 | Just use `sap` global function to print any variable. 45 | 46 | You can also print to a file 47 | 48 | ```ruby 49 | sapf 'hello world' 50 | ``` 51 | 52 | By default it will print everything to `sapf.log` file in current directory or to `log/sapf.log` if you're on Rails. See `log_file_path` config option to override this. 53 | 54 | Also, take a look at [cop for RuboCop](https://github.com/olegantonyan/super_awesome_print_rubocop) to make `sap` didn't leak into production. 55 | 56 | ## Development 57 | 58 | After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. 59 | 60 | 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). 61 | 62 | ## Contributing 63 | 64 | Bug reports and pull requests are welcome on GitHub at https://github.com/olegantonyan/super_awesome_print. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://www.contributor-covenant.org) code of conduct. 65 | 66 | 67 | ## License 68 | 69 | The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). 70 | --------------------------------------------------------------------------------