Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow disabling logging by setting AUSTIN_NO_LOGGING in the environment #121

Merged
merged 1 commit into from
Jul 5, 2022
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
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Added support for Python 3.11.

Allowed disabling logging by setting the environment variable
AUSTIN_NO_LOGGING.

Improved permission error reporting on MacOS.

Improved MacOS support.
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,15 @@ where the structure of `[frame]` and the number and type of metrics on each line
depend on the mode.


## Environment variables

Some behaviour of Austin can be configured via environment variables.

| Variable | Effect |
| ------------------- | ------ |
| `AUSTIN_NO_LOGGING` | Disables all [log messages](#logging) (since Austin 3.4.0). |


## Normal Mode

In normal mode, the `[frame]` part of each emitted sample has the structure
Expand Down Expand Up @@ -522,6 +531,8 @@ statistics. _Bad_ frames are output together with the other frames. In general,
entries for bad frames will not be visible in a flame graph as all tests show
error rates below 1% on average.

Logging can be disabled using [environment variables](#environment-variables).


## Cheat sheet

Expand Down
10 changes: 10 additions & 0 deletions src/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ FILE * logfile = NULL;
#include "austin.h"
#include "logging.h"

int logging = 1;

void
_log_writer(int prio, const char * fmt, va_list ap) {
if (!logging) return;
#ifdef PL_UNIX
vsyslog(prio, fmt, ap);

Expand All @@ -69,9 +71,16 @@ _log_writer(int prio, const char * fmt, va_list ap) {
#endif
}

static int
has_nonempty_env(const char * s) {
const char * v = getenv(s);
return v != NULL && *v != '\0';
}

void
logger_init(void) {
if (has_nonempty_env("AUSTIN_NO_LOGGING")) logging = 0;
if (!logging) return;
#ifdef PL_UNIX
setlogmask (LOG_UPTO (LOG_DEBUG));
openlog ("austin", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
Expand Down Expand Up @@ -162,6 +171,7 @@ log_t(const char * fmt, ...) {

void
logger_close(void) {
if (!logging) return;
#ifdef PL_UNIX
closelog();

Expand Down
10 changes: 10 additions & 0 deletions test/test_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,13 @@ def test_qualnames(py, austin):

assert has_pattern(result.stdout, "qualnames.py:Foo.run"), compress(result.stdout)
assert has_pattern(result.stdout, "qualnames.py:Bar.run"), compress(result.stdout)


@allpythons()
def test_no_logging(py, monkeypatch):
monkeypatch.setenv("AUSTIN_NO_LOGGING", "1")
result = austin("-i", "1ms", *python(py), target("target34.py"))
assert has_pattern(result.stdout, "target34.py:keep_cpu_busy:3"), compress(
result.stdout
)
assert result.returncode == 0, result.stderr or result.stdout