Created
April 10, 2014 07:48
-
-
Save evanpurkhiser/10353053 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/common/msg.c b/common/msg.c | |
index a8ff492..dc62a3d 100644 | |
--- a/common/msg.c | |
+++ b/common/msg.c | |
@@ -20,6 +20,7 @@ | |
#include <stdlib.h> | |
#include <stdarg.h> | |
#include <string.h> | |
+#include <ctype.h> | |
#include <unistd.h> | |
#include <assert.h> | |
#include <pthread.h> | |
@@ -204,6 +205,32 @@ static void set_msg_color(FILE* stream, int lev) | |
terminal_set_foreground_color(stream, v_colors[lev]); | |
} | |
+static void pretty_print_module(FILE* stream, struct mp_log *log) | |
+{ | |
+ char *prefix = log->verbose_prefix; | |
+ | |
+ // Use random color based on the name of the module | |
+ unsigned int mod = 0; | |
+ for (int i = 0; i < strlen(prefix); ++i) | |
+ mod = 31 * mod + (int) prefix[i]; | |
+ int c2 = (mod + 1) % 15 + 1; | |
+ | |
+ // Convert the prefix to uppercase | |
+ char upper_prefix[strlen(prefix) + 1]; | |
+ for (int i = 0; i < strlen(prefix); ++i) | |
+ upper_prefix[i] = toupper(prefix[i]); | |
+ | |
+ terminal_set_foreground_color(stream, c2); | |
+ fprintf(stream, "%10s", upper_prefix); | |
+ terminal_set_foreground_color(stream, -1); | |
+ fprintf(stream, ": "); | |
+ | |
+ if (log->root->color) | |
+ set_msg_color(stream, log->terminal_level); | |
+ else | |
+ terminal_set_foreground_color(stream, -1); | |
+} | |
+ | |
static void print_msg_on_terminal(struct mp_log *log, int lev, char *text) | |
{ | |
struct mp_log_root *root = log->root; | |
@@ -246,8 +273,13 @@ static void print_msg_on_terminal(struct mp_log *log, int lev, char *text) | |
if (header) { | |
if (root->show_time) | |
fprintf(stream, "[%" PRId64 "] ", mp_time_us()); | |
- if (prefix) | |
- fprintf(stream, "[%s] ", prefix); | |
+ | |
+ if (prefix) { | |
+ if (root->module) | |
+ pretty_print_module(stream, log); | |
+ else if (root->verbose) | |
+ fprintf(stream, "[%s] ", prefix); | |
+ } | |
} | |
char *next = strchr(text, '\n'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment