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.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/agent/logging/am_logger.rb', line 9

def initialize
	@obj=ManageEngine::APMObjectHolder.instance
	path = getLogsPath
	#puts "#{path}"
	if  Dir[path] == []
		Dir.mkdir(path)
	end
	@apmLogPath= path + '/apm.log'
	#puts "#{path}"
#			file = open(path, File::WRONLY | File::APPEND | File::CREAT)
    begin
      @apmlog = Logger.new(@apmLogPath, 10, 5 * 1024 * 1024)
      @apmlog.level = Logger::INFO
    rescue Exception => e
      puts "Unable to create/edit the log file #{@apmLogPath}. Writing agent logs to STDOUT.\nError: #{e.message}"
      @apmlog = Logger.new(STDOUT)
      @apmlog.level = Logger::WARN
    end
    # @apmlog = Logger.new(file)
    @apmlog.datetime_format = "%Y-%m-%d %H:%M:%S" 
	@apmlog.formatter = proc do |severity, datetime, progname, msg|
		"[#{datetime}|#{Process.pid}][#{severity}]:#{msg}\n"
	end
	@apmlog.debug("[LOGGER] APM Agent Logging Initialized")

end

Instance Method Details

#closeObject



114
115
116
# File 'lib/agent/logging/am_logger.rb', line 114

def close
	@apmlog.close
end

#debug(msg) ⇒ Object



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

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

#error(msg) ⇒ Object



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

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

#fatal(msg) ⇒ Object



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

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

#getLogFilePathObject



36
37
38
# File 'lib/agent/logging/am_logger.rb', line 36

def getLogFilePath
  return @apmLogPath
end

#getLogsPathObject



40
41
42
43
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
69
70
# File 'lib/agent/logging/am_logger.rb', line 40

def	getLogsPath
	props = {}
	begin
		if FileTest.exist?(@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 @obj.constants.conf_location+"log"
	end

end

#info(msg) ⇒ Object



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

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

#logException(msg, e) ⇒ Object



109
110
111
112
# File 'lib/agent/logging/am_logger.rb', line 109

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

#setLevel(level) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/agent/logging/am_logger.rb', line 72

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



96
97
98
# File 'lib/agent/logging/am_logger.rb', line 96

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