Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
Allow to set logging level for process instance
Change logging level with third-party system responses from info to debug
  • Loading branch information
dolfinus committed Nov 30, 2019
1 parent e9e887e commit c8f543b
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 41 deletions.
82 changes: 73 additions & 9 deletions docs/index-all.html

Large diffs are not rendered by default.

41 changes: 34 additions & 7 deletions docs/org/camunda/latera/bss/SimpleLogger.html
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,21 @@ <h3>Properties Summary</h3>
</tr>

<tr class="altColor">
<td class="colFirst"><code><strong><a href='http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html' title='Integer'>Integer</a></strong></code>&nbsp;</td>
<td class="colLast"><code><a href="#currentLevel">currentLevel</a></code><br></td>
</tr>

<tr class="rowColor">
<td class="colFirst"><code><strong><a href='http://download.oracle.com/javase/6/docs/api/java/time/format/DateTimeFormatter.html' title='DateTimeFormatter'>DateTimeFormatter</a></strong></code>&nbsp;</td>
<td class="colLast"><code><a href="#dateFormat">dateFormat</a></code><br></td>
</tr>

<tr class="rowColor">
<tr class="altColor">
<td class="colFirst"><code><strong><a href='http://download.oracle.com/javase/6/docs/api/java/lang/String.html' title='String'>String</a></strong></code>&nbsp;</td>
<td class="colLast"><code><a href="#homsOrderCode">homsOrderCode</a></code><br></td>
</tr>

<tr class="altColor">
<tr class="rowColor">
<td class="colFirst"><code><strong><a href='http://download.oracle.com/javase/6/docs/api/java/lang/String.html' title='String'>String</a></strong></code>&nbsp;</td>
<td class="colLast"><code><a href="#processInstanceId">processInstanceId</a></code><br></td>
</tr>
Expand Down Expand Up @@ -226,23 +231,29 @@ <h3>Methods Summary</h3>

<tr class="altColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code>void</code></td>
<td class="colLast"><code><strong><a href="#log(org.camunda.latera.bss.connectors.hoper.hydra.Object, java.lang.CharSequence)">log</a></strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html' title='CharSequence'>CharSequence</a> level = "info")</code><br></td>
<td class="colLast"><code>static&nbsp;<a href='http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html' title='Integer'>Integer</a></code></td>
<td class="colLast"><code><strong><a href="#levelToInt(java.lang.CharSequence)">levelToInt</a></strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html' title='CharSequence'>CharSequence</a> level)</code><br></td>
</tr>

<tr class="rowColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code>void</code></td>
<td class="colLast"><code><strong><a href="#log_oracle(org.camunda.latera.bss.connectors.hoper.hydra.Object, java.lang.CharSequence)">log_oracle</a></strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html' title='CharSequence'>CharSequence</a> level = 'info')</code><br></td>
<td class="colLast"><code><strong><a href="#log(org.camunda.latera.bss.connectors.hoper.hydra.Object, java.lang.CharSequence)">log</a></strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html' title='CharSequence'>CharSequence</a> level = 'info')</code><br></td>
</tr>

<tr class="altColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code>void</code></td>
<td class="colLast"><code><strong><a href="#warn(org.camunda.latera.bss.connectors.hoper.hydra.Object)">warn</a></strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message)</code><br></td>
<td class="colLast"><code><strong><a href="#log_oracle(org.camunda.latera.bss.connectors.hoper.hydra.Object, java.lang.CharSequence)">log_oracle</a></strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html' title='CharSequence'>CharSequence</a> level = 'info')</code><br></td>
</tr>

<tr class="rowColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code>void</code></td>
<td class="colLast"><code><strong><a href="#warn(org.camunda.latera.bss.connectors.hoper.hydra.Object)">warn</a></strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message)</code><br></td>
</tr>

<tr class="altColor">
<td class="colFirst"><code></code></td>
<td class="colLast"><code>void</code></td>
<td class="colLast"><code><strong><a href="#warn_oracle(org.camunda.latera.bss.connectors.hoper.hydra.Object)">warn_oracle</a></strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message)</code><br></td>
Expand Down Expand Up @@ -291,6 +302,14 @@ <h3>Inherited Methods Summary</h3>
</a>
<h3>Property Detail</h3>

<a name="currentLevel"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4><a href='http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html' title='Integer'>Integer</a> <strong>currentLevel</strong></h4>
<p></p>
</li>
</ul>

<a name="dateFormat"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
Expand Down Expand Up @@ -398,10 +417,18 @@ <h4>void <strong>info_oracle</strong>(<a href='../../../../org/camunda/latera/bs
</li>
</ul>

<a name="levelToInt(java.lang.CharSequence)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>static&nbsp;<a href='http://download.oracle.com/javase/6/docs/api/java/lang/Integer.html' title='Integer'>Integer</a> <strong>levelToInt</strong>(<a href='http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html' title='CharSequence'>CharSequence</a> level)</h4>
<p></p>
</li>
</ul>

<a name="log(org.camunda.latera.bss.connectors.hoper.hydra.Object, java.lang.CharSequence)"><!-- --></a>
<ul class="blockListLast">
<li class="blockList">
<h4>void <strong>log</strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html' title='CharSequence'>CharSequence</a> level = "info")</h4>
<h4>void <strong>log</strong>(<a href='../../../../org/camunda/latera/bss/connectors/hoper/hydra/Object.html'>Object</a> message, <a href='http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html' title='CharSequence'>CharSequence</a> level = 'info')</h4>
<p></p>
</li>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion src/org/camunda/latera/bss/connectors/Imprint.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
12 changes: 6 additions & 6 deletions src/org/camunda/latera/bss/console.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/org/camunda/latera/bss/http.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}" {
Expand Down
31 changes: 26 additions & 5 deletions src/org/camunda/latera/bss/logging.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit c8f543b

Please sign in to comment.