Class: ManageEngine::APMLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/agent/logging/am_logger.rb

Instance Method Summary collapse

Constructor Details

#initializeAPMLogger

Returns a new instance of APMLogger.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/agent/logging/am_logger.rb', line 7

def initialize
	@obj=ManageEngine::APMObjectHolder.instance
	path = getLogsPath
	#puts "#{path}"
	if  Dir[path] == []
		Dir.mkdir(path)
	end
	path= path + '/apm.log'
	#puts "#{path}"
#			file = open(path, File::WRONLY | File::APPEND | File::CREAT)
	@apmlog = Logger.new(path, 10, 100 * 1024 * 1024)
	#	@apmlog = Logger.new(file)
	@apmlog.level = Logger::INFO
	@apmlog.datetime_format = "%Y-%m-%d %H:%M:%S"	
	@apmlog.formatter = proc do |severity, datetime, progname, msg|
		"[#{datetime}|#{Process.pid}]:#{msg}\n"
	end
	@apmlog.debug("[LOGGER] APM Agent Logging Initialized")

end

Instance Method Details

#closeObject



105
106
107
# File 'lib/agent/logging/am_logger.rb', line 105

def close
	@apmlog.close
end

#debug(msg) ⇒ Object



81
82
83
# File 'lib/agent/logging/am_logger.rb', line 81

def debug(msg)
	@apmlog.debug(msg)
end

#error(msg) ⇒ Object



89
90
91
# File 'lib/agent/logging/am_logger.rb', line 89

def error(msg)
	@apmlog.error(msg)
end

#fatal(msg) ⇒ Object



93
94
95
# File 'lib/agent/logging/am_logger.rb', line 93

def fatal(msg)
	@apmlog.fatal(msg)
end

#getLogsPathObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/agent/logging/am_logger.rb', line 29

def	getLogsPath
	props = {}
	begin
		if FileTest.exists?(@obj.constants.apm_conf)
		propsFile=File.open(@obj.constants.apm_conf, 'r') 
		propsFile.read.each_line do |line|
			line.strip!
			if (line[0] != ?# and line[0] != ?=)
				i = line.index('=')
				if (i)
					props[line[0..i - 1].strip] = line[i + 1..-1].strip
				else
					props[line] = ''
				end
			end
		end
		else
			puts "ManageEngine Ruby Agent Configuration File Not exist in #{@obj.constants.apm_conf}.\n Duplicate file will be available in <Gems Folder>/apm-agent/lib/config "
		end
	rescue Exception=>e
		puts "Problem in Reading Property File : \n #{e.message} \n  #{e.backtrace}"
	ensure
		#
	end
	if props["apminsight.log.dir"]!=nil
		return props["apminsight.log.dir"]
	else
		return "./log"
	end

end

#info(msg) ⇒ Object



77
78
79
# File 'lib/agent/logging/am_logger.rb', line 77

def info(msg)
	@apmlog.info(msg)
end

#logException(msg, e) ⇒ Object



98
99
100
101
102
103
# File 'lib/agent/logging/am_logger.rb', line 98

def logException(msg,e)
	@apmlog.info( "#{msg} => #{e.message}")
	@apmlog.debug( "!!!!!!!!!!!!!!!!!!!!!!EXCEPTION !!!!!!!!!!!!!!!!!!!!!!!!!!!!")
	@apmlog.debug( "Message  : #{msg}\nTrace :\n#{e.backtrace}")
	@apmlog.debug( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
end

#setLevel(level) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/agent/logging/am_logger.rb', line 61

def setLevel level
	level =  level.upcase
	case level.upcase 
	when "INFO" then @apmlog.level = Logger::INFO
	when "DEBUG" then @apmlog.level = Logger::DEBUG
	when "WARN" then @apmlog.level = Logger::WARN
	when "ERROR" then @apmlog.level = Logger::ERROR
	when "FATAL" then @apmlog.level = Logger::FATAL
	when "FINE" then @apmlog.level = Logger::DEBUG
	when "SEVERE" then @apmlog.level = Logger::ERROR
	when "WARNING" then @apmlog.level = Logger::WARN
	else 
		@apmlog.level = Logger::DEBUG
	end
end

#warn(msg) ⇒ Object



85
86
87
# File 'lib/agent/logging/am_logger.rb', line 85

def warn(msg)
	@apmlog.warn(msg)
end