git status
On branch develop
Untracked files:
(use "git add <file>..." to include in what will be committed)
testDir/
nothing added to commit but untracked files present (use "git add" to track)
git status -uall
On branch develop
Untracked files:
(use "git add <file>..." to include in what will be committed)
testDir/a.txt
testDir/b.txt
testDir/c.txt
nothing added to commit but untracked files present (use "git add" to track)
git log –name-status
個人的に一番使うlogのオプションです。 下記のようにそのコミットで変更されたファイルが出力され、 git status + git log のようなイメージで使えます。
初めまして、17新卒でエンジニアとして入社したむらさきです。 4月にエンジニアとして入社し、Ruby on Railsを使用してwebサイトの改修や機能の追加などを行っています。入社前のインターンに参加するまでRubyもRailsもwebサイト構築もしたことの無かったのですが、この3ヵ月弱で色々なことを学んで少しずつですが成長を日々実感しています。 さて、今回から記事を書くわけですが、他のエンジニアの方々のような難しいことを書く知識はないので、実際に仕事で制作した「Rubyでlogを作成してローテーションさせる」機能について復習を兼ねてまとめたいと思います。
ドキュメントにある様にcallメソッドの4つの引数によってフォーマットを変えられます。今回はserverity, time, prognameは必要なく、msgだけあればいいので
#config/environment.rb
# Load the Rails application.
require File.expand_path('../application', __FILE__)
#ここから記述
class CustomLogger
class Formatter
def call(_severity, _time, _progname, msg)
"#{msg}\n"
end
end
end
#ここまで記述
# Initialize the Rails application.
Rails.application.initialize!
#lib/tasks/log_rotate.rb
module Tasks
module LogRotate
require 'fileutils'
require 'active_support'
class << self
def rotate
time = Time.current.months_ago(3).strftime('%Y%m%d%H%M%S')
log_all = Dir.glob("#{Rails.root}/public/contact_log/*")
log_all.each do |i|
if File.stat(i).mtime.strftime('%Y%m%d%H%M%S') < time
FileUtils.rm_f(i)
end
end
end
end
end
end