16.2 Logging Search, the Logging Query Language & OCI Audit
Key Takeaways
A Logging query starts with
searchand one or more log streams scoped to a compartment, log group, or log, such assearch "compartmentOcid/logGroup/log".In the Logging Query Language,
logContentis a special column for full-text search over the whole log entry, and it supports wildcards such as'*ERROR*'.The
summarizeoperator aggregates log entries by fields and time buckets, for examplesummarize count() by rounddown(datetime, '5m').OCI Audit records calls to public OCI API endpoints made through the Console, CLI, SDKs, custom clients, and other OCI services.
Audit logs are retained for 365 days, a tenancy-level retention period that cannot be changed.
Logging Search
The Search page in OCI Logging lets you query many logs at once: several logs, several log groups, or a whole compartment, including the _Audit log group. Results can be filtered, aggregated, and visualized. Searches are available in the Console, the Logging Search API, and the CLI.
- Basic mode builds filters with form fields and a time range.
- Advanced mode lets you write the Logging Query Language directly.
- Saved searches store useful queries for reuse by the team.
Field names are case-sensitive and use JSON dot notation, such as data.statusCode. Names with special characters are quoted, such as "opc-request-id".
The Logging Query Language
A query is a pipeline. It starts with a log stream and passes the entries through operators separated by |.
Log Streams
search "compartmentOcid/logGroupNameOrOcid/logNameOrOcid"
search "compartmentOcid/logGroupNameOrOcid"
search "compartmentOcid"
search "compartmentOcid/appLogs/apiLog", "compartmentOcid_2/lbLogs"
The scope can be one log, one log group, or a whole compartment, and several streams can be combined in one query.
Filtering With where
search "compartmentOcid/appLogs"
| where data.statusCode = 500 and data.path = '/checkout'
- Comparison operators:
=,!=,>,>=,<,<=; Boolean operators:and,or, andnot(...). - Functions such as
contains_ci(...)(case-insensitive) andcontains_cs(...)(case-sensitive) check for substrings. - Full-text search uses the special column
logContent, which represents the whole original message.where logContent = 'ERROR'matches a value exactly, andwhere logContent = '*ERROR*'matches entries that contain ERROR anywhere.
Shaping Results
| Operator | Purpose | Example |
|---|---|---|
select | Choose and rename fields | select data.clientIp as ip, data.statusCode |
extend | Add a computed column | extend concat(host, '.example.com') as fqn |
sort by | Order results, ascending by default | sort by datetime desc |
top N by | Keep the top N rows | top 10 by data.latencyMs |
dedup | Remove duplicates by fields | dedup data.clientIp |
count | Count rows | count |
summarize | Aggregate by fields and time buckets | summarize count() as errors by rounddown(datetime, '5m') |
Aggregate functions include count(), sum(), avg(), min(), max(), first(), and last(). The rounddown(datetime, '1m') function buckets timestamps into intervals in days, hours, minutes, or seconds, which is how you build an "errors per 5 minutes" chart.
Worked Example: Finding a Spike of Errors
search "compartmentOcid/prodLogs/apiGatewayAccess"
| where data.statusCode >= 500
| summarize count() as errors by data.path, rounddown(datetime, '5m') as bucket
| sort by errors desc
This shows which API paths produced server errors in each five-minute bucket, sorted by count. The same search and where logic is what a Connector Hub log filter task uses to choose which entries to move (Section 16.3).
OCI Audit
The Audit service automatically records calls to all public OCI API endpoints, whether they come from the Console, CLI, SDKs, your own clients, or other OCI services. All services support Audit logging, and it needs no setup.
What an Audit Event Contains
Audit events use the CloudEvents 0.1 envelope. Important attributes include:
| Attribute | Meaning |
|---|---|
eventType and eventTime | What happened and when |
data.identity | Who made the call, such as principalName, the IP address, and the authentication type |
data.request | Request details, such as the action (GET, POST, DELETE) and path |
data.response | The response, including the HTTP status |
data.resourceId and data.compartmentId | The affected resource and its compartment |
Since October 8, 2019, Audit uses the version 2 schema, which is what the Console displays.
The Object Storage Limitation
For Object Storage, Audit records bucket-related events, such as creating a bucket or changing its visibility, but not object-related events such as reading or writing objects. Use the Object Storage read and write service logs for object access (Section 16.1).
Viewing and Searching
Audit logs are organized by compartment, so you need to know the compartment where an event happened. You can browse them on the Audit page or search them with other logs through the _Audit log group on the Logging Search page:
search "compartmentOcid/_Audit"
| where data.request.action = 'DELETE'
| sort by datetime desc
IAM and Retention
- Grant auditors read access with a policy such as
allow group Auditors to read audit-events in tenancy, or limit it to one compartment. - Audit logs are retained for 365 days. Retention is a tenancy-level setting that applies to all regions and compartments, and it cannot be changed.
- For longer retention or analysis in other tools, use Connector Hub with Logging as the source and Object Storage, Streaming, or Logging Analytics as the target.
Common Investigation Patterns
| Question | Where to look |
|---|---|
| Who deleted the production load balancer? | Audit: DELETE on the load balancer, with data.identity.principalName |
| Who downloaded a file from a bucket? | Object Storage read service log |
| Why are users getting 502 errors? | Load Balancer access and error logs, then backend custom logs |
| Was traffic to the database subnet rejected? | VCN flow logs for rejected records |
| Which API paths had the most errors in the last hour? | API Gateway access logs with summarize |
An engineer wants the number of HTTP 5xx responses per API path in five-minute buckets from API Gateway access logs. Starting from search "compartmentOcid/prodLogs/apigw", which pipeline completes the query?
| where data.statusCode >= 500 | dedup data.path, datetime
| where logContent = '*5*' | summarize count() by data.path
| where data.statusCode >= 500 | summarize count() by data.path, rounddown(datetime, '5m')
| where data.statusCode >= 500 | sort by data.path | top 300 by rounddown(datetime, '5m')
A compliance team asks to keep OCI Audit events for three years. What should the architect do?
Change the tenancy's Audit retention setting from 365 days to three years
Copy audit events to Object Storage with Connector Hub, as Audit retention is fixed
Copy the _Audit log group into a custom log and set its retention to three years
Enable Object Storage write logs on every bucket, which also capture all audit events
A security analyst sees that a production bucket was made public. Where can the analyst find who changed the bucket's visibility?
In the bucket's read access service log in OCI Logging
In VCN flow logs for the Object Storage service gateway
Only in Cloud Guard, because Audit does not record Object Storage calls
In OCI Audit, which records bucket updates with the caller's identity
Sections you finish are checked off in the contents.