Skip to content

Add timestamps to management, server and agent .err logs - #12967

Open
dheeraj12347 wants to merge 5 commits into
apache:mainfrom
dheeraj12347:fix-12887-err-timestamps-clean
Open

Add timestamps to management, server and agent .err logs#12967
dheeraj12347 wants to merge 5 commits into
apache:mainfrom
dheeraj12347:fix-12887-err-timestamps-clean

Conversation

@dheeraj12347

@dheeraj12347 dheeraj12347 commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

This change updates console logging and stderr routing so .err files get timestamped entries for:

client/conf/log4j-cloud.xml.in

server/conf/log4j-cloud.xml.in

agent/conf/log4j-cloud.xml.in

usage/conf/log4j-cloud_usage.xml.in

For the management server, API server, and agents, the CONSOLE appender patterns now include %d{DEFAULT} at the beginning (matching the existing rolling file appender patterns), and a CONSOLE_ERR appender has been added that sends ERROR and above to SYSTEM_ERR with the same timestamped pattern. This ensures that the stderr output captured into the .err files by the systemd units includes timestamps and aligns more closely with the corresponding .log files.

For the Usage server, a CONSOLE_ERR appender targeting SYSTEM_ERR has been added using the existing %d{ABSOLUTE}{GMT} timestamp pattern, so usage.err also gets timestamped entries.

Hyper-V’s log4j-cloud.xml.in already uses a timestamped console pattern and is unchanged.
Fixes #12887.

@dheeraj12347

Copy link
Copy Markdown
Contributor Author

This is a replacement for PR #12896 with the same .err timestamp change, but scoped to only the three log4j config files and based on the latest main.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates Log4j2 console appender patterns to include timestamps so systemd-captured console/stderr .err logs are timestamped and aligned with existing rolling file logs (per #12887).

Changes:

  • Prepended %d{DEFAULT} to the CONSOLE appender PatternLayout in client, server, and agent configs.
  • Minor cleanup: removed a few blank/whitespace-only lines in the XML configs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
server/conf/log4j-cloud.xml.in Adds timestamp to console log pattern; minor whitespace cleanup.
client/conf/log4j-cloud.xml.in Adds timestamp to console log pattern; minor whitespace cleanup.
agent/conf/log4j-cloud.xml.in Adds timestamp to console log pattern; removes extra blank lines between logger entries.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 1.75439% with 56 lines in your changes missing coverage. Please review.
✅ Project coverage is 18.01%. Comparing base (e2d18c0) to head (bc9fb41).
⚠️ Report is 331 commits behind head on main.

Files with missing lines Patch % Lines
...main/java/com/cloud/consoleproxy/ConsoleProxy.java 3.12% 31 Missing ⚠️
...m/cloud/consoleproxy/ConsoleProxyNoVNCHandler.java 0.00% 14 Missing ⚠️
...a/com/cloud/consoleproxy/ConsoleProxyGCThread.java 0.00% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##               main   #12967     +/-   ##
===========================================
  Coverage     18.00%   18.01%             
- Complexity    16464    16608    +144     
===========================================
  Files          5977     6029     +52     
  Lines        537726   542189   +4463     
  Branches      66026    66459    +433     
===========================================
+ Hits          96839    97688    +849     
- Misses       429968   433485   +3517     
- Partials      10919    11016     +97     
Flag Coverage Δ
uitests 3.52% <ø> (-0.01%) ⬇️
unittests 19.17% <1.75%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DaanHoogland
DaanHoogland requested a review from Copilot April 8, 2026 14:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 65 to 68
<Console name="CONSOLE" target="SYSTEM_OUT">
<ThresholdFilter level="OFF" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="%-5p [%c{1.}] (%t:%x) %m%ex%n"/>
<PatternLayout pattern="%d{DEFAULT} %-5p [%c{1.}] (%t:%x) %m%ex%n"/>
</Console>

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says the .err logs are fed from console/stderr, but this Console appender targets SYSTEM_OUT. If systemd is capturing stderr into .err, changing the stdout pattern won’t affect .err. Consider switching the console target to SYSTEM_ERR (or update the systemd unit routing) so the timestamped console output actually lands in .err.

Copilot uses AI. Check for mistakes.
Comment thread client/conf/log4j-cloud.xml.in
Comment thread agent/conf/log4j-cloud.xml.in
@DaanHoogland

Copy link
Copy Markdown
Contributor

@dheeraj12347 , can you check co-pilot’s comments and explain why it is not applicable (if so)?

@dheeraj12347

Copy link
Copy Markdown
Contributor Author

Hi @DaanHoogland,

This PR only updates the existing CONSOLE PatternLayout in the client, server, and agent log4j-cloud.xml.in files by prepending %d{DEFAULT}, so the console output captured in the .err files gets the same timestamped format as the rolling log files.

I’m not changing the current console target or the service/unit stream routing here, since I wanted to keep this PR limited to the scope of issue #12887.

I’ve also updated the PR description to remove the earlier “console/stderr” wording, which was confusing.

Thanks for pointing it out :)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 65 to +67
<Console name="CONSOLE" target="SYSTEM_OUT">
<ThresholdFilter level="OFF" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="%-5p [%c{1.}] (%t:%x) %m%ex%n"/>
<PatternLayout pattern="%d{DEFAULT} %-5p [%c{1.}] (%t:%x) %m%ex%n"/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to double check this, @dheeraj12347 . I looked in an env and the .out file already contains the date stamps for each line. The .err file doesn’t .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to double check this, @dheeraj12347 . I looked in an env and the .out file already contains the date stamps for each line. The .err file doesn’t .

You’re right, Daan – .out already had timestamps while .err didn’t. I’ve now added a CONSOLE_ERR appender using SYSTEM_ERR with the same timestamped pattern, so stderr (and thus the .err files) will get timestamps as well.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@blueorangutan

Copy link
Copy Markdown

Packaging result [SF]: ✔️ el8 ✔️ el9 ✔️ el10 ✔️ debian ✔️ suse15. SL-JID 17465

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +79 to +82

<Console name="CONSOLE_ERR" target="SYSTEM_ERR">
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
<PatternLayout pattern="%d{DEFAULT} %-5p [%c{1.}] (%t:%x) %m%ex%n"/>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve now updated usage/conf/log4j-cloud_usage.xml.in to add a CONSOLE_ERR appender targeting SYSTEM_ERR with a timestamped pattern, so usage.err will also get timestamps in line with issue #12887.

@DaanHoogland

Copy link
Copy Markdown
Contributor

@blueorangutan package

@blueorangutan

Copy link
Copy Markdown

@DaanHoogland a [SL] Jenkins job has been kicked to build packages. It will be bundled with no SystemVM templates. I'll keep you posted as I make progress.

@DaanHoogland DaanHoogland left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clgtm

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

Suppressed comments (6)

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java:86

  • sessionTimeoutMillis is stored in an int but represents milliseconds; values above ~2,147,483,647 ms (~24.8 days) will overflow and can become negative, which would break both the WebSocket idle timeout and GC logic. Consider switching this to a long (and parsing with Long.parseLong) and avoid exposing it as a public mutable static (e.g., make it private static with an accessor) to reduce accidental runtime modification.
    /**
     * Session timeout in milliseconds, default 300000 (5 minutes).
     */
    public static int sessionTimeoutMillis = 300000;

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java:180

  • sessionTimeoutMillis is stored in an int but represents milliseconds; values above ~2,147,483,647 ms (~24.8 days) will overflow and can become negative, which would break both the WebSocket idle timeout and GC logic. Consider switching this to a long (and parsing with Long.parseLong) and avoid exposing it as a public mutable static (e.g., make it private static with an accessor) to reduce accidental runtime modification.
        // Read consoleproxy.session.timeout in milliseconds.
        s = conf.getProperty("consoleproxy.session.timeout");
        if (s != null) {
            try {
                int parsedTimeout = Integer.parseInt(s);
                if (parsedTimeout < 1000) {

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxy.java:200

  • Class#newInstance() is deprecated and can mask constructor exceptions. Prefer clz.getDeclaredConstructor().newInstance() so constructor failures are reported correctly and access checks are explicit.
        try {
            Class<?> clz = Class.forName(factoryClzName);
            try {
                ConsoleProxyServerFactory factory = (ConsoleProxyServerFactory) clz.newInstance();
                factory.init(ConsoleProxy.ksBits, ConsoleProxy.ksPassword);
                return factory;

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyGCThread.java:72

  • File#delete() returns a boolean and does not throw under normal circumstances; the try/catch will rarely help and currently ignores delete failures when delete() returns false. Consider checking the boolean return value and logging when deletion fails (and optionally include the file path). Also, the updated log message lost a separating space after [ignored], reducing readability.
        File logDir = new File("./logs");
        File[] files = logDir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (System.currentTimeMillis() - file.lastModified() >= 86400000L) {
                    try {
                        file.delete();
                    } catch (Throwable e) {
                        logger.info("[ignored]failed to delete file: " + e.getLocalizedMessage());
                    }

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyGCThread.java:54

  • The timeout comparison truncates both configured milliseconds (/ 1000) and observed idle time (/ 1000), which can effectively shorten the configured timeout by up to ~999ms and makes the behavior dependent on truncation boundaries. A more accurate approach is to compare using milliseconds (e.g., compute idleMillis and compare directly to sessionTimeoutMillis), or at least use a ceiling conversion when computing seconds from milliseconds to avoid disconnecting/GC’ing earlier than configured.
    private int getMaxSessionIdleSeconds() {
        if (ConsoleProxy.sessionTimeoutMillis <= 0) {
            return DEFAULT_MAX_SESSION_IDLE_SECONDS;
        }

        return Math.max(1, ConsoleProxy.sessionTimeoutMillis / 1000);
    }

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyGCThread.java:103

  • The timeout comparison truncates both configured milliseconds (/ 1000) and observed idle time (/ 1000), which can effectively shorten the configured timeout by up to ~999ms and makes the behavior dependent on truncation boundaries. A more accurate approach is to compare using milliseconds (e.g., compute idleMillis and compare directly to sessionTimeoutMillis), or at least use a ceiling conversion when computing seconds from milliseconds to avoid disconnecting/GC’ing earlier than configured.
                long secondsUnused = (System.currentTimeMillis() - client.getClientLastFrontEndActivityTime()) / 1000;
                if (secondsUnused < getMaxSessionIdleSeconds()) {

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.err logs have no timestamp

7 participants