Class: App42::Log::LogService

Inherits:
Object
  • Object
show all
Defined in:
lib/log/LogService.rb

Overview

Centralize logging for your App. This service allows different levels e.g. info, debug, fatal, error etc. to log a message and query the messages based on different parameters.

You can fetch logs based on module, level, message, date range etc.

See Also:

Instance Method Summary collapse

Constructor Details

#initialize(api_key, secret_key, base_url) ⇒ LogService

this is a constructor that takes

Parameters:

  • apiKey
  • secretKey
  • baseURL


32
33
34
35
36
37
38
39
# File 'lib/log/LogService.rb', line 32

def initialize(api_key, secret_key, base_url)
  puts "LogService->initialize"
  @api_key = api_key
  @secret_key = secret_key
  @base_url = base_url
  @resource = "log"
  @version = "1.0"
end

Instance Method Details

#build_and_send(msg, appModule, level) ⇒ Object

Builds and Logs the message

Parameters:

  • msg
    • Message to be logged

  • module
    • Module name for which the message is getting logged

  • level
    • The level on which the message is getting logged

Returns:

  • Log object containing logged message



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/log/LogService.rb', line 56

def build_and_send(msg,appModule,level)
  puts "Build and Send Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(msg, "Message");
  util.throwExceptionIfNullOrBlank(appModule, "App Module");
  util.throwExceptionIfNullOrBlank(appModule, "Level");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    body = {'app42' => {"log"=> {
      "message" => msg,
      "appModule" => appModule
      }}}.to_json
    puts "Body #{body}"
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc
    }
    query_params = params.clone
    params.store("body", body)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/#{level}"
    response = connection.post(signature, resource_url, query_params, body)
    log = LogResponseBuilder.new()
    logObj  = log.buildResponse(response);
  rescue  App42Exception =>e
    puts e
    raise e
  rescue  Exception => e
    puts e
    raise App42Exception.new(e)
  end
  return logObj
end

#debug(msg, appModule) ⇒ Object

Logs the debug message

Parameters:

  • msg
    • Message to be logged

  • module
    • Module name for which the message is getting logged

Returns:

  • Log object containing logged message

Raises:

  • App42Exception



127
128
129
# File 'lib/log/LogService.rb', line 127

def debug( msg,  appModule)
  return build_and_send(msg, appModule, "debug");
end

#error(msg, appModule) ⇒ Object

Logs the error message

Parameters:

  • msg
    • Message to be logged

  • module
    • Module name for which the message is getting logged

Returns:

  • Log object containing logged message

Raises:

  • App42Exception



161
162
163
# File 'lib/log/LogService.rb', line 161

def error( msg,  appModule)
  return build_and_send(msg, appModule, "error");
end

#fatal(msg, appModule) ⇒ Object

Logs the fatal message

Parameters:

  • msg
    • Message to be logged

  • module
    • Module name for which the message is getting logged

Returns:

  • Log object containing logged message

Raises:

  • App42Exception



144
145
146
# File 'lib/log/LogService.rb', line 144

def fatal( msg,  appModule)
  return build_and_send(msg, appModule, "fatal");
end

#fetch_log_by_date_range(startDate, endDate) ⇒ Object

Fetch log messages based on Date range

Parameters:

  • startDate
    • Start date from which the log messages have to be fetched

  • endDate
    • End date upto which the log messages have to be fetched

Returns:

  • Log object containing fetched messages

Raises:

  • App42Exception



643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
# File 'lib/log/LogService.rb', line 643

def fetch_log_by_date_range(startDate, endDate)
  puts "Fetch Logs By Date Range Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(startDate, "Start Date");
  util.throwExceptionIfNullOrBlank(endDate, "End Date");
  strStartdate = util.get_timestamp_utc_from_date(startDate)
  strEnddate = util.get_timestamp_utc_from_date(endDate)
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    strStartDate = util.get_timestamp_utc_from_date(startDate);
    strEndDate = util.get_timestamp_utc_from_date(endDate);
    params.store("startDate", strStartdate)
    params.store("endDate", strEnddate)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/startDate/#{strStartdate}/endDate/#{strEnddate}"
    response = connection.get(signature, resource_url, query_params)
    logObj = LogResponseBuilder.new().buildResponse(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return logObj
end

#fetch_log_by_date_range_by_paging(startDate, endDate, max, offset) ⇒ Object

Fetch log messages based on Date range by paging.

Parameters:

  • startDate
    • Start date from which the log messages have to be fetched

  • endDate
    • End date upto which the log messages have to be fetched

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Log object containing fetched messages

Raises:

  • App42Exception



551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/log/LogService.rb', line 551

def fetch_log_by_date_range_by_paging(startDate, endDate, max, offset)
  puts "Fetch Logs By Date Range By Paging Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.validateMax(max);
  util.throwExceptionIfNullOrBlank(max, "Max");
  util.throwExceptionIfNullOrBlank(offset, "Offset");
  util.throwExceptionIfNullOrBlank(startDate, "Start Date");
  util.throwExceptionIfNullOrBlank(endDate, "End Date");
  strStartdate = util.get_timestamp_utc_from_date(startDate)
  strEnddate = util.get_timestamp_utc_from_date(endDate)
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone

    strStartDate = util.get_timestamp_utc_from_date(startDate);
    strEndDate = util.get_timestamp_utc_from_date(endDate);
    params.store("startDate", strStartdate)
    params.store("endDate", strEnddate)
    params.store("max", "" + (max.to_i).to_s)
    params.store("offset", "" + (offset.to_i).to_s)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/paging/startDate/#{strStartdate}/endDate/#{strEnddate}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
    response = connection.get(signature, resource_url, query_params)
    logObj = LogResponseBuilder.new().buildResponse(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return logObj
end

#fetch_logs_by_debugObject

Fetch log messages based on Debug Level

Returns:

  • Log object containing fetched debug messages

Raises:

  • App42Exception



602
603
604
# File 'lib/log/LogService.rb', line 602

def fetch_logs_by_debug()
  return fetch_logs_by_level("DEBUG");
end

#fetch_logs_by_debug_by_paging(max, offset) ⇒ Object

Fetch log messages based on Debug Level by paging.

Parameters:

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Log object containing fetched debug messages

Raises:

  • App42Exception



496
497
498
# File 'lib/log/LogService.rb', line 496

def fetch_logs_by_debug_by_paging(max, offset)
  return fetch_logs_by_level_by_paging("DEBUG", max, offset);
end

#fetch_logs_by_errorObject

Fetch log messages based on Error Level

Returns:

  • Log object containing fetched error messages

Raises:

  • App42Exception



614
615
616
# File 'lib/log/LogService.rb', line 614

def fetch_logs_by_error()
  return fetch_logs_by_level("ERROR");
end

#fetch_logs_by_error_by_paging(max, offset) ⇒ Object

Fetch log messages based on Error Level by paging.

Parameters:

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Log object containing fetched error messages

Raises:

  • App42Exception



513
514
515
# File 'lib/log/LogService.rb', line 513

def fetch_logs_by_error_by_paging(max, offset)
  return fetch_logs_by_level_by_paging("ERROR", max, offset);
end

#fetch_logs_by_fatalObject

Fetch log messages based on Fatal Level

Returns:

  • Log object containing fetched Fatal messages

Raises:

  • App42Exception



626
627
628
# File 'lib/log/LogService.rb', line 626

def fetch_logs_by_fatal()
  return fetch_logs_by_level("FATAL");
end

#fetch_logs_by_fatal_by_paging(max, offset) ⇒ Object

Fetch log messages based on Fatal Level by paging.

Parameters:

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Log object containing fetched Fatal messages

Raises:

  • App42Exception



530
531
532
# File 'lib/log/LogService.rb', line 530

def fetch_logs_by_fatal_by_paging(max, offset)
  return fetch_logs_by_level_by_paging("FATAL", max, offset);
end

#fetch_logs_by_infoObject

Fetch log messages based on Info Level

Returns:

  • Log object containing fetched info messages

Raises:

  • App42Exception



462
463
464
# File 'lib/log/LogService.rb', line 462

def fetch_logs_by_info()
  return fetch_logs_by_level("INFO");
end

#fetch_logs_by_info_by_paging(max, offset) ⇒ Object

Fetch log messages based on Info Level by paging.

Parameters:

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Log object containing fetched info messages

Raises:

  • App42Exception



479
480
481
# File 'lib/log/LogService.rb', line 479

def fetch_logs_by_info_by_paging(max, offset)
  return fetch_logs_by_level_by_paging("INFO", max, offset);
end

#fetch_logs_by_level(level) ⇒ Object

Fetch the log messages based on the Level

Parameters:

  • level
    • The level on which logs have to be searched

Returns:

  • Log object containing fetched messages

Raises:

  • App42Exception



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/log/LogService.rb', line 372

def fetch_logs_by_level(level)
  puts "Fetch Logs By Leve Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(level, "Level");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("type", level)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/type/#{level}"
    response = connection.get(signature, resource_url, query_params)
    logObj = LogResponseBuilder.new().buildResponse(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return logObj
end

#fetch_logs_by_level_by_paging(level, max, offset) ⇒ Object

Fetch the log messages based on the Level by paging.

Parameters:

  • level
    • The level on which logs have to be searched

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Log object containing fetched messages

Raises:

  • App42Exception



418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/log/LogService.rb', line 418

def fetch_logs_by_level_by_paging(level, max, offset)
  puts "Fetch Logs By Level By Paging Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.validateMax(max);
  util.throwExceptionIfNullOrBlank(level, "Level");
  util.throwExceptionIfNullOrBlank(max, "Max");
  util.throwExceptionIfNullOrBlank(offset, "Offset");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("type", level)
    params.store("max", "" + (max.to_i).to_s)
    params.store("offset", "" + (offset.to_i).to_s)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/paging/type/#{level}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
    response = connection.get(signature, resource_url, query_params)
    logObj = LogResponseBuilder.new().buildResponse(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return logObj
end

#fetch_logs_by_module(moduleName) ⇒ Object

Fetch the log messages based on the Module

Parameters:

  • moduleName
    • Module name for which the messages has to be fetched

Returns:

  • Log object containing fetched messages

Raises:

  • App42Exception



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/log/LogService.rb', line 176

def fetch_logs_by_module(moduleName)
  puts "Fetch Logs By Module Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("moduleName", moduleName)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/module/#{moduleName}"
    response = connection.get(signature, resource_url, query_params)
    puts "Response is #{response}"
    logObj = LogResponseBuilder.new().buildResponse(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return logObj
end

#fetch_logs_by_module_and_text(moduleName, text) ⇒ Object

Fetch log messages based on the Module and Message Text

Parameters:

  • moduleName
    • Module name for which the messages has to be fetched

  • text
    • The log message on which logs have to be searched

Returns:

  • Log object containing fetched messages

Raises:

  • App42Exception



273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/log/LogService.rb', line 273

def fetch_logs_by_module_and_text(moduleName, text)
  puts "Fetch Logs By Module And Text Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
  util.throwExceptionIfNullOrBlank(text, "Text");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("moduleName", moduleName)
    params.store("text", text)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/module/#{moduleName}/text/#{text}"
    response = connection.get(signature, resource_url, query_params)
    logObj = LogResponseBuilder.new().buildResponse(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return logObj
end

#fetch_logs_by_module_and_text_by_paging(moduleName, text, max, offset) ⇒ Object

Fetch log messages based on the Module and Message Text by paging.

Parameters:

  • moduleName
    • Module name for which the messages has to be fetched

  • text
    • The log message on which logs have to be searched

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Log object containing fetched messages

Raises:

  • App42Exception



323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# File 'lib/log/LogService.rb', line 323

def fetch_logs_by_module_and_text_by_paging(moduleName, text, max, offset)
  puts "Fetch Logs By Module And Text By Paging Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.validateMax(max);
  util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
  util.throwExceptionIfNullOrBlank(text, "Text");
  util.throwExceptionIfNullOrBlank(max, "Max");
  util.throwExceptionIfNullOrBlank(offset, "Offset");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("moduleName", moduleName)
    params.store("text", text)
    params.store("max", "" + (max.to_i).to_s)
    params.store("offset", "" + (offset.to_i).to_s)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/paging/module/#{moduleName}/text/#{text}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
    response = connection.get(signature, resource_url, query_params)
    logObj = LogResponseBuilder.new().buildResponse(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return logObj
end

#fetch_logs_by_module_by_paging(moduleName, max, offset) ⇒ Object

Fetch the log messages based on the Module by paging.

Parameters:

  • moduleName
    • Module name for which the messages has to be fetched

  • max
    • Maximum number of records to be fetched

  • offset
    • From where the records are to be fetched

Returns:

  • Log object containing fetched messages

Raises:

  • App42Exception



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/log/LogService.rb', line 223

def fetch_logs_by_module_by_paging(moduleName, max, offset)
  puts "Fetch Logs By Module By Paging Called "
  puts "Base url #{@base_url}"
  response = nil
  logObj = nil
  logObj = Log.new
  util = Util.new
  util.validateMax(max);
  util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
  util.throwExceptionIfNullOrBlank(max, "Max");
  util.throwExceptionIfNullOrBlank(offset, "Offset");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("moduleName", moduleName)
    params.store("max", "" + (max.to_i).to_s)
    params.store("offset", "" + (offset.to_i).to_s)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/paging/module/#{moduleName}/#{(max.to_i).to_s}/#{(offset.to_i).to_s}"
    response = connection.get(signature, resource_url, query_params)
    logObj = LogResponseBuilder.new().buildResponse(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  puts logObj
  return logObj
end

#fetch_logs_count_by_date_range(startDate, endDate) ⇒ Object

Fetch count of log messages based on Date range

Parameters:

  • startDate
    • Start date from which the count of log messages have to be fetched

  • endDate
    • End date upto which the count of log messages have to be fetched

Returns:

  • App42Response object containing count of fetched messages

Raises:

  • App42Exception



879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
# File 'lib/log/LogService.rb', line 879

def fetch_logs_count_by_date_range(startDate, endDate)
  puts "Fetch Logs Count By Date Range Called "
  puts "Base url #{@base_url}"
  response = nil
  responseObj = App42Response.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(startDate, "Start Date");
  util.throwExceptionIfNullOrBlank(endDate, "End Date");
  strStartdate = util.get_timestamp_utc_from_date(startDate)
  strEnddate = util.get_timestamp_utc_from_date(endDate)
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    strStartDate = util.get_timestamp_utc_from_date(startDate);
    strEndDate = util.get_timestamp_utc_from_date(endDate);
    params.store("startDate", strStartdate)
    params.store("endDate", strEnddate)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/startDate/#{strStartdate}/endDate/#{strEnddate}/count"
    response = connection.get(signature, resource_url, query_params)
    responseObj.strResponse=(response)
    responseObj.isResponseSuccess=(true)
    responseObj = LogResponseBuilder.new()
    responseObj.getTotalRecords(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return responseObj
end

#fetch_logs_count_by_debugObject

Fetch count of log messages based on Debug Level

Returns:

  • App42Response object containing count of fetched debug messages

Raises:

  • App42Exception



838
839
840
# File 'lib/log/LogService.rb', line 838

def fetch_logs_count_by_debug()
  return fetch_logs_count_by_level("DEBUG");
end

#fetch_logs_count_by_errorObject

Fetch count of log messages based on Error Level

Returns:

  • App42Response object containing count of fetched error messages

Raises:

  • App42Exception



850
851
852
# File 'lib/log/LogService.rb', line 850

def fetch_logs_count_by_error()
  return fetch_logs_count_by_level("ERROR");
end

#fetch_logs_count_by_fatalObject

Fetch count of log messages based on Fatal Level

Returns:

  • App42Response object containing count of fetched Fatal messages

Raises:

  • App42Exception



862
863
864
# File 'lib/log/LogService.rb', line 862

def fetch_logs_count_by_fatal()
  return fetch_logs_count_by_level("FATAL");
end

#fetch_logs_count_by_infoObject

Fetch count of log messages based on Info Level

Returns:

  • App42Response object containing count of fetched info messages

Raises:

  • App42Exception



826
827
828
# File 'lib/log/LogService.rb', line 826

def fetch_logs_count_by_info()
  return fetch_logs_count_by_level("INFO");
end

#fetch_logs_count_by_level(level) ⇒ Object

Fetch the count of log messages based on the Level

Parameters:

  • level
    • The level on which count of logs have to be searched

Returns:

  • App42Response object containing count of fetched messages

Raises:

  • App42Exception



784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
# File 'lib/log/LogService.rb', line 784

def fetch_logs_count_by_level(level)
  puts "Fetch Logs Count By Level Called "
  puts "Base url #{@base_url}"
  response = nil
  responseObj = App42Response.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(level, "Level");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("type", level)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/type/#{level}/count"
    response = connection.get(signature, resource_url, query_params)
    puts "Response is #{response}"
    responseObj.strResponse=(response)
    responseObj.isResponseSuccess=(true)
    responseObj = LogResponseBuilder.new()
    responseObj.getTotalRecords(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return responseObj
end

#fetch_logs_count_by_module(moduleName) ⇒ Object

Fetch the count of log messages based on the Module

Parameters:

  • moduleName
    • Module name for which the count of messages has to be fetched

Returns:

  • App42Response object containing count of fetched messages

Raises:

  • App42Exception



691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
# File 'lib/log/LogService.rb', line 691

def fetch_logs_count_by_module(moduleName)
  puts "Fetch Logs Count By Module Called "
  puts "Base url #{@base_url}"
  response = nil
  responseObj = App42Response.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("moduleName", moduleName)
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/module/#{moduleName}/count"
    response = connection.get(signature, resource_url, query_params)
    responseObj.strResponse=(response)
    responseObj.isResponseSuccess=(true)
    responseObj = LogResponseBuilder.new()
    responseObj.getTotalRecords(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return responseObj
end

#fetch_logs_count_by_module_and_text(moduleName, text) ⇒ Object

Fetch count of log messages based on the Module and Message Text

Parameters:

  • moduleName
    • Module name for which the count of messages has to be fetched

  • text
    • The log message on which count of logs have to be searched

Returns:

  • App42Response object containing count of fetched messages

Raises:

  • App42Exception



737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
# File 'lib/log/LogService.rb', line 737

def fetch_logs_count_by_module_and_text(moduleName, text)
  puts "Fetch Logs Count By Module And Text Called "
  puts "Base url #{@base_url}"
  response = nil
  responseObj = App42Response.new
  util = Util.new
  util.throwExceptionIfNullOrBlank(moduleName, "ModuleName");
  util.throwExceptionIfNullOrBlank(text, "Text");
  begin
    connection = App42::Connection::RESTConnection.new(@base_url)
    query_params = Hash.new
    params = {
      'apiKey'=> @api_key,
      'version' => @version,
      'timeStamp' => util.get_timestamp_utc,
    }
    query_params = params.clone
    params.store("moduleName", moduleName)
    params.store("text", text);
    puts query_params
    signature = util.sign(@secret_key, params)
    resource_url = "#{@version}/#{@resource}/module/#{moduleName}/text/#{text}/count"
    response = connection.get(signature, resource_url, query_params)
    puts "Response is #{response}"
    responseObj.strResponse=(response)
    responseObj.isResponseSuccess=(true)
    responseObj = LogResponseBuilder.new()
    responseObj.getTotalRecords(response);
  rescue  App42Exception =>e
    raise e
  rescue  Exception => e
    raise App42Exception.new(e)
  end
  return responseObj
end

#info(msg, appModule) ⇒ Object

Logs the info message

Parameters:

  • msg
    • Message to be logged

  • module
    • Module name for which the message is getting logged

Returns:

  • Log object containing logged message

Raises:

  • App42Exception



110
111
112
# File 'lib/log/LogService.rb', line 110

def info( msg,  appModule)
  return build_and_send(msg, appModule, "info");
end