Storing and Viewing Function Logs

When a function is invoked, you'll typically want to access the function's logs for troubleshooting. The Oracle Cloud Infrastructure Logging service is the default and recommended option for accessing, searching, and storing function logs. See Using the Console to Enable and View Function Logs in Oracle Cloud Infrastructure Logging. For more information about the contents of function logs, see Details for Functions.

Alternatively, there might be occasions when you want to send function logs to an external logging destination like Papertrail. To send logs to an external logging destination instead of the Oracle Cloud Infrastructure Logging service, you use the Fn Project CLI to specify a syslog URL. See Using Fn Project CLI Commands to Specify a syslog URL.

Note that to store and view logs for a function, the function must include print statements. For example:
  • For node.js: console.log('Entering Hello Node.js function');
  • For java: System.err.println("Entering Java Hello World Function");
  • For go: fmt.Println("Entering Hello Go function")

Using the Console to Enable and View Function Logs in Oracle Cloud Infrastructure Logging

To enable and view function logs in the Oracle Cloud Infrastructure Logging service:

  1. Log in to the Console as a functions developer.
  2. In the Console, open the navigation menu. Under Solutions and Platform, go to Developer Services and click Functions.
  3. Select the region and compartment containing the application with functions for which you want to create, enable, and view logs.

    The Applications page shows all the applications in the compartment you selected.

  4. Select the application with functions for which you want to create, enable, and view logs.
  5. To create and enable a new function log in the Oracle Cloud Infrastructure Logging service:
    1. Under Resources, click Logs, click the Actions icon (three dots), and then click Enable Log and specify:
      • Compartment: The compartment in which to create the new log. By default, the current compartment.
      • Log Group: The log group in which to create the new log. Select an existing log group, or select:
        • Auto-create a default log group to create a default log group with a default name (DEFAULT_GROUP), if one doesn't exist already.
        • Create a new log group to create a new log group with a name and description that you provide.
      • Log Name: The name of the new log. By default, <application-name>_invoke .
      • Log Retention: The length of time to retain log data.
    2. Click Enable Log to create the new log (and the new log group, if you specified one).

    For more information, see Enabling Logging for a Resource.

  6. To enable an existing function log, under Resources, click Logs, click the Actions icon (three dots), and then click Enable Log.
  7. To view the data in an existing function log, under Resources, click Logs, and then click the name of the log you want to view in the Log Name column.

    The log opens in the log group's Log Details page, enabling you to sort and filter log data by time.

Using Fn Project CLI Commands to Specify a syslog URL

The Oracle Cloud Infrastructure Logging service is the default and recommended option for accessing, searching, and storing function logs.

Alternatively, you can send function logs to an external logging destination like Papertrail instead by using the Fn Project CLI to specify a syslog URL. Note that to use an external logging destination, you must have set up a VCN with public subnets and an internet gateway (see Create the VCN and Subnets to Use with Oracle Functions, if they don't exist already).

To send function logs to an external logging destination by setting the syslog URL:

  1. Log in to your development environment as a functions developer.
  2. To create a new application and specify that all functions in the application send their logs to an external logging destination, enter:

    $ fn create app <app-name> --syslog-url <logging-service-url> --annotation oracle.com/oci/subnetIds='["<subnet-ocid>"]'

    where:

    • <app-name> is the name of the new application. Avoid entering confidential information.
    • <logging-service-url> is the syslog URL to which to send logs.
    • <subnet-ocid> is the OCID of the public subnet (or subnets, up to a maximum of six) in which to run functions. If a regional subnet has been defined, best practice is to select that subnet to make failover across availability domains simpler to implement. If a regional subnet has not been defined and you need to meet high availability requirements, select multiple subnets (enclose each OCID in double quotes separated by commas, in the format '["<subnet-ocid>","<subnet-ocid>"]'. Oracle recommends that the public subnets are in the same region as the Docker registry that's specified in the Fn Project CLI context (see 6. Create an Fn Project CLI Context to Connect to Oracle Cloud Infrastructure).

    For example, fn create app acmeapp --syslog-url tcp://my.papertrail.com:4242 --annotation oracle.com/oci/subnetIds='["ocid1.subnet.oc1.phx.aaaaaaaacnh..."]'

    Note that if you subsequently set up Oracle Cloud Infrastructure Logging to store logs, the existing syslog URL details are retained. So if you later decide to resume sending function logs to the external logging destination, you simply have to disable Oracle Cloud Infrastructure Logging and logs will be sent to the syslog URL again.

  3. To update an existing application and specify that all functions in the application send their logs to an external logging destination, enter:

    $ fn update app <app-name> --syslog-url <logging-service-url> 

    where:

    • <app-name> is the name of the application to update
    • <logging-service-url> is the syslog URL to which to send logs

    For example, fn update app acmeapp --syslog-url tcp://my.papertrail.com:4242

  4. To update an existing application and remove the external logging destination specified for the syslog URL, enter:

    $ fn update app <app-name> --syslog-url '' 

    where:

    • <app-name> is the name of the application to update

    For example, fn update app acmeapp --syslog-url ''

Previously Supported Logging Options

In earlier Oracle Functions releases (prior to the release of the Oracle Cloud Infrastructure Logging service), you could specify where Oracle Functions stores a function's logs by setting up a 'logging policy' for the application containing the function. Previously, you could use the Console to set up a logging policy to:

  • Store logs as objects in a storage bucket in Oracle Cloud Infrastructure Object Storage by selecting the OCI Logging option.

    To view function logs in a storage bucket, the group to which you belong must have been granted access with the following identity policy statements:

  • Store logs by sending them to an external logging destination like Papertrail by selecting the Syslog URL option.

For an existing application where you have previously already set up a logging policy, the above functionality is still supported and the existing logging policy is applied. However, note the following:

  • You cannot use the Console to set up a new logging policy or edit an existing logging policy.
  • If the existing logging policy specified storing function logs as objects in a storage bucket in Oracle Cloud Infrastructure Object Storage:
    • The ability to store logs in Object Storage will be deprecated in a future release.
    • Oracle recommends you switch to storing logs using Oracle Cloud Infrastructure Logging.
    • If you do switch to using Oracle Cloud Infrastructure Logging to store logs, you cannot revert to storing the logs in Object Storage.
    • Logs stored in Object Storage will continue to exist (with each log name including the OCID of the associated function, as before).
  • If the existing logging policy specified a syslog URL:
    • If you switch to using Oracle Cloud Infrastructure Logging to store logs, the existing syslog URL details are retained. So if you later decide to resume sending function logs to the external logging destination, you simply have to disable Oracle Cloud Infrastructure Logging and logs will be sent to the syslog URL again.
    • If you want to change the syslog URL in the existing logging policy, you have to use the Fn Project CLI to change it.