Class: MGit::Loger

Inherits:
Object
  • Object
show all
Defined in:
lib/m-git/foundation/loger.rb,
lib/m-git/foundation/loger.rb

Overview

日志模块

Constant Summary collapse

MGIT_LOG_FILE_NAME =
'mgit.log'
DEFAULT_SHIFT_SIZE =

每个文件1M

1048576
DEFAULT_SHIFT_AGE =

保留10个文件

10
DEFAULT_LOG_FILE =
"./mgit.log"

Class Method Summary collapse

Class Method Details

.config(root) ⇒ Object

配置Log模块

Parameters:

  • root (String)

    工程根目录



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/m-git/foundation/loger.rb', line 17

def self.config(root)
  # 是否开启log
  begin
    log_enable = MGit::MGitConfig.query_with_key(root, :logenable)
  rescue MGitClass::Error => e
    log_enable = TRUE
  end
  MGit::Loger.set_log_enable(log_enable)

  # 配置log路径
  log_dir = File.join(root, MGit::Constants::PROJECT_DIR[:log_dir])
  FileUtils.mkdir_p(log_dir) if !Dir.exist?(log_dir)
  file_path = File.join(log_dir, MGIT_LOG_FILE_NAME)
  MGit::Loger.set_log_file(file_path)

  # 配置log的level
  begin
    log_level = MGit::MGitConfig.query_with_key(root, :loglevel)
  rescue MGitClass::Error => e
    log_level = 1
  end
  MGit::Loger.set_log_level(log_level)

end

.debug(message) ⇒ Object

打印 DEBUG类型的log



79
80
81
# File 'lib/m-git/foundation/loger.rb', line 79

def self.debug(message)
  self.logger.debug(message) if @log_enable
end

.error(message) ⇒ Object

打印 ERROR类型的log



100
101
102
# File 'lib/m-git/foundation/loger.rb', line 100

def self.error(message)
  self.logger.error(message) if @log_enable
end

.fatal(message) ⇒ Object

打印 FATAL类型的log



107
108
109
# File 'lib/m-git/foundation/loger.rb', line 107

def self.fatal(message)
  self.logger.fatal(message) if @log_enable
end

.info(message) ⇒ Object

打印 DEBUG类型的log



86
87
88
# File 'lib/m-git/foundation/loger.rb', line 86

def self.info(message)
  self.logger.info(message) if @log_enable
end

.set_log_enable(log_enable) ⇒ Object

设置mgit log是否开启 默认开启

Parameters:

  • log_enable (Boolean)

    是否开启log日志



56
57
58
# File 'lib/m-git/foundation/loger.rb', line 56

def self.set_log_enable(log_enable)
  @log_enable = log_enable
end

.set_log_file(file_path) ⇒ Object

设置mgit log的文件名, 默认路径在工作区的 .mgit/logs/mgit.log



72
73
74
# File 'lib/m-git/foundation/loger.rb', line 72

def self.set_log_file(file_path)
  @log_file = file_path
end

.set_log_level(level) ⇒ Object

设置mgit log的打印等级

Parameters:

  • level (Enumerable)

    : Logger::DEBUG | Logger::INFO | Logger::ERROR | Logger::FATAL



65
66
67
# File 'lib/m-git/foundation/loger.rb', line 65

def self.set_log_level(level)
  self.logger.level = level
end

.warn(message) ⇒ Object

打印 WARN类型的log



93
94
95
# File 'lib/m-git/foundation/loger.rb', line 93

def self.warn(message)
  self.logger.warn(message) if @log_enable
end