16.1 OCI Logging: Log Groups, Service Logs, Custom Logs & the Unified Monitoring Agent
Key Takeaways
OCI Logging handles three kinds of logs: audit logs, service logs, and custom logs.
Each log in OCI Logging is a resource with its own OCID, and every log belongs to a log group in a compartment.
Custom logs can be ingested with the Logging Ingestion API (PutLogs) or with the fluentd-based Unified Monitoring Agent.
Instances that send custom logs through the agent need a dynamic group and a policy such as
allow dynamic-group app-fleet to use log-content in compartment apps.Object Storage read and write log categories capture object-level access events that the Audit service does not record.
Why Centralized Logging Matters
When an incident happens, architects need to answer questions like "which client called this API?", "what did the load balancer return?", and "what did the application log just before it failed?". OCI Logging is a fully managed, highly scalable service that gives you a single place to enable, manage, and search the logs from OCI resources, applications, other clouds, and on-premises systems.
The Three Kinds of Logs
| Kind | Source | How you get it |
|---|---|---|
| Audit logs | The Audit service, which records API calls to public OCI endpoints | Always on; read-only; shown on the Audit page and in Search as the _Audit log group (Section 16.2) |
| Service logs | OCI services such as API Gateway, Events, Functions, Load Balancer, Object Storage, and VCN Flow Logs | Enable a log category on each resource |
| Custom logs | Your applications, other clouds, or on-premises systems | Unified Monitoring Agent or the Logging Ingestion API |
Logs and Log Groups
- A log is a first-class OCI resource with an OCID. For example, enabling flow logs on a subnet creates a dedicated log.
- A log group is a logical container for logs in a compartment. You must create one before you enable a log. Use log groups to apply IAM policies and to search related logs together, such as one log group per application or environment.
- Moving a log group to another compartment moves all of its logs with it.
Logs are encrypted in flight during ingestion, encrypted at rest, and encrypted when archived. Only UTF-8 text is supported.
Retention
For service and custom logs, you choose the retention period in 30-day increments up to 180 days. For longer retention, such as compliance archives kept for years, use Connector Hub to copy logs to Object Storage (Section 16.3).
Service Logs and Log Categories
Each service defines its own log categories, which are unrelated to other services' categories:
| Service | Example categories | Typical use |
|---|---|---|
| Object Storage | Read and write access events for a bucket | Who downloaded or uploaded which object |
| Load Balancer | Access and error logs | Request status codes and backend errors |
| API Gateway | Access and execution logs | Per-request API details and policy decisions |
| Functions | Function invocation logs | Application output from functions |
| VCN Flow Logs | Accepted and rejected traffic records | Troubleshooting security list and NSG rules |
| Events | Rule execution logs | Checking event delivery |
To enable a service log on a resource, you need permission on the log group and the update permission on the resource, which for many resources comes with the use verb. For example, users who can use buckets in a compartment can enable logging on those buckets.
Object Storage Logs Versus Audit
The Audit service records bucket-level API calls, such as creating a bucket or changing its visibility, but not object-level operations such as GetObject or PutObject. To answer "who downloaded this file?", enable the bucket's read log category, and its write category for uploads.
Custom Logs
Unified Monitoring Agent
The Unified Monitoring Agent is a fluentd-based agent that runs on OCI instances, delivered as the Oracle Cloud Agent plugin called Custom Logs Monitoring, which must be enabled on the instance. It works on both VM and bare metal instances.
An agent configuration tells the agent what to collect:
- Host groups: the dynamic groups (or groups) of instances that use the configuration.
- Log inputs: Log Directory (Tail) file paths, such as
/var/log/app/*.log, or Windows Event Logs. - Parser: how to turn lines into structured fields, for example none, JSON, regular expression, multiline, syslog, or Apache formats.
- Destination: the custom log that receives the entries.
Any log field longer than 10,000 characters is truncated during ingestion. Agent configuration updates are detected and loaded automatically. The same agent can also collect custom metrics, such as Prometheus endpoints, for Monitoring.
IAM for Agents
The instances must be in a dynamic group, and a policy must let that group get configurations and send logs:
allow dynamic-group app-fleet to use log-content in compartment apps
With use log-content, the instances can download their configuration, push logs, and search logs. Readers who only need to view logs get read log-content, which covers service and custom logs alike.
The Logging Ingestion API
Applications, other clouds, and on-premises systems can send entries directly with the PutLogs operation of the Logging Ingestion API, which uses an ingestion.logging.<region> endpoint. This is useful for containers, serverless code, or systems where installing the agent is not possible.
Logging APIs
- Logging Management API: create and manage logs, log groups, and agent configurations.
- Logging Ingestion API: send custom log entries (PutLogs).
- Logging Search API: search logs programmatically (Section 16.2).
Design Example: A Three-Tier Application
- Create a log group per environment, such as
prod-app-logs. - Enable Load Balancer access and error logs, API Gateway access and execution logs, and VCN flow logs on the application subnets.
- Enable the Custom Logs Monitoring plugin on the application instances, add them to a dynamic group, and create an agent configuration that tails
/var/log/app/*.logwith a JSON parser. - Enable Object Storage write logs on the upload bucket.
- Use Connector Hub to archive everything to Object Storage for one year, and to raise alarms on error patterns.
A security team must find out which user downloaded a confidential file from an Object Storage bucket yesterday. Audit logs show bucket changes but no downloads. What should have been enabled?
A search of the _Audit log group over a longer time range
The read access log category on the bucket in OCI Logging
A Cloud Guard detector recipe for the bucket
VCN flow logs on the subnet of the client
The Unified Monitoring Agent is installed on application instances and an agent configuration exists, but no custom log entries arrive. The instances are in a dynamic group. Which policy is most likely missing?
allow dynamic-group app-fleet to read log-groups in compartment apps
allow dynamic-group app-fleet to manage instances in compartment apps
allow group app-admins to read log-content in compartment apps
allow dynamic-group app-fleet to use log-content in compartment apps
A regulation requires keeping application logs for seven years. Logs are currently kept in OCI Logging. What should the architect do?
Use Connector Hub to archive the logs to Object Storage
Set the custom log's retention period to seven years
Store the logs in the _Audit log group, which keeps data for longer
Increase the retention period on the log group that contains the application logs
Sections you finish are checked off in the contents.