Display the paramiko log for Azure Function in python on Azure

Viewed 77

I'd like to know how to display the paramiko log (same log as would be written to a file when running paramiko.util.log_to_file("paramiko.log")) when running the following Azure Function in python on Azure. When I run the code on my local computer I do get the paramiko log output, but not when the Azure Function is run on Azure.

import datetime
import logging
import azure.functions as func
from azure.identity import DefaultAzureCredential
from azure.keyvault.secrets import SecretClient
import paramiko


def main(mytimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(
        tzinfo=datetime.timezone.utc).isoformat()

    if mytimer.past_due:
        logging.info('The timer is past due!')

    logging.Logger.root.level = 10
    logging.basicConfig()
    logging.getLogger("paramiko").setLevel(logging.DEBUG)
          
    # Used for getting access to secrets on Azure key vault for authentication purposes
    credential = DefaultAzureCredential()

    secret_client = SecretClient(vault_url="InsertVaultURL", credential=credential)
    secret_name = secret_client.get_secret("InsertSecretUsernameName")
    secret_pass = secret_client.get_secret("InsertSecretPasswordName")
    secret_host_key = secret_client.get_secret("InsertSecretHostKeyName")
    
    # Server name for FSTP server 
    host_name = 'InsertFSTPHostAddress'
          
    # Connecting to FSTP server
    ssh = paramiko.SSHClient()
    ssh.get_host_keys().add(hostname = host_name, keytype='ssh-rsa', key = paramiko.PKey(data = secret_host_key.value.encode('ascii')))
    ssh.load_system_host_keys()
    ssh.connect(hostname = host_name, port = 22, username=secret_name.value, password=secret_pass.value)
    sftp = ssh.open_sftp()

    # Perform some activity with SFTP connection

    # Close the SFTP session
    sftp.close()

    # Close SSH Client
    ssh.close()

My host.json file has the following contents:

{
  "version":  "2.0",
  "logging": {
    "fileLoggingMode": "always",
    "logLevel": {
      "default": "Debug"
    }
  },
  "extensionBundle": {
    "id": "Microsoft.Azure.Functions.ExtensionBundle",
    "version": "[2.*, 3.0.0)"
  }
}

I have also included PYTHON_ENABLE_DEBUG_LOGGING = 1 in the configuration settings of my Azure Function on the Azure Portal to no avail.

0 Answers
Related