# Stackdriver Logging API . entries

## Instance Methods

Lists log entries. Use this method to retrieve log entries from Stackdriver Logging. For ways to export log entries, see Exporting Logs.

Writes log entries to Stackdriver Logging. All log entries are written by this method.

### Method Details

`list(body, x__xgafv=None)`

    Lists log entries. Use this method to retrieve log entries from Stackdriver Logging. For ways to export log entries, see Exporting Logs.

    Args:
      body: object, The request body. (required)
        The object takes the form of:

    { # The parameters to ListLogEntries.
        "orderBy": "A String", # Optional. How the results should be sorted. Presently, the only permitted values are "timestamp asc" (default) and "timestamp desc". The first option returns entries in order of increasing values of LogEntry.timestamp (oldest first), and the second option returns entries in order of decreasing timestamps (newest first). Entries with equal timestamps are returned in order of LogEntry.insertId.
        "resourceNames": [ # Required. Names of one or more resources from which to retrieve log entries:
            # "projects/[PROJECT_ID]"
            # "organizations/[ORGANIZATION_ID]"
            # Projects listed in the project_ids field are added to this list.
          "A String",
        ],
        "pageSize": 42, # Optional. The maximum number of results to return from this request. Non-positive values are ignored. The presence of nextPageToken in the response indicates that more results might be available.
        "filter": "A String", # Optional. A filter that chooses which log entries to return. See Advanced Logs Filters. Only log entries that match the filter are returned. An empty filter matches all log entries in the resources listed in resource_names. Referencing a parent resource that is not listed in resource_names will cause the filter to return no results. The maximum length of the filter is 20000 characters.
        "pageToken": "A String", # Optional. If present, then retrieve the next batch of results from the preceding call to this method. pageToken must be the value of nextPageToken from the previous response. The values of other method parameters should be identical to those in the previous call.
        "projectIds": [ # Deprecated. Use resource_names instead. One or more project identifiers or project numbers from which to retrieve log entries. Example: "my-project-1A". If present, these project identifiers are converted to resource name format and added to the list of resources in resource_names.
          "A String",
        ],
      }

      x__xgafv: string, V1 error format.
        Allowed values
          1 - v1 error format
          2 - v2 error format

    Returns:
      An object of the form:

        { # Result returned from ListLogEntries.
        "nextPageToken": "A String", # If there might be more results than those appearing in this response, then nextPageToken is included. To get the next set of results, call this method again using the value of nextPageToken as pageToken.If a value for next_page_token appears and the entries field is empty, it means that the search found no log entries so far but it did not have time to search all the possible log entries. Retry the method with this value for page_token to continue the search. Alternatively, consider speeding up the search by changing your filter to specify a single log name or resource type, or to narrow the time range of the search.
        "entries": [ # A list of log entries.
          { # An individual entry in a log.
            "httpRequest": { # A common proto for logging HTTP requests. Only contains semantics defined by the HTTP specification. Product-specific logging information MUST be defined in a separate message. # Optional. Information about the HTTP request associated with this log entry, if applicable.
              "status": 42, # The response code indicating the status of response. Examples: 200, 404.
              "cacheValidatedWithOriginServer": True or False, # Whether or not the response was validated with the origin server before being served from cache. This field is only meaningful if cache_hit is True.
              "requestMethod": "A String", # The request method. Examples: "GET", "HEAD", "PUT", "POST".
              "latency": "A String", # The request processing latency on the server, from the time the request was received until the response was sent.
              "cacheFillBytes": "A String", # The number of HTTP response bytes inserted into cache. Set only when a cache fill was attempted.
              "requestUrl": "A String", # The scheme (http, https), the host name, the path and the query portion of the URL that was requested. Example: "http://example.com/some/info?color=red".
              "serverIp": "A String", # The IP address (IPv4 or IPv6) of the origin server that the request was sent to.
              "cacheLookup": True or False, # Whether or not a cache lookup was attempted.
              "cacheHit": True or False, # Whether or not an entity was served from cache (with or without validation).
              "referer": "A String", # The referer URL of the request, as defined in HTTP/1.1 Header Field Definitions (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).
              "remoteIp": "A String", # The IP address (IPv4 or IPv6) of the client that issued the HTTP request. Examples: "192.168.1.1", "FE80::0202:B3FF:FE1E:8329".
              "userAgent": "A String", # The user agent sent by the client. Example: "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)".
              "requestSize": "A String", # The size of the HTTP request message in bytes, including the request headers and the request body.
              "responseSize": "A String", # The size of the HTTP response message sent back to the client, in bytes, including the response headers and the response body.
            },
            "resource": { # An object representing a resource that can be used for monitoring, logging, billing, or other purposes. Examples include virtual machine instances, databases, and storage devices such as disks. The type field identifies a MonitoredResourceDescriptor object that describes the resource's schema. Information in the labels field identifies the actual resource and its attributes according to the schema. For example, a particular Compute Engine VM instance could be represented by the following object, because the MonitoredResourceDescriptor for "gce_instance" has labels "instance_id" and "zone": # Required. The monitored resource associated with this log entry. Example: a log entry that reports a database error would be associated with the monitored resource designating the particular database that reported the error.
                # { "type": "gce_instance",
                #   "labels": { "instance_id": "12345678901234",
                #               "zone": "us-central1-a" }}
              "labels": { # Required. Values for all of the labels listed in the associated monitored resource descriptor. For example, Cloud SQL databases use the labels "database_id" and "zone".
                "a_key": "A String",
              },
              "type": "A String", # Required. The monitored resource type. This field must match the type field of a MonitoredResourceDescriptor object. For example, the type of a Cloud SQL database is "cloudsql_database".
            },
            "textPayload": "A String", # The log entry payload, represented as a Unicode string (UTF-8).
            "trace": "A String", # Optional. Resource name of the trace associated with the log entry, if any. If it contains a relative resource name, the name is assumed to be relative to //tracing.googleapis.com. Example: projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824
            "timestamp": "A String", # Optional. The time the event described by the log entry occurred. If omitted, Stackdriver Logging will use the time the log entry is received.
            "labels": { # Optional. A set of user-defined (key, value) data that provides additional information about the log entry.
              "a_key": "A String",
            },
            "insertId": "A String", # Optional. A unique ID for the log entry. If you provide this field, the logging service considers other log entries in the same project with the same ID as duplicates which can be removed. If omitted, Stackdriver Logging will generate a unique ID for this log entry.
            "jsonPayload": { # The log entry payload, represented as a structure that is expressed as a JSON object.
              "a_key": "", # Properties of the object.
            },
            "logName": "A String", # Required. The resource name of the log to which this log entry belongs:
                # "projects/[PROJECT_ID]/logs/[LOG_ID]"
                # "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]"
                # [LOG_ID] must be URL-encoded within log_name. Example: "organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity". [LOG_ID] must be less than 512 characters long and can only include the following characters: upper and lower case alphanumeric characters, forward-slash, underscore, hyphen, and period.For backward compatibility, if log_name begins with a forward-slash, such as /projects/..., then the log entry is ingested as usual but the forward-slash is removed. Listing the log entry will not show the leading slash and filtering for a log name with a leading slash will never return any results.
            "protoPayload": { # The log entry payload, represented as a protocol buffer. Some Google Cloud Platform services use this field for their log entry payloads.
              "a_key": "", # Properties of the object. Contains field @type with type URL.
            },
            "operation": { # Additional information about a potentially long-running operation with which a log entry is associated. # Optional. Information about an operation associated with the log entry, if applicable.
              "last": True or False, # Optional. Set this to True if this is the last log entry in the operation.
              "id": "A String", # Optional. An arbitrary operation identifier. Log entries with the same identifier are assumed to be part of the same operation.
              "producer": "A String", # Optional. An arbitrary producer identifier. The combination of id and producer must be globally unique. Examples for producer: "MyDivision.MyBigCompany.com", "github.com/MyProject/MyApplication".
              "first": True or False, # Optional. Set this to True if this is the first log entry in the operation.
            },
            "sourceLocation": { # Additional information about the source code location that produced the log entry. # Optional. Source code location information associated with the log entry, if any.
              "function": "A String", # Optional. Human-readable name of the function or method being invoked, with optional context such as the class or package name. This information may be used in contexts such as the logs viewer, where a file and line number are less meaningful. The format can vary by language. For example: qual.if.ied.Class.method (Java), dir/package.func (Go), function (Python).
              "line": "A String", # Optional. Line within the source file. 1-based; 0 indicates no line number available.
              "file": "A String", # Optional. Source file name. Depending on the runtime environment, this might be a simple name or a fully-qualified name.
            },
            "severity": "A String", # Optional. The severity of the log entry. The default value is LogSeverity.DEFAULT.
          },
        ],
      }

`write(body, x__xgafv=None)`

    Writes log entries to Stackdriver Logging. All log entries are written by this method.

    Args:
      body: object, The request body. (required)
        The object takes the form of:

    { # The parameters to WriteLogEntries.
        "resource": { # An object representing a resource that can be used for monitoring, logging, billing, or other purposes. Examples include virtual machine instances, databases, and storage devices such as disks. The type field identifies a MonitoredResourceDescriptor object that describes the resource's schema. Information in the labels field identifies the actual resource and its attributes according to the schema. For example, a particular Compute Engine VM instance could be represented by the following object, because the MonitoredResourceDescriptor for "gce_instance" has labels "instance_id" and "zone": # Optional. A default monitored resource object that is assigned to all log entries in entries that do not specify a value for resource. Example:
            # { "type": "gce_instance",
            #   "labels": {
            #     "zone": "us-central1-a", "instance_id": "00000000000000000000" }}
            # See LogEntry.
            # { "type": "gce_instance",
            #   "labels": { "instance_id": "12345678901234",
            #               "zone": "us-central1-a" }}
          "labels": { # Required. Values for all of the labels listed in the associated monitored resource descriptor. For example, Cloud SQL databases use the labels "database_id" and "zone".
            "a_key": "A String",
          },
          "type": "A String", # Required. The monitored resource type. This field must match the type field of a MonitoredResourceDescriptor object. For example, the type of a Cloud SQL database is "cloudsql_database".
        },
        "partialSuccess": True or False, # Optional. Whether valid entries should be written even if some other entries fail due to INVALID_ARGUMENT or PERMISSION_DENIED errors. If any entry is not written, the response status will be the error associated with one of the failed entries and include error details in the form of WriteLogEntriesPartialErrors.
        "labels": { # Optional. Default labels that are added to the labels field of all log entries in entries. If a log entry already has a label with the same key as a label in this parameter, then the log entry's label is not changed. See LogEntry.
          "a_key": "A String",
        },
        "logName": "A String", # Optional. A default log resource name that is assigned to all log entries in entries that do not specify a value for log_name:
            # "projects/[PROJECT_ID]/logs/[LOG_ID]"
            # "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]"
            # [LOG_ID] must be URL-encoded. For example, "projects/my-project-id/logs/syslog" or "organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity". For more information about log names, see LogEntry.
        "entries": [ # Required. The log entries to write. Values supplied for the fields log_name, resource, and labels in this entries.write request are added to those log entries that do not provide their own values for the fields.To improve throughput and to avoid exceeding the quota limit for calls to entries.write, you should write multiple log entries at once rather than calling this method for each individual log entry.
          { # An individual entry in a log.
            "httpRequest": { # A common proto for logging HTTP requests. Only contains semantics defined by the HTTP specification. Product-specific logging information MUST be defined in a separate message. # Optional. Information about the HTTP request associated with this log entry, if applicable.
              "status": 42, # The response code indicating the status of response. Examples: 200, 404.
              "cacheValidatedWithOriginServer": True or False, # Whether or not the response was validated with the origin server before being served from cache. This field is only meaningful if cache_hit is True.
              "requestMethod": "A String", # The request method. Examples: "GET", "HEAD", "PUT", "POST".
              "latency": "A String", # The request processing latency on the server, from the time the request was received until the response was sent.
              "cacheFillBytes": "A String", # The number of HTTP response bytes inserted into cache. Set only when a cache fill was attempted.
              "requestUrl": "A String", # The scheme (http, https), the host name, the path and the query portion of the URL that was requested. Example: "http://example.com/some/info?color=red".
              "serverIp": "A String", # The IP address (IPv4 or IPv6) of the origin server that the request was sent to.
              "cacheLookup": True or False, # Whether or not a cache lookup was attempted.
              "cacheHit": True or False, # Whether or not an entity was served from cache (with or without validation).
              "referer": "A String", # The referer URL of the request, as defined in HTTP/1.1 Header Field Definitions (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).
              "remoteIp": "A String", # The IP address (IPv4 or IPv6) of the client that issued the HTTP request. Examples: "192.168.1.1", "FE80::0202:B3FF:FE1E:8329".
              "userAgent": "A String", # The user agent sent by the client. Example: "Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Q312461; .NET CLR 1.0.3705)".
              "requestSize": "A String", # The size of the HTTP request message in bytes, including the request headers and the request body.
              "responseSize": "A String", # The size of the HTTP response message sent back to the client, in bytes, including the response headers and the response body.
            },
            "resource": { # An object representing a resource that can be used for monitoring, logging, billing, or other purposes. Examples include virtual machine instances, databases, and storage devices such as disks. The type field identifies a MonitoredResourceDescriptor object that describes the resource's schema. Information in the labels field identifies the actual resource and its attributes according to the schema. For example, a particular Compute Engine VM instance could be represented by the following object, because the MonitoredResourceDescriptor for "gce_instance" has labels "instance_id" and "zone": # Required. The monitored resource associated with this log entry. Example: a log entry that reports a database error would be associated with the monitored resource designating the particular database that reported the error.
                # { "type": "gce_instance",
                #   "labels": { "instance_id": "12345678901234",
                #               "zone": "us-central1-a" }}
              "labels": { # Required. Values for all of the labels listed in the associated monitored resource descriptor. For example, Cloud SQL databases use the labels "database_id" and "zone".
                "a_key": "A String",
              },
              "type": "A String", # Required. The monitored resource type. This field must match the type field of a MonitoredResourceDescriptor object. For example, the type of a Cloud SQL database is "cloudsql_database".
            },
            "textPayload": "A String", # The log entry payload, represented as a Unicode string (UTF-8).
            "trace": "A String", # Optional. Resource name of the trace associated with the log entry, if any. If it contains a relative resource name, the name is assumed to be relative to //tracing.googleapis.com. Example: projects/my-projectid/traces/06796866738c859f2f19b7cfb3214824
            "timestamp": "A String", # Optional. The time the event described by the log entry occurred. If omitted, Stackdriver Logging will use the time the log entry is received.
            "labels": { # Optional. A set of user-defined (key, value) data that provides additional information about the log entry.
              "a_key": "A String",
            },
            "insertId": "A String", # Optional. A unique ID for the log entry. If you provide this field, the logging service considers other log entries in the same project with the same ID as duplicates which can be removed. If omitted, Stackdriver Logging will generate a unique ID for this log entry.
            "jsonPayload": { # The log entry payload, represented as a structure that is expressed as a JSON object.
              "a_key": "", # Properties of the object.
            },
            "logName": "A String", # Required. The resource name of the log to which this log entry belongs:
                # "projects/[PROJECT_ID]/logs/[LOG_ID]"
                # "organizations/[ORGANIZATION_ID]/logs/[LOG_ID]"
                # [LOG_ID] must be URL-encoded within log_name. Example: "organizations/1234567890/logs/cloudresourcemanager.googleapis.com%2Factivity". [LOG_ID] must be less than 512 characters long and can only include the following characters: upper and lower case alphanumeric characters, forward-slash, underscore, hyphen, and period.For backward compatibility, if log_name begins with a forward-slash, such as /projects/..., then the log entry is ingested as usual but the forward-slash is removed. Listing the log entry will not show the leading slash and filtering for a log name with a leading slash will never return any results.
            "protoPayload": { # The log entry payload, represented as a protocol buffer. Some Google Cloud Platform services use this field for their log entry payloads.
              "a_key": "", # Properties of the object. Contains field @type with type URL.
            },
            "operation": { # Additional information about a potentially long-running operation with which a log entry is associated. # Optional. Information about an operation associated with the log entry, if applicable.
              "last": True or False, # Optional. Set this to True if this is the last log entry in the operation.
              "id": "A String", # Optional. An arbitrary operation identifier. Log entries with the same identifier are assumed to be part of the same operation.
              "producer": "A String", # Optional. An arbitrary producer identifier. The combination of id and producer must be globally unique. Examples for producer: "MyDivision.MyBigCompany.com", "github.com/MyProject/MyApplication".
              "first": True or False, # Optional. Set this to True if this is the first log entry in the operation.
            },
            "sourceLocation": { # Additional information about the source code location that produced the log entry. # Optional. Source code location information associated with the log entry, if any.
              "function": "A String", # Optional. Human-readable name of the function or method being invoked, with optional context such as the class or package name. This information may be used in contexts such as the logs viewer, where a file and line number are less meaningful. The format can vary by language. For example: qual.if.ied.Class.method (Java), dir/package.func (Go), function (Python).
              "line": "A String", # Optional. Line within the source file. 1-based; 0 indicates no line number available.
              "file": "A String", # Optional. Source file name. Depending on the runtime environment, this might be a simple name or a fully-qualified name.
            },
            "severity": "A String", # Optional. The severity of the log entry. The default value is LogSeverity.DEFAULT.
          },
        ],
      }

      x__xgafv: string, V1 error format.
        Allowed values
          1 - v1 error format
          2 - v2 error format

    Returns:
      An object of the form:

        { # Result returned from WriteLogEntries. empty
      }