カラーのロゴ情報

1716 ワード

#include 
#include 
#include 

/*
 *      linux log     
 *
 */



# define PRT_OBJECT(x) ((struct prt_object *)(x))

/** Message types */
enum msg_item_type
{
    MSG_INFO=0, /**< Important information */
    MSG_ERR,    /**< Error */
    MSG_WARN,   /**< Warning */
    MSG_DBG,    /**< Debug */
};


#define COL(x,y)  "\033[" #x ";" #y "m"
#define RED     COL(31,1)
#define GREEN   COL(32,1)
#define YELLOW  COL(0,33)
#define WHITE   COL(0,1)
#define GRAY    "\033[0m"

static const char msg_type[4][9] = { " info", " error", " warning", " debug" };
static const char msg_color[4][8] = { WHITE, RED, YELLOW, GRAY };


/*               ,    ,           ,
 *                        .
 */
void prt_log(int type,const char *module, const char *format, ...)
{
    va_list args;
    char tmp[200];

    va_start(args, format);
    vsprintf(tmp, format, args);
    va_end(args);


    fprintf(stderr, "%s %s: %s %s", module, msg_type[type],msg_color[type],tmp);
    fputs(GRAY"
", stderr); } #define MODULE_STRING "log.c" #define msg_dbg(...) \ prt_log(MSG_DBG, MODULE_STRING, __VA_ARGS__) #define msg_warn(...) \ prt_log(MSG_WARN, MODULE_STRING, __VA_ARGS__) #define msg_err(...) \ prt_log(MSG_ERR, MODULE_STRING, __VA_ARGS__) #define msg_info(...) \ prt_log(MSG_INFO, MODULE_STRING, __VA_ARGS__) int main(void) { msg_err("hal read err!"); msg_info("hal read"); msg_dbg("hal reading......"); msg_warn("hal have not read"); return 0; }

次のような効果が得られます.