aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-10-20 18:35:32 -0400
committerDrew DeVault <sir@cmpwn.com>2017-10-23 21:17:52 -0400
commit0f7e84c11060d5d4388c60a990fdc4cbb839dc70 (patch)
tree03dcc9850e583a10fb4c8cdfd11b6d7feb7bb2c1
parentcf43670529a7498d0f40c1e4e25e32734234de18 (diff)
downloadsway-0f7e84c11060d5d4388c60a990fdc4cbb839dc70.zip
sway-0f7e84c11060d5d4388c60a990fdc4cbb839dc70.tar.gz
sway-0f7e84c11060d5d4388c60a990fdc4cbb839dc70.tar.bz2
Merge pull request #1419 from 4e554c4c/better_logs
Print log level even if STDERR is not a tty
-rw-r--r--common/log.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/common/log.c b/common/log.c
index af1bdc3..6dc9d74 100644
--- a/common/log.c
+++ b/common/log.c
@@ -22,6 +22,12 @@ static const char *verbosity_colors[] = {
[L_INFO ] = "\x1B[1;34m",
[L_DEBUG ] = "\x1B[1;30m",
};
+static const char verbosity_chars[] = {
+ [L_SILENT] = '\0',
+ [L_ERROR ] = 'E',
+ [L_INFO ] = 'I',
+ [L_DEBUG ] = 'D',
+};
void init_log(log_importance_t verbosity) {
if (verbosity != L_DEBUG) {
@@ -62,6 +68,16 @@ void _sway_vlog(const char *filename, int line, log_importance_t verbosity,
static struct tm *tm_info;
char buffer[26];
+ unsigned int c = verbosity;
+ if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
+ c = sizeof(verbosity_colors) / sizeof(char *) - 1;
+ }
+
+ // First, if not printing color, show the log level
+ if (!(colored && isatty(STDERR_FILENO)) && c != L_SILENT) {
+ fprintf(stderr, "%c: ", verbosity_chars[c]);
+ }
+
// get current time
t = time(NULL);
// convert time to local time (determined by the locale)
@@ -70,11 +86,6 @@ void _sway_vlog(const char *filename, int line, log_importance_t verbosity,
strftime(buffer, sizeof(buffer), "%x %X - ", tm_info);
fprintf(stderr, "%s", buffer);
- unsigned int c = verbosity;
- if (c > sizeof(verbosity_colors) / sizeof(char *) - 1) {
- c = sizeof(verbosity_colors) / sizeof(char *) - 1;
- }
-
if (colored && isatty(STDERR_FILENO)) {
fprintf(stderr, "%s", verbosity_colors[c]);
}
@@ -124,6 +135,8 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) {
if (colored && isatty(STDERR_FILENO)) {
fprintf(stderr, "%s", verbosity_colors[c]);
+ } else if (c != L_SILENT) {
+ fprintf(stderr, "%c: ", verbosity_chars[c]);
}
va_list args;