Class JsonStepLogger

java.lang.Object
io.getlime.security.powerauth.lib.cmd.logging.JsonStepLogger
All Implemented Interfaces:
StepLogger

public class JsonStepLogger extends Object implements StepLogger
Class responsible for logging the steps performed during the processes to the JSON structure.
Author:
Petr Dvorak, petr@wultra.com
  • Constructor Details

    • JsonStepLogger

      public JsonStepLogger(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:
      start in interface StepLogger
    • writeItem

      public void writeItem(String id, String name, String description, String status, Object object)
      Writes a JSON object representing the step of the execution.
      Specified by:
      writeItem in interface StepLogger
      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(String id, String uri, String method, Object requestObject, byte[] requestBytes, Map<String,?> headers)
      Write the information about the server call. Uses "writeItem" method under the hood.
      Specified by:
      writeServerCall in interface StepLogger
      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.
      requestBytes - Request bytes, in case of the POST, PUT, DELETE method.
      headers - HTTP request headers.
    • writeServerCallOK

      public void writeServerCallOK(String id, Object responseObject, Map<String,?> headers)
      Write information about the successful server request. Uses "writeItem" method under the hood.
      Specified by:
      writeServerCallOK in interface StepLogger
      Parameters:
      id - Step ID.
      responseObject - HTTP response object.
      headers - HTTP response headers.
    • writeServerCallError

      public void writeServerCallError(String id, int statusCode, Object responseObject, Map<String,?> headers)
      Write information about the failed server request. Uses "writeItem" method under the hood.
      Specified by:
      writeServerCallError in interface StepLogger
      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:
      close in interface StepLogger
    • writeServerCallConnectionError

      public void writeServerCallConnectionError(String id, Exception e)
      Write error in case of a network issues.
      Specified by:
      writeServerCallConnectionError in interface StepLogger
      Parameters:
      id - Step ID.
      e - Network exception.
    • writeError

      public void writeError(String id, String errorMessage)
      Write error with given error message. Error message is mapped as a step description.
      Specified by:
      writeError in interface StepLogger
      Parameters:
      id - Step ID.
      errorMessage - Error message.
    • writeError

      public void writeError(String id, 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:
      writeError in interface StepLogger
      Parameters:
      id - Step ID.
      exception - Exception that should be logged.
    • writeError

      public void writeError(String id, String name, String errorMessage)
      Write error with given error name and error message, that is used as a description.
      Specified by:
      writeError in interface StepLogger
      Parameters:
      id - Step ID.
      name - Error name.
      errorMessage - Error message.
    • writeError

      public void writeError(String id, String name, String errorMessage, Exception exception)
      Write error with given error name and error message, that is used as a description.
      Specified by:
      writeError in interface StepLogger
      Parameters:
      id - Step ID.
      name - Error name.
      errorMessage - Error message.
      exception - Exception that caused the error.
    • writeDoneOK

      public void writeDoneOK(String id)
      Write information about successfully finished execution.
      Specified by:
      writeDoneOK in interface StepLogger
      Parameters:
      id - Step ID.
    • writeDoneFailed

      public void writeDoneFailed(String id)
      Write information about incorrectly finished execution.
      Specified by:
      writeDoneFailed in interface StepLogger
      Parameters:
      id - Step ID.