Getting started with log management

Build a practical log management workflow: structured logging, collection, access control, live search, alerts, dashboards, retention, and archives.

Best practices
The log lifecycle, from collection and analysis to retention and archiving

When an application fails, the relevant evidence may be scattered across an application log, a database log, a reverse proxy, and a container that no longer exists. Collecting those records in one place helps, but a searchable pile of text is only a starting point. Engineers also need consistent timestamps, useful fields, access controls, and a retention policy that keeps the right evidence available.

Log management is the set of practices and tools that makes this possible. It covers how logs are generated, collected, processed, stored, searched, and eventually archived or deleted. This guide walks through that lifecycle and the decisions involved in building a system that remains useful as the environment grows.

What log management provides

A log records something that happened: a request completed, a connection failed, a user authenticated, or a background job changed state. Good log management makes those events accessible in the context needed to understand them.

A centralized workflow supports several related tasks:

  • Troubleshooting: reconstruct what happened around a failure and test possible explanations.
  • Alerting: detect specific events or unusual event rates while there is still time to respond.
  • System analysis: understand usage, recurring errors, and interactions between services.
  • Preventing recurrence: review the evidence after an incident and improve code, configuration, detection, or operating procedures.

Without that workflow, engineers may have to connect to individual machines, locate the right files, and reconcile timestamps manually. That can work for a small environment. It becomes harder when services run on many hosts, containers disappear, or several people need to investigate at once.

Centralization reduces the retrieval work. Consistent fields and identifiers make the retrieved records easier to interpret. Both are necessary: a central store full of inconsistent or incomplete events still leaves a great deal of work to the person on call.

The log management lifecycle

A typical pipeline collects events, prepares them for use, and sends them to a system that supports analysis and lifecycle management. Access controls apply throughout the path, not just in the search interface.

1. Generate useful events

Start with application instrumentation and the logging settings of the services the application depends on. Use a supported logging library, choose meaningful severity levels, and record enough context to distinguish one operation from another.

Locally, tools such as tail, grep, sed, and jq can help inspect output. Files remain common on hosts; containerized applications often write to standard output and let the runtime capture the stream. Make that output useful before adding more infrastructure around it.

Structured formats such as JSON make fields explicit. A timestamp, severity, service name, environment, request ID, and error details are generally easier to query as separate fields than as parts of a sentence. The precise schema depends on the application, but consistency matters more than clever formatting.

Do not log secrets merely because a downstream tool can redact them. Avoiding collection is the most direct way to keep a password or token out of the entire pipeline.

For a language-specific example, see the Python logging guide (Chinese).

2. Collect and centralize logs

Once applications and dependencies produce useful records, collect them from web servers, cloud services, containers, network devices, and other sources.

Several functions may appear in this path:

  • Collection: a collector such as Fluentd, Filebeat, Vector, or DataKit reads events from supported files, streams, or protocols.
  • Buffering: a bounded queue absorbs temporary differences between incoming and outgoing rates. This may be a collector's local buffer or a separate service such as Kafka, depending on durability and replay requirements.
  • Processing: parsers and transformations extract fields, normalize values, enrich events, filter noise, or redact sensitive data.
  • Central storage and analysis: the processed events reach a self-hosted backend or a managed service where authorized users can query them.

A buffer buys time; it does not make an overloaded destination infinitely reliable. Decide what happens when it fills, whether it survives a restart, and how much throughput is available to drain it after an outage.

Processing location also matters. A rule that runs before transmission can reduce what leaves the source. A rule that runs after storage cannot establish that the original record was never persisted. Guance's Pipeline documentation describes its processing facilities; choose the execution path that matches your requirement.

3. Restrict access and protect the data

Even carefully designed logs can contain information that should not be broadly accessible. Protect them in transit and at rest, limit collection of sensitive values, and restrict access according to role and responsibility.

Redaction, masking, and access control solve different problems. Masking a value in one interface does not necessarily remove it from storage or exports. Encryption does not prevent an authorized but overly privileged user from reading the data. Test the controls in every supported path.

Integrity protection also needs more than an unprotected checksum. A hash can help detect changes only when its trusted reference is protected; an attacker who can replace both the record and its hash defeats a naive check. Audit-sensitive systems may require signed records, protected manifests, immutable storage, or another design appropriate to their threat model.

Record access and administrative changes where the platform supports them. An audit trail should make it possible to investigate who accessed which data and when. Review permissions periodically, especially when people change teams.

Maintain every component in the logging path. Vulnerabilities in a logging library or processor can affect the application and its environment, even if the central storage system is fully patched.

4. Watch a live stream

Live tailing shows new events as they arrive. It is useful during a deployment or while reproducing a problem, particularly when filters can isolate a service, request, or error.

A centralized live view avoids opening separate tail -f sessions on multiple servers. Still, check the tool's sampling, rate limits, and delivery delay. A live display is an observation tool; it should not be treated as proof that every event was durably stored.

5. Search and analyze historical events

Search becomes useful when the query matches a question an engineer is trying to answer. Common starting points include:

  • Find errors or warnings for a particular service.
  • Inspect a bounded time range around the first symptom.
  • Follow a request or user action across several components.
  • Compare failure patterns before and after a deployment.

For example, to inspect errors on a search endpoint, filter by severity and the recorded route, then set the time range to the last 30 minutes. The exact syntax depends on the backend and field names. An illustrative expression such as the following is pseudocode, not Guance DQL:

level = "error" AND request.route = "/search"

Check that those fields are parsed and typed as expected. A query over a field that never reached the index can return no results even though matching text exists in the raw events.

Save frequently used queries so that the team can reuse a known starting point. For a wider investigation, correlate application events with dependency logs and traces. A consistent request or trace identifier is much stronger evidence of a relationship than two events occurring at roughly the same time.

6. Monitor events and trigger useful alerts

Manual search answers a question someone has already asked. Monitoring can detect a condition that deserves attention before anyone starts searching.

Structured fields make alert conditions easier to define and review. Two common patterns are event-based and rate-based detection.

Alert on an event or a missing event

A particular error, security event, or business state change may justify an alert. Absence can also matter. If a scheduled backup should produce a completion event, failure to observe it by the expected deadline can trigger investigation.

Account for collection delay and pipeline health. A missing success event could mean the job failed, the log was lost, or the collector stopped. An alert should provide enough context to distinguish those possibilities.

Alert on a rate or a sustained pattern

A few HTTP 500 responses may be transient. A sustained increase can indicate a service problem. A rate-based rule can detect the pattern without notifying someone for every individual error.

Where possible, consider error rates relative to traffic rather than raw counts alone. Set a meaningful window, define how missing data is handled, and route the alert to a team that can act. Low event rates can also be significant when a normally active process suddenly becomes quiet.

The goal is a useful response, not the largest possible number of alerts. Tune recurring false positives and duplicate notifications before they make important signals easier to ignore.

7. Build dashboards and reports

Dashboards summarize questions that come up repeatedly: which services are failing, which routes produce the most errors, whether a deployment changed behavior, or whether an expected business process completed.

A useful chart has a defined population, time range, and unit. “Errors” may mean a count, a rate, or a percentage; label it accordingly. Keep a path from the aggregate back to the underlying events so that a spike can be investigated.

Reports can help people outside the on-call rotation follow longer-term trends. Select measures that support a decision, such as whether a recurring failure is becoming less frequent, rather than building a dashboard simply because fields are available.

8. Set retention and archive policies

Retention determines how long records remain available in a particular tier. The right duration depends on operational use, internal policy, and applicable obligations. Different event types may warrant different treatment.

For example, an organization might keep routine application logs searchable for 30 days and retain selected authentication audit records for six months. Those durations are illustrative, not a universal compliance rule. Establish the actual requirement with the relevant owners before configuring deletion.

At the end of a tier's retention period, there are two main options:

  • Delete the records. This permanently removes the ability to investigate them, subject to any separately retained copies. Confirm that deletion is allowed and that related backups and exports follow the intended policy.
  • Archive the records. Move or preserve them in a less expensive tier, often object storage. Retrieval may require time, query charges, re-ingestion, or temporary storage. Test that process before an audit or incident makes it urgent.

An archive is not automatically cheaper in every workload. Storage price, request volume, retrieval patterns, and operational work determine the result. Often the sensible design is a short interactive search window plus longer archival retention for a selected subset.

Problems to plan for as the system grows

A working pilot needs more than additional disk space to become a dependable production service. The most common pressures are closely related:

  • Volume: more events increase collection, transmission, processing, storage, and query work. Measure useful volume and noise separately.
  • Operating effort: self-hosted components need upgrades, capacity planning, recovery procedures, and people who can support them.
  • Performance: ingestion and search can contend for resources. Test realistic query concurrency while events are arriving.
  • Inconsistent formats: incompatible field names, timestamps, and types make cross-service investigation harder.
  • Security and privacy: permissions and redaction need to remain effective across sources, destinations, archives, and exports.
  • Alert fatigue: noisy rules and duplicate notifications can obscure the failures that require action.
  • Lifecycle management: retention, deletion, and retrieval must remain predictable as the number of datasets grows.

Monitor the logging system itself. A service that silently stops receiving one application's events can look healthy while hiding an important gap.

Choose a service model the team can support

Self-hosting offers control over architecture, placement, and customization. That may be valuable for unusual processing requirements or a tightly controlled environment. It also assigns responsibility for infrastructure, security updates, availability, and recovery to the organization. A private commercial deployment can be another option; data-location requirements do not always imply building every component from open source.

A managed service can reduce infrastructure and upgrade work and provide integrated search, alerting, and lifecycle features. Evaluate its limits, commercial terms, regions, export paths, and behavior at projected volume. “Managed” changes the division of responsibilities; the team still owns its logging schema, collection decisions, permissions, and alert quality.

Choose by comparing the required workflow with the capabilities and responsibilities of each model. The cheapest ingestion rate may not produce the lowest total cost, and the most feature-rich service may add little value to a narrow requirement.

Guance provides centralized log analysis with search and monitoring capabilities. To evaluate it, start with a representative source, verify the parsed fields and timestamps, and test the queries and alerts your team would actually use. The Guance log documentation provides the next steps.

For a broader comparison, see Choosing an enterprise log platform.

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting