add set_loglevel_from_env() #2277

This commit is contained in:
nick black 2021-10-17 17:12:52 -04:00
parent acb91339e4
commit 27917d12ec
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
4 changed files with 22 additions and 0 deletions

View File

@ -909,6 +909,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
}else{
loglevel = NCLOGLEVEL_SILENT;
}
set_loglevel_from_env(&loglevel);
int cursor_y = -1;
int cursor_x = -1;
if(interrogate_terminfo(&ret->tcache, ret->ttyfp, utf8, 1,

View File

@ -1746,6 +1746,10 @@ emit_scrolls(const tinfo* ti, int count, fbuf* f){
// replace or populate the TERM environment variable with 'termname'
int putenv_term(const char* termname) __attribute__ ((nonnull (1)));
// check environment for NOTCURSES_LOGLEVEL, and use it if defined.
int set_loglevel_from_env(ncloglevel_e* loglevel)
__attribute__ ((nonnull (1)));
#undef API
#undef ALLOC

View File

@ -1002,6 +1002,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
ret->rstate.f.used = 0;
ret->rstate.f.size = 0;
ret->loglevel = opts->loglevel;
set_loglevel_from_env(&ret->loglevel);
if(!(opts->flags & NCOPTION_INHIBIT_SETLOCALE)){
init_lang();
}

View File

@ -8,6 +8,22 @@
#endif
#include "internal.h"
int set_loglevel_from_env(ncloglevel_e* llptr){
const char* ll = getenv("NOTCURSES_LOGLEVEL");
if(ll == NULL){
return 0;
}
char* endl;
long l = strtol(ll, &endl, 10);
if(l < NCLOGLEVEL_PANIC || l > NCLOGLEVEL_TRACE){
logpanic("Illegal NOTCURSES_LOGLEVEL: %s\n", ll);
return -1;
}
*llptr = l;
loginfo("Got loglevel from environment: %ld\n", l);
return 0;
}
char* notcurses_accountname(void){
#ifndef __MINGW64__
const char* un;