Class JsonStepLogger
java.lang.Object
io.getlime.security.powerauth.lib.cmd.logging.JsonStepLogger
- All Implemented Interfaces:
StepLogger
public class JsonStepLogger extends java.lang.Object implements StepLogger
Class responsible for logging the steps performed during the processes to the JSON structure.
- Author:
- Petr Dvorak, petr@wultra.com
-
Constructor Summary
Constructors Constructor Description JsonStepLogger(java.io.OutputStream outputStream)Create a new logger that outputs to the stream. -
Method Summary
Modifier and Type Method Description voidclose()Closes the logger output, writes code to close the array and opened object: // ] // }voidstart()Start the object streaming, outputs start of the JSON object: // { // "steps" : [voidwriteDoneFailed(java.lang.String id)Write information about incorrectly finished execution.voidwriteDoneOK(java.lang.String id)Write information about successfully finished execution.voidwriteError(java.lang.String id, java.lang.Exception exception)Write error with given exception information.voidwriteError(java.lang.String id, java.lang.String errorMessage)Write error with given error message.voidwriteError(java.lang.String id, java.lang.String name, java.lang.String errorMessage)Write error with given error name and error message, that is used as a description.voidwriteError(java.lang.String id, java.lang.String name, java.lang.String errorMessage, java.lang.Exception exception)Write error with given error name and error message, that is used as a description.voidwriteItem(java.lang.String id, java.lang.String name, java.lang.String description, java.lang.String status, java.lang.Object object)Writes a JSON object representing the step of the execution.voidwriteServerCall(java.lang.String id, java.lang.String uri, java.lang.String method, java.lang.Object requestObject, java.util.Map<java.lang.String,?> headers)Write the information about the server call.voidwriteServerCallConnectionError(java.lang.String id, java.lang.Exception e)Write error in case of a network issues.voidwriteServerCallError(java.lang.String id, int statusCode, java.lang.Object responseObject, java.util.Map<java.lang.String,?> headers)Write information about the failed server request.voidwriteServerCallOK(java.lang.String id, java.lang.Object responseObject, java.util.Map<java.lang.String,?> headers)Write information about the successful server request.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
JsonStepLogger
public JsonStepLogger(java.io.OutputStream outputStream)Create a new logger that outputs to the stream.- Parameters:
outputStream- Output stream.
-
-
Method Details
-
start
public void start()Start the object streaming, outputs start of the JSON object: // { // "steps" : [- Specified by:
startin interfaceStepLogger
-
writeItem
public void writeItem(java.lang.String id, java.lang.String name, java.lang.String description, java.lang.String status, java.lang.Object object)Writes a JSON object representing the step of the execution.- Specified by:
writeItemin interfaceStepLogger- Parameters:
id- Step ID.name- Step name.description- Step detailed description.status- Step status result.object- Custom object associated with the step.
-
writeServerCall
public void writeServerCall(java.lang.String id, java.lang.String uri, java.lang.String method, java.lang.Object requestObject, java.util.Map<java.lang.String,?> headers)Write the information about the server call. Uses "writeItem" method under the hood.- Specified by:
writeServerCallin interfaceStepLogger- Parameters:
id- Step ID.uri- URI that will be called.method- HTTP method of the call.requestObject- Request object, in case of the POST, PUT, DELETE method.headers- HTTP request headers.
-
writeServerCallOK
public void writeServerCallOK(java.lang.String id, java.lang.Object responseObject, java.util.Map<java.lang.String,?> headers)Write information about the successful server request. Uses "writeItem" method under the hood.- Specified by:
writeServerCallOKin interfaceStepLogger- Parameters:
id- Step ID.responseObject- HTTP response object.headers- HTTP response headers.
-
writeServerCallError
public void writeServerCallError(java.lang.String id, int statusCode, java.lang.Object responseObject, java.util.Map<java.lang.String,?> headers)Write information about the failed server request. Uses "writeItem" method under the hood.- Specified by:
writeServerCallErrorin interfaceStepLogger- Parameters:
id- Step ID.statusCode- HTTP response status code.responseObject- HTTP response object.headers- HTTP response headers.
-
close
public void close()Closes the logger output, writes code to close the array and opened object: // ] // }- Specified by:
closein interfaceStepLogger
-
writeServerCallConnectionError
public void writeServerCallConnectionError(java.lang.String id, java.lang.Exception e)Write error in case of a network issues.- Specified by:
writeServerCallConnectionErrorin interfaceStepLogger- Parameters:
id- Step ID.e- Network exception.
-
writeError
public void writeError(java.lang.String id, java.lang.String errorMessage)Write error with given error message. Error message is mapped as a step description.- Specified by:
writeErrorin interfaceStepLogger- Parameters:
id- Step ID.errorMessage- Error message.
-
writeError
public void writeError(java.lang.String id, java.lang.Exception exception)Write error with given exception information. Exception description is mapped as a step description, exception is passed as a custom object.- Specified by:
writeErrorin interfaceStepLogger- Parameters:
id- Step ID.exception- Exception that should be logged.
-
writeError
public void writeError(java.lang.String id, java.lang.String name, java.lang.String errorMessage)Write error with given error name and error message, that is used as a description.- Specified by:
writeErrorin interfaceStepLogger- Parameters:
id- Step ID.name- Error name.errorMessage- Error message.
-
writeError
public void writeError(java.lang.String id, java.lang.String name, java.lang.String errorMessage, java.lang.Exception exception)Write error with given error name and error message, that is used as a description.- Specified by:
writeErrorin interfaceStepLogger- Parameters:
id- Step ID.name- Error name.errorMessage- Error message.exception- Exception that caused the error.
-
writeDoneOK
public void writeDoneOK(java.lang.String id)Write information about successfully finished execution.- Specified by:
writeDoneOKin interfaceStepLogger- Parameters:
id- Step ID.
-
writeDoneFailed
public void writeDoneFailed(java.lang.String id)Write information about incorrectly finished execution.- Specified by:
writeDoneFailedin interfaceStepLogger- Parameters:
id- Step ID.
-