Module: XasLogger

Defined in:
lib/xasin_logger.rb

Defined Under Namespace

Modules: Mix Classes: Standalone

Class Method Summary collapse

Class Method Details

.init_formatting_logger(log_dest) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/xasin_logger.rb', line 6

def XasLogger.init_formatting_logger(log_dest)
	logger = Logger.new(log_dest);

	logger.formatter = proc do |severity, datetime, progname, msg|
		outStr = "[#{datetime.strftime("%b-%d %H:%M:%S.%L")}] #{msg}\n";

		case(severity)
		when 'DEBUG'
			outStr = "D #{outStr}";
		when 'WARN'
			outStr = "W #{outStr}".yellow
		when 'INFO'
			outStr = "I #{outStr}".green
		when 'ERROR'
			outStr = "E #{outStr}".red
		when 'FATAL'
			outStr = "F #{outStr}".black.on_red
		else
			outStr = "? #{outStr}".purple
		end

		outStr;
	end

	return logger;
end

.init_logger_list(list) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/xasin_logger.rb', line 33

def XasLogger.init_logger_list(list)
	lgrList = [list].flatten;

	outList = Array.new();
	lgrList.each do |logger|
		if(logger.is_a? Logger)
			outList << logger;
		else
			outList << init_formatting_logger(logger)
		end
	end
end

.loggersObject



46
47
48
49
50
# File 'lib/xasin_logger.rb', line 46

def XasLogger.loggers()
	@loggers ||= [init_formatting_logger(STDOUT)];

	return @loggers
end

.loggers=(loggerList) ⇒ Object



52
53
54
# File 'lib/xasin_logger.rb', line 52

def XasLogger.loggers=(loggerList)
	@loggers = init_logger_list(loggerList);
end