Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6705019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:21:19+00:00 2026-05-26T07:21:19+00:00

I am tracking down some concurrency issues and it would be very helpful to

  • 0

I am tracking down some concurrency issues and it would be very helpful to have the output lines from each thread in a different color when logging to a console. I am on OS X. Could this be done using a conversion pattern to output some control codes or would it need a custom appender? Anyone know how?

2011-10-21 12:14:42,859 ["http-bio-8080"-exec-9] DEBUG ...
2011-10-21 12:14:43,198 ["http-bio-8080"-exec-10] DEBUG ...

The lines for exec-9 and exec-10 should be in different colors.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:21:20+00:00Added an answer on May 26, 2026 at 7:21 am

    You can extend PatternLayout and override format(ILoggingEvent). There you could look at LoggingEvent.getThreadName() to get some color based on the thread name (odd/even, maybe?).

    In order to output color to the console, you’ll need to use an ANSI Escape Sequence.

    For instance, to output a red text:

      "\u001b["  // Prefix - see [1]
    + "0"        // Brightness
    + ";"        // Separator
    + "31"       // Red foreground
    + "m"        // Suffix
    + text       // the text to output
    + "\u001b[m " // Prefix + Suffix to reset color
    

    Here some examples:

    • ColoredPatternLayout implementation by Ingo Thon.
    • Colour-coded Console Logging with Log4J blog post.

    Just to add, maybe you could also achieve this by setting in the MDC a variable “randColor” with a random ANSI color code, for instance, in a Filter, and using it in the conversionPattern of a standard org.apache.log4j.PatternLayout in your log4j’s console appender configuration:

    <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern"
                   value="\u001b[0;%X{randColor}m ....... \u001b[m" />
        </layout>
    </appender>
    

    [1] What does "\u001B[J" represent?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are tracking down some memory issues in our application and we have visibility
Today I was tracking down a floating point exception in some code I had
There is nothing like the 43rd day of your life spent tracking down issues
I'm having a blast tracking down some heap corruption. I've enabled standard page heap
I need some help tracking down a bit of nitty gritty information on the
I'm working on tracking down some difficult to find memory leaks in my iPhone
Possible Duplicate: Tips/Techniques for tracking down leaks in monotouch programs? I have a MonoTouch
I've been tracking down some memory leaks in a Javascript file I've been working
Today I was tracking down why my program was getting some unexpected checksum-mismatch errors,
I spent part of yesterday and today tracking down a bug in some Matlab

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.