[C programming on Linux] make color log records with printf

Source: Internet
Author: User

Wrote a simple program, but given that there is some information that needs to be printed on the console, just like the information displayed by the console when you launch Apache Tomcat on Windows. After a while, the printf was encapsulated, supporting the console print log and supporting the output to the file. But the console is fixed color, not good-looking. So on the internet to find a bit of information, printf also really support the output of different colors, as follows:

Example: printf ("\033[1;33m Hello World.") \033[0m \ n ");

\033 [1; 33m xxxx

|          |             | |

Start background color Font color string

Some common color codes:

none = "\033[0m"
Black = "\033[0;30m"
Dark_gray = "\033[1;30m"
Blue = "\033[0;34m"
Light_blue = "\033[1;34m"
Green = "\033[0;32m"
Light_green-= "\033[1;32m"
Cyan = "\033[0;36m"
Light_cyan = "\033[1;36m"
Red = "\033[0;31m"
light_red = "\033[1;31m"
Purple = "\033[0;35m"
Light_purple = "\033[1;35m"
Brown = "\033[0;33m"
Yellow = "\033[1;33m"
Light_gray = "\033[0;37m"
White = "\033[1;37m"


[C programming on Linux] make color log records with printf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.