Class: GitPusshuTen::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/gitpusshuten/log.rb

Class Method Summary collapse

Class Method Details

.error(message) ⇒ Object

Displays an error message



30
31
32
33
34
# File 'lib/gitpusshuten/log.rb', line 30

def self.error(message)
  message = "[error] ".color(:red) + message
  puts message
  to_file message
end

.gitpusshuten_dirObject

Returns the Gitpusshuten directory path



72
73
74
# File 'lib/gitpusshuten/log.rb', line 72

def self.gitpusshuten_dir
  File.join(Dir.pwd, '.gitpusshuten')
end

.log_dirObject

Returns the Gitpusshuten log directory path



78
79
80
# File 'lib/gitpusshuten/log.rb', line 78

def self.log_dir
  File.join(gitpusshuten_dir, 'log')
end

.message(message) ⇒ Object

Displays a regular message



14
15
16
17
18
# File 'lib/gitpusshuten/log.rb', line 14

def self.message(message)
  message = "[message] ".color(:green) + message
  puts message
  to_file message
end

.silent(message) ⇒ Object

Silently logs messages



38
39
40
# File 'lib/gitpusshuten/log.rb', line 38

def self.silent(message)
  to_file message
end

.standard(message) ⇒ Object

Displays a regular message without prefix



7
8
9
10
# File 'lib/gitpusshuten/log.rb', line 7

def self.standard(message)
  puts message unless message.nil?
  to_file message
end

.to_file(message) ⇒ Object

Logs the message to the log file



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gitpusshuten/log.rb', line 44

def self.to_file(message)
  return unless message.is_a?(String)
  
  ##
  # Don't log if we're not working within the Gitpusshuten directory
  if File.directory?(gitpusshuten_dir)
    
    ##
    # Create the log directory if it doesn't exist
    if not File.directory?(log_dir)
      FileUtils.mkdir_p(log_dir)
    end
    
    ##
    # Remove all ANSI coloring codes for clean logging
    message.gsub!(/\[\d+m/, '')
    
    ##
    # Log the message to the file (append)
    File.open(File.join(log_dir, 'gitpusshuten.log'), 'a') do |file|
      file << "\n#{Time.now.strftime("[%m/%d/%Y %H:%M:%S]")} #{message}"
    end
    
  end
end

.warning(message) ⇒ Object

Displays a warning message



22
23
24
25
26
# File 'lib/gitpusshuten/log.rb', line 22

def self.warning(message)
  message = "[warning] ".color(:yellow) + message
  puts message
  to_file message
end