Module: LogManager

Defined in:
lib/log_manager.rb,
lib/generators/log_manager/execute_generator.rb,
lib/generators/log_manager/install_generator.rb

Defined Under Namespace

Modules: Generators

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.compressObject

Returns the value of attribute compress.



8
9
10
# File 'lib/log_manager.rb', line 8

def compress
  @compress
end

.rotation_frequencyObject

Returns the value of attribute rotation_frequency.



8
9
10
# File 'lib/log_manager.rb', line 8

def rotation_frequency
  @rotation_frequency
end

.saved_filesObject

Returns the value of attribute saved_files.



8
9
10
# File 'lib/log_manager.rb', line 8

def saved_files
  @saved_files
end

Class Method Details

.file_pathObject



57
58
59
# File 'lib/log_manager.rb', line 57

def self.file_path
  File.join(Dir.pwd, 'config', "log_manager.yml")
end

.hiObject



11
12
13
# File 'lib/log_manager.rb', line 11

def self.hi
  "Hi #{self.project_name}, If you are looking for a gem that helps you manage your log and also make your day awesome, You just found it!"
end

.log_rotateObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/log_manager.rb', line 19

def self.log_rotate
  File.open(self.project_name, "w") do |f|
    f.puts(self.path + '/log/*.log {')
    f.puts('  ' + @rotation_frequency)
    f.puts('  missingok')
    f.puts('  rotate ' + @saved_files.to_s)
    if @compress
      f.puts('  compress')
      f.puts('  delaycompress')
    end
    f.puts('  notifempty')
    f.puts('  copytruncate')
    f.puts('}')
  end
  return true
end

.pathObject



15
16
17
# File 'lib/log_manager.rb', line 15

def self.path
  Dir.pwd.to_s
end

.project_nameObject



36
37
38
# File 'lib/log_manager.rb', line 36

def self.project_name
  self.path.split('/').last
end

.setup(enviroment = 'development') ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/log_manager.rb', line 40

def self.setup enviroment = 'development'
  if self.validate_file
    config = YAML::load(File.open(LogManager.file_path))
    enviroment_config = config[enviroment]
    @rotation_frequency = enviroment_config['rotation_frequency']
    @saved_files = enviroment_config['saved_files']
    @compress = enviroment_config['compress']
    return true
  else
    "File doesnt exists yet, please run 'rails generate log_manager:install"
  end
end

.validate_fileObject



53
54
55
# File 'lib/log_manager.rb', line 53

def self.validate_file
  File.exist?(LogManager.file_path)
end