Class: QuickBase::Logger
- Inherits:
-
Object
- Object
- QuickBase::Logger
- Defined in:
- lib/broker/client/QuickBaseClient.rb
Overview
To log QuickBase requests and responses to a file, make an instance of this class and call Client.setLogger( loggerInstance ). Call Client.setLogger( nil ) to turn logging off. The log file is written in CSV format to make it importable by QuickBase.
Instance Attribute Summary collapse
-
#append ⇒ Object
readonly
Returns the value of attribute append.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #changeLogFile(filename, append = true) ⇒ Object
- #closeLogFile ⇒ Object
- #getTimeString ⇒ Object
-
#initialize(filename, append = true) ⇒ Logger
constructor
A new instance of Logger.
- #logRequest(dbidForRequestURL, api_Request, requestXML) ⇒ Object
- #logResponse(error, responseXML) ⇒ Object
Constructor Details
#initialize(filename, append = true) ⇒ Logger
Returns a new instance of Logger.
5054 5055 5056 5057 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5054 def initialize( filename, append = true ) @requestEntryNum = @responseEntryNum = 0 changeLogFile( filename, append ) end |
Instance Attribute Details
#append ⇒ Object (readonly)
Returns the value of attribute append.
5052 5053 5054 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5052 def append @append end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
5052 5053 5054 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5052 def file @file end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5052 5053 5054 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5052 def filename @filename end |
Instance Method Details
#changeLogFile(filename, append = true) ⇒ Object
5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5069 def changeLogFile( filename, append = true ) if @file and @filename and @filename != filename closeLogFile() end begin @append = append skipHeader = (@append == true and FileTest.exist?( filename )) @file = File.open( filename, @append ? "a" : "w" ) @filename = filename @file.print( "entry,request time,dbid,api,request,response time, response" ) unless skipHeader rescue StandardError => e closeLogFile() puts "Logger error: #{e}" end end |
#closeLogFile ⇒ Object
5059 5060 5061 5062 5063 5064 5065 5066 5067 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5059 def closeLogFile() if @file @file.close @file = nil @filename = nil @append = true @requestEntryNum = @responseEntryNum = 0 end end |
#getTimeString ⇒ Object
5123 5124 5125 5126 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5123 def getTimeString() t = Time.now t.strftime( "%Y-%m-%d-%H-%M-%S" ) end |
#logRequest(dbidForRequestURL, api_Request, requestXML) ⇒ Object
5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5085 def logRequest( dbidForRequestURL, api_Request, requestXML ) if @file @requestEntryNum += 1 entry = "\n#{@requestEntryNum}," entry << "#{getTimeString()}," entry << "#{dbidForRequestURL}," entry << "#{api_Request}," maxChars = requestXML.length > 256 ? 256 : requestXML.length request = requestXML[0,maxChars] request.gsub!( ",", "_" ) entry << "#{request}" @file.print( entry ) end end |
#logResponse(error, responseXML) ⇒ Object
5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 |
# File 'lib/broker/client/QuickBaseClient.rb', line 5103 def logResponse( error, responseXML ) if @file @responseEntryNum += 1 if @responseEntryNum != @requestEntryNum entry = "\n#{@responseEntryNum},,,,#{getTimeString()}," else entry = ",#{getTimeString()}," end maxChars = responseXML.length > 256 ? 256 : responseXML.length response = responseXML[0,maxChars] response.gsub!( ",", "_" ) entry << "#{response}" @file.print( entry ) end end |