写了一个简单的程序,但是考虑到有一些信息是需要打印在控制台上的,就像在windows上启动apache tomcat时控制台显示的信息一样。琢磨一会儿之后,对printf进行了封装,支持控制台打印日志,支持输出到文件里。不过控制台都是固定颜色的,不好看。于是在网上找了一下资料,printf还真支持输出不同的颜色,如下:
实例:printf("\033[1;33m Hello World. \033[0m \n");
\033 [1; 33m xxxx
| | | |
开始 背景色 字体色 字符串
一些常见的颜色代码:
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"