From c8f543bae8de15db223bbe1fe49c08cfe7cab245 Mon Sep 17 00:00:00 2001 From: dolfinus Date: Sat, 30 Nov 2019 14:44:22 +0300 Subject: [PATCH] Improve logging Allow to set logging level for process instance Change logging level with third-party system responses from info to debug --- docs/index-all.html | 82 +++++++++++++++++-- docs/org/camunda/latera/bss/SimpleLogger.html | 41 ++++++++-- .../latera/bss/connectors/Imprint.groovy | 2 +- src/org/camunda/latera/bss/console.groovy | 12 +-- .../AutoSaveOrderData.groovy | 2 +- src/org/camunda/latera/bss/http.groovy | 24 +++--- src/org/camunda/latera/bss/logging.groovy | 31 +++++-- 7 files changed, 153 insertions(+), 41 deletions(-) diff --git a/docs/index-all.html b/docs/index-all.html index df5d8c74..27ac04a0 100644 --- a/docs/index-all.html +++ b/docs/index-all.html @@ -333,6 +333,8 @@

C

closeTask(String) - Method in Task
+
closeTimerTask() - Method in Task +
closeWaitTask() - Method in Task
Company - Trait in org.camunda.latera.bss.helpers.hydra @@ -514,8 +516,12 @@

D

Convert map keys to camelCase.
deepSnakeCaseKeys(List) - Method in MapUtil
Convert map keys to snake_case.
+
deleteAddAgreementAddParam(Map) - Method in Contract +
deleteAddress(def, def, def) - Method in Address
+
deleteBaseSubjectAddParam(Map) - Method in BaseSubject +
deleteBaseSubjectAddress(Map) - Method in Address
deleteBaseSubjectEmail(Map) - Method in Address @@ -532,6 +538,10 @@

D

deleteComponent(def) - Method in Equipment
+
deleteContractAddParam(Map) - Method in Contract +
+
deleteContractAppAddParam(Map) - Method in Contract +
deleteCountry(def) - Method in Country
deleteCountryState(def) - Method in Country @@ -540,6 +550,8 @@

D

deleteCustomerAccount(def, def) - Method in Account
+
deleteCustomerAddParam(Map) - Method in Customer +
deleteCustomerContract(def, def) - Method in Contract
deleteCustomerEquipment(def, def) - Method in Equipment @@ -679,7 +691,7 @@

E

Convert some class values before get JSON representation.
EventLogging - Class in org.camunda.latera.bss.executionListeners
-
execute(CharSequence, Map) - Method in HID +
execute(Map, CharSequence) - Method in HID
executeBill(def) - Method in Bill
@@ -696,12 +708,16 @@

F

fetchAddAgreement(Map) - Method in Contract
+
fetchAddAgreementAddParam(Map) - Method in Contract +
fetchAddress(Map) - Method in Address
fetchAppAccess(Map) - Method in Customer
fetchBaseSubject(Map) - Method in BaseSubject
+
fetchBaseSubjectAddParam(Map) - Method in BaseSubject +
fetchBaseSubjectAddress(Map) - Method in Address
fetchBaseSubjectContacts(Map) - Method in Address @@ -718,12 +734,18 @@

F

fetchContract(Map) - Method in Contract
+
fetchContractAddParam(Map) - Method in Contract +
fetchContractApp(Map) - Method in Contract
+
fetchContractAppAddParam(Map) - Method in Contract +
fetchCustomer(Map) - Method in Customer
fetchCustomerAccount(Map) - Method in Account
+
fetchCustomerAddParam(Map) - Method in Customer +
fetchCustomerByAccount(Map) - Method in Customer
fetchCustomerFirstContract(Map) - Method in Contract @@ -734,6 +756,8 @@

F

fetchEquipment(Map) - Method in Equipment
+
fetchEquipmentAddParam(Map) - Method in Equipment +
fetchEquipmentAddress(Map) - Method in Address
fetchEquipmentBind(Map) - Method in Equipment @@ -784,12 +808,16 @@

F

fetchReseller(Map) - Method in Reseller
+
fetchResellerAddParam(Map) - Method in Reseller +
fetchResellerCustomer(Map) - Method in Reseller
fetchSelfCareAccess(Map) - Method in Customer
fetchService(Map) - Method in Service
+
fetchServiceAddParam(Map) - Method in Service +
fetchServiceSubscription(Map) - Method in Service
fetchSubscription(Map) - Method in Service @@ -867,7 +895,11 @@

G

getAddAgreementTypeId() - Method in Contract
-
getAddParamDataType(Map) - Method in AddParam +
getAddParamDataType(Map, def) - Method in AddParam +
+
getAddParamValue(Map, Map) - Method in AddParam +
+
getAddParamValueRaw(Map, Boolean) - Method in AddParam
getAddress(def) - Method in Address
@@ -965,6 +997,10 @@

G

getChargeReservedTypeId() - Method in Invoice
+
getCharType() - Method in DataType +
+
getCharTypeId() - Method in DataType +
getCheckTask() - Method in Task
getChildSubscription(def, def, def) - Method in Subscription @@ -1375,10 +1411,6 @@

G

getFirmId() - Method in Hydra
-
getFlagType() - Method in DataType -
-
getFlagTypeId() - Method in DataType -
getFloatType() - Method in DataType
getFloatTypeId() - Method in DataType @@ -1503,6 +1535,14 @@

G

getInvoiceTypeId() - Method in Invoice
+
getIPGateway(CharSequence) - Method in Address +
+
getIPGatewayById(def) - Method in Address +
+
getIPMask(CharSequence) - Method in Address +
+
getIPMaskById(def) - Method in Address +
getIPv6Mask() - Method in Address
getISPApplication() - Method in Customer @@ -1903,14 +1943,26 @@

G

getSubjectTypeId(def) - Method in Subject
+
getSubnetAddressByVLAN(Map) - Method in Address +
+
getSubnetAddressesByVLAN(Map) - Method in Address +
getSubnetByIP(CharSequence) - Method in Address
+
getSubnetByVLAN(Map) - Method in Address +
+
getSubnetGateway(CharSequence) - Method in Address +
+
getSubnetGatewayById(def) - Method in Address +
getSubnetIdByIP(CharSequence) - Method in Address
getSubnetMask(CharSequence) - Method in Address
getSubnetMaskById(def) - Method in Address
+
getSubnetv6Mask() - Method in Address +
getSubscription(def) - Method in Subscription
getSubscriptionBy(Map) - Method in Subscription @@ -1921,8 +1973,6 @@

G

getSubscriptionsTable() - Method in Subscription
-
getSuubnetv6Mask() - Method in Address -
getTableColumns(CharSequence, CharSequence) - Method in Table
getTableData(Map) - Method in Table @@ -1933,6 +1983,8 @@

G

getTicket(def) - Method in Ticket
+
getTimerTask() - Method in Task +
getUnknownUnit() - Method in Ref
getUnknownUnitId() - Method in Ref @@ -2102,7 +2154,7 @@

I

isInteger(def) - Method in Numeric
Check whether input is Integer or not.
isIntegerStrict(def) - Method in Numeric -
Check whether input is Integer or not.
+
Check whether input is Integer or not.
isIntStrict(def) - Method in Numeric
Check whether input is Integer or not.
isInvoice(def) - Method in Invoice @@ -2165,6 +2217,8 @@

L

leftShift(def) - Method in CSV
<< operator overload.
+
levelToInt(CharSequence) - Method in SimpleLogger +
ListUtil - Class in org.camunda.latera.bss.utils
local(ZonedDateTime) - Method in DateTimeUtil @@ -2653,12 +2707,22 @@

R

S

+
saveAddAgreementAddParam(Map) - Method in Contract +
+
saveBaseSubjectAddParam(Map) - Method in BaseSubject +
+
saveContractAddParam(Map) - Method in Contract +
+
saveContractAppAddParam(Map) - Method in Contract +
saveCustomerAddParam(Map) - Method in Customer
saveData(Map, Boolean) - Method in Order
saveDataRaw(Map) - Method in Order
+
saveEquipmentAddParam(Map) - Method in Equipment +
SaveOrderData - Class in org.camunda.latera.bss.executionListeners
saveOrderData() - Method in HOMS diff --git a/docs/org/camunda/latera/bss/SimpleLogger.html b/docs/org/camunda/latera/bss/SimpleLogger.html index d2f1819c..292b44f8 100644 --- a/docs/org/camunda/latera/bss/SimpleLogger.html +++ b/docs/org/camunda/latera/bss/SimpleLogger.html @@ -126,16 +126,21 @@

Properties Summary

+ Integer  + currentLevel
+ + + DateTimeFormatter  dateFormat
- + String  homsOrderCode
- + String  processInstanceId
@@ -226,23 +231,29 @@

Methods Summary

- void - log(Object message, CharSequence level = "info")
+ static Integer + levelToInt(CharSequence level)
void - log_oracle(Object message, CharSequence level = 'info')
+ log(Object message, CharSequence level = 'info')
void - warn(Object message)
+ log_oracle(Object message, CharSequence level = 'info')
+ + void + warn(Object message)
+ + + void warn_oracle(Object message)
@@ -291,6 +302,14 @@

Inherited Methods Summary

Property Detail

+ + + + diff --git a/src/org/camunda/latera/bss/connectors/Imprint.groovy b/src/org/camunda/latera/bss/connectors/Imprint.groovy index 15ad16c0..63cafd54 100644 --- a/src/org/camunda/latera/bss/connectors/Imprint.groovy +++ b/src/org/camunda/latera/bss/connectors/Imprint.groovy @@ -37,7 +37,7 @@ class Imprint { } def print(CharSequence template, Map data = [:]) { - this.logger.info('Printing begin...') + logger.info('Printing begin...') if (!data) { data = Order.getData(execution) } diff --git a/src/org/camunda/latera/bss/console.groovy b/src/org/camunda/latera/bss/console.groovy index eecab5f0..0f82af07 100644 --- a/src/org/camunda/latera/bss/console.groovy +++ b/src/org/camunda/latera/bss/console.groovy @@ -35,17 +35,17 @@ class Console { logger.info("Exit code: ${proc.exitValue()}") if (!supressStdout) { - logger.info('Stdout:') - logger.info(stdout) + logger.debug('Stdout:') + logger.debug(stdout) } if (!supressStderr) { if (proc.exitValue()) { - logger.error('Sterr:') - logger.error(stderr) + logger.debug('Sterr:') + logger.debug(stderr) } else { - logger.info('Sterr:') - logger.info(stderr) + logger.debug('Sterr:') + logger.debug(stderr) } } return [proc: proc, stdout: stdout, stderr: stderr] diff --git a/src/org/camunda/latera/bss/executionListeners/AutoSaveOrderData.groovy b/src/org/camunda/latera/bss/executionListeners/AutoSaveOrderData.groovy index 4183737a..0076a83a 100644 --- a/src/org/camunda/latera/bss/executionListeners/AutoSaveOrderData.groovy +++ b/src/org/camunda/latera/bss/executionListeners/AutoSaveOrderData.groovy @@ -17,7 +17,7 @@ class AutoSaveOrderData implements ExecutionListener { def homs = new HOMS(execution) homs.saveOrderData() } else { - logger.info('Order data has not changed, save not needed') + logger.debug('Order data has not changed, save not needed') } } } diff --git a/src/org/camunda/latera/bss/http.groovy b/src/org/camunda/latera/bss/http.groovy index 648f5940..fc74e451 100644 --- a/src/org/camunda/latera/bss/http.groovy +++ b/src/org/camunda/latera/bss/http.groovy @@ -71,23 +71,23 @@ class HTTPRestProcessor { def private responseBlock(Boolean failure = false, Boolean supress = false) { {FromServer response, Object data -> - logger.info("Response status: ${response.statusCode}") - logger.info("Content-Type: ${response.contentType}") - logger.info("Response data: -----") + logger.debug("Response status: ${response.statusCode}") + logger.debug("Content-Type: ${response.contentType}") + logger.debug("Response data: -----") if (data) { if (supress) { - logger.info("*Supressing response data*") + logger.debug("*Supressing response data*") } else { if (data instanceof byte[]) { - logger.info(new String(data)) + logger.debug(new String(data)) } else { - logger.info(data.toString()) + logger.debug(data.toString()) } } } else { - logger.info("*Empty response*") + logger.debug("*Empty response*") } - logger.info("--------------------") + logger.debug("--------------------") if (failure) { throw new HttpException(response, data) @@ -119,13 +119,13 @@ class HTTPRestProcessor { params.body = escape(params.body) } if (params.body || params.query) { - logger.info("Request data: ------") + logger.debug("Request data: ------") if (supressRequestBody) { - logger.info("*Supressing request data*") + logger.debug("*Supressing request data*") } else { - logger.info(params.body ? params.body.toString() : params.query.toString()) + logger.debug(params.body ? params.body.toString() : params.query.toString()) } - logger.info("--------------------") + logger.debug("--------------------") } def result = httpClient."${method}" { diff --git a/src/org/camunda/latera/bss/logging.groovy b/src/org/camunda/latera/bss/logging.groovy index 22646401..22766e44 100644 --- a/src/org/camunda/latera/bss/logging.groovy +++ b/src/org/camunda/latera/bss/logging.groovy @@ -33,19 +33,40 @@ class SimpleLogger { String processInstanceId String homsOrderCode DateTimeFormatter dateFormat + Integer currentLevel SimpleLogger(DelegateExecution execution) { this.processInstanceId = execution.getProcessInstanceId() this.homsOrderCode = execution.getVariable('homsOrderCode') ?: 'ORD-NONE' this.dateFormat = execution.getVariable('loggingDateFormat') ? DateTimeFormatter.ofPattern(execution.getVariable('loggingDateFormat')) : DATE_TIME_FORMAT + this.currentLevel = levelToInt(execution.getVariable('loggingLevel') ?: 'info') } - void log(Object message, CharSequence level = "info") { - String timestamp = format(local(), this.dateFormat) - String logPrefix = "${timestamp} ${processInstanceId} [${homsOrderCode}] ${level.toUpperCase().padRight(5, ' ')} - ".toString() + static Integer levelToInt(CharSequence level) { + switch (level) { + case 'debug': + return 0 + case 'info': + return 1 + case ['warn', 'warning']: + return 2 + case ['err', 'error']: + return 3 + case ['crit', 'critical']: + return 4 + default: + return 5 + } + } + + void log(Object message, CharSequence level = 'info') { + if (levelToInt(level) >= this.currentLevel) { + String timestamp = format(local(), this.dateFormat) + String logPrefix = "${timestamp} ${processInstanceId} [${homsOrderCode}] ${level.toUpperCase().padRight(5, ' ')} - ".toString() - message.toString().split('\n').each { def it -> - println(logPrefix + it) + message.toString().split('\n').each { def it -> + println(logPrefix + it) + } } }