docstr: Creates and returns WebSocketApp to listen to lightning app logs.
  
      .. code-block:: python
          # Synchronous reading, run_forever() is blocking
  
  
          def print_log_msg(ws_app, msg):
              print(msg)
  
  
          flow_logs_socket = client.create_lightning_logs_socket("project_id", "app_id", "flow", print_log_msg)
          flow_socket.run_forever()
  
      .. code-block:: python
          # Asynchronous reading (with Threads)
  
  
          def print_log_msg(ws_app, msg):
              print(msg)
  
  
          flow_logs_socket = client.create_lightning_logs_socket("project_id", "app_id", "flow", print_log_msg)
          work_logs_socket = client.create_lightning_logs_socket("project_id", "app_id", "work_1", print_log_msg)
  
          flow_logs_thread = Thread(target=flow_logs_socket.run_forever)
          work_logs_thread = Thread(target=work_logs_socket.run_forever)
  
          flow_logs_thread.start()
          work_logs_thread.start()
          # .......
  
          flow_logs_socket.close()
          work_logs_thread.close()
  
  Arguments:
      project_id: Project ID.
      app_id: Application ID.
      component: Component name eg flow.
      on_message_callback: Callback object which is called when received data.
      on_error_callback: Callback object which is called when we get error.
  
  Returns:
      WebSocketApp of the wanted socket
docstr_tok: ["Creates","and","returns","WebSocketApp","to","listen","to","lightning","app","logs",".","..","code-block",":",":","python","#","Synchronous","reading",",","run_forever","(",")","is","blocking","def","print_log_msg","(","ws_app",",","msg",")",":","print","(","msg",")","flow_logs_socket","=","client.create_lightning_logs_socket","(","``","project_id","''",",","``","app_id","''",",","``","flow","''",",","print_log_msg",")","flow_socket.run_forever","(",")","..","code-block",":",":","python","#","Asynchronous","reading","(","with","Threads",")","def","print_log_msg","(","ws_app",",","msg",")",":","print","(","msg",")","flow_logs_socket","=","client.create_lightning_logs_socket","(","``","project_id","''",",","``","app_id","''",",","``","flow","''",",","print_log_msg",")","work_logs_socket","=","client.create_lightning_logs_socket","(","``","project_id","''",",","``","app_id","''",",","``","work_1","''",",","print_log_msg",")","flow_logs_thread","=","Thread","(","target=flow_logs_socket.run_forever",")","work_logs_thread","=","Thread","(","target=work_logs_socket.run_forever",")","flow_logs_thread.start","(",")","work_logs_thread.start","(",")","#",".......","flow_logs_socket.close","(",")","work_logs_thread.close","(",")","Arguments",":","project_id",":","Project","ID",".","app_id",":","Application","ID",".","component",":","Component","name","eg","flow",".","on_message_callback",":","Callback","object","which","is","called","when","received","data",".","on_error_callback",":","Callback","object","which","is","called","when","we","get","error",".","Returns",":","WebSocketApp","of","the","wanted","socket"]
code: def create_lightning_logs_socket(
      self,
      project_id: str,
      app_id: str,
      component: str,
      on_message_callback: Callable,
      on_error_callback: Optional[Callable] = None,
  ) -> WebSocketApp:
      """Creates and returns WebSocketApp to listen to lightning app logs.
  
          .. code-block:: python
              # Synchronous reading, run_forever() is blocking
  
  
              def print_log_msg(ws_app, msg):
                  print(msg)
  
  
              flow_logs_socket = client.create_lightning_logs_socket("project_id", "app_id", "flow", print_log_msg)
              flow_socket.run_forever()
  
          .. code-block:: python
              # Asynchronous reading (with Threads)
  
  
              def print_log_msg(ws_app, msg):
                  print(msg)
  
  
              flow_logs_socket = client.create_lightning_logs_socket("project_id", "app_id", "flow", print_log_msg)
              work_logs_socket = client.create_lightning_logs_socket("project_id", "app_id", "work_1", print_log_msg)
  
              flow_logs_thread = Thread(target=flow_logs_socket.run_forever)
              work_logs_thread = Thread(target=work_logs_socket.run_forever)
  
              flow_logs_thread.start()
              work_logs_thread.start()
              # .......
  
              flow_logs_socket.close()
              work_logs_thread.close()
  
      Arguments:
          project_id: Project ID.
          app_id: Application ID.
          component: Component name eg flow.
          on_message_callback: Callback object which is called when received data.
          on_error_callback: Callback object which is called when we get error.
  
      Returns:
          WebSocketApp of the wanted socket
  
      """
      _token = self._get_api_token()
      clean_ws_host = urlparse(
          self.api_client.configuration.host
      ).netloc
      socket_url = self._app_logs_socket_url(
          host=clean_ws_host,
          project_id=project_id,
          app_id=app_id,
          token=_token,
          component=component,
      )
  
      return WebSocketApp(
          socket_url,
          on_message=on_message_callback,
          on_error=on_error_callback,
      )
  
file_path: pytorch-lightning/src/lightning/app/utilities/logs_socket_api.py
imports: from typing import Callable, Optional
  from urllib.parse import urlparse
  from websocket import WebSocketApp
  from lightning.app.utilities.auth import _AuthTokenGetter
label_desc: Use image node_id 2 for calling the _LightningLogsSocketAPI obj's underlying member method code with example usage: obj.create_lightning_logs_socket(project_id, app_id, component, on_message_callback, on_error_callback) and returns: WebSocketApp