Skip to content

feat(logs): add chronological historical log tailing - #6153

Open
testfax wants to merge 3 commits into
Unitech:developmentfrom
testfax:feat/chronological-logs
Open

feat(logs): add chronological historical log tailing#6153
testfax wants to merge 3 commits into
Unitech:developmentfrom
testfax:feat/chronological-logs

Conversation

@testfax

@testfax testfax commented Sep 8, 2026

Copy link
Copy Markdown
Q A
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? partial - syntax checks and manual functional test pass; full npm test requires bash
Fixed tickets none
License MIT
Doc PR none

Summary

Adds optional chronological merging of historical log output for pm2 logs.

New flags:

  • pm2 logs --chronological
  • pm2 logs --chrono

Current behavior

The initial historical output from pm2 logs is grouped by log file. Each file's last N lines are printed before moving to the next file.

After the historical tail completes, realtime logs are naturally interleaved across processes.

New behavior

With --chronological or --chrono, PM2:

  1. Reads the last N lines from each selected log file.
  2. Parses the stored PM2 timestamp.
  3. Merges entries from all processes.
  4. Sorts them globally by timestamp.
  5. Prints the merged historical output.
  6. Continues with the existing realtime log stream.

Normal pm2 logs behavior is unchanged.

Timestamp requirements

Chronological mode requires timestamped application logs.

If an application historical log entry has no parseable timestamp, PM2 returns an error instead of inferring order from file modification times.

Non-timestamped PM2 daemon diagnostic lines are skipped.

Validation performed

  • node --check lib/API/Log.js
  • node --check lib/API/LogManagement.js
  • node --check lib/binaries/CLI.js
  • git diff --check
  • Manual test with multiple timestamped PM2 processes using:
    • pm2 logs --chrono
    • pm2 logs --chronological

Full npm test was not run successfully on Windows because the project's test command requires bash.

Example

pm2 logs --chrono
pm2 logs --chronological --lines 50

@CLAassistant

CLAassistant commented Sep 8, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants