Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,14 @@ UMBER_LVL=*=never,fully.qualified.class.name=verbose

These assignments are evaluated left-to-right, so latter ones will take precedence.

## Enabling line buffering

If you need to enable line buffering (e.g. you are reading the output of a program using Umber through a pipe let's say and you need `getline()` to return immediately when a new line is produced), you can use the `UMBER_LINEBUF` environment variable:

```console
UMBER_LINEBUF=true # This can be set to whatever except "", "0", or "false".
```

This will enable line buffering on both `stdout` and `stderr`.

Thank you for attending my TED Talk.
15 changes: 15 additions & 0 deletions src/umber.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ struct umber_class_t {
umber_lvl_t lvl;
};

__attribute__((constructor)) void set_linebuf(void) {
char const* const val = getenv("UMBER_LINEBUF");

if (val == NULL) {
return;
}

if (*val == '\0' || *val == '0' || strcasecmp(val, "false") == 0) {
return;
}

setlinebuf(stdout);
setlinebuf(stderr);
}

umber_class_t const* umber_class_new(
char const* name,
umber_lvl_t const default_lvl,
Expand Down