common: un-hardcode 'stderr' as the logging stream

It's now a global variable that's initialized to stderr
(This is prep work for eventual support of printing applications)
This commit is contained in:
Solomon Peachy 2020-08-11 12:48:38 -04:00
parent c05ae9401a
commit 27181eda63
8 changed files with 21 additions and 17 deletions

View file

@ -893,7 +893,7 @@ top:
}
last_state = state;
fflush(stderr);
fflush(logger);
switch(state) {
case S_IDLE:

View file

@ -29,7 +29,7 @@
#include <signal.h>
#include <strings.h> /* For strncasecmp */
#define BACKEND_VERSION "0.106"
#define BACKEND_VERSION "0.107"
#ifndef URI_PREFIX
#error "Must Define URI_PREFIX"
#endif
@ -60,6 +60,7 @@ int ncopies = 1;
int collate = 0;
int test_mode = 0;
int quiet = 0;
FILE *logger;
const char *corrtable_path = CORRTABLE_PATH;
static int max_xfer_size = URB_XFER_SIZE;
@ -1001,7 +1002,7 @@ for more details.\n\
You should have received a copy of the GNU General Public License\n\
along with this program; if not, see <https://www.gnu.org/licenses/>.\n\n";
fprintf(stderr, "%s", license);
fprintf(logger, "%s", license);
}
void print_help(const char *argv0, const struct dyesub_backend *backend)
@ -1270,6 +1271,8 @@ int main (int argc, char **argv)
const char *backend_str = NULL;
int printer_type;
logger = stderr;
/* Handle environment variables */
if (getenv("BACKEND_QUIET"))
quiet = atoi(getenv("BACKEND_QUIET"));

View file

@ -50,15 +50,15 @@
#endif
#define STR_LEN_MAX 64
#define STATE( ... ) do { if (!quiet) fprintf(stderr, "STATE: " __VA_ARGS__ ); } while(0)
#define ATTR( ... ) do { if (!quiet) fprintf(stderr, "ATTR: " __VA_ARGS__ ); } while(0)
#define PAGE( ... ) do { if (!quiet) fprintf(stderr, "PAGE: " __VA_ARGS__ ); } while(0)
#define DEBUG( ... ) do { if (!quiet) fprintf(stderr, "DEBUG: " __VA_ARGS__ ); } while(0)
#define DEBUG2( ... ) do { if (!quiet) fprintf(stderr, __VA_ARGS__ ); } while(0)
#define INFO( ... ) do { if (!quiet) fprintf(stderr, "INFO: " __VA_ARGS__ ); } while(0)
#define WARNING( ... ) do { fprintf(stderr, "WARNING: " __VA_ARGS__ ); } while(0)
#define ERROR( ... ) do { fprintf(stderr, "ERROR: " __VA_ARGS__ ); sleep(1); } while (0)
#define PPD( ... ) do { fprintf(stderr, "PPD: " __VA_ARGS__ ); sleep(1); } while (0)
#define STATE( ... ) do { if (!quiet) fprintf(logger, "STATE: " __VA_ARGS__ ); } while(0)
#define ATTR( ... ) do { if (!quiet) fprintf(logger, "ATTR: " __VA_ARGS__ ); } while(0)
#define PAGE( ... ) do { if (!quiet) fprintf(logger, "PAGE: " __VA_ARGS__ ); } while(0)
#define DEBUG( ... ) do { if (!quiet) fprintf(logger, "DEBUG: " __VA_ARGS__ ); } while(0)
#define DEBUG2( ... ) do { if (!quiet) fprintf(logger, __VA_ARGS__ ); } while(0)
#define INFO( ... ) do { if (!quiet) fprintf(logger, "INFO: " __VA_ARGS__ ); } while(0)
#define WARNING( ... ) do { fprintf(logger, "WARNING: " __VA_ARGS__ ); } while(0)
#define ERROR( ... ) do { fprintf(logger, "ERROR: " __VA_ARGS__ ); sleep(1); } while (0)
#define PPD( ... ) do { fprintf(logger, "PPD: " __VA_ARGS__ ); sleep(1); } while (0)
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
#define le16_to_cpu(__x) __x
@ -281,6 +281,7 @@ extern int collate;
extern int test_mode;
extern int quiet;
extern const char *corrtable_path;
extern FILE *logger;
enum {
TEST_MODE_NONE = 0,

View file

@ -456,7 +456,7 @@ top:
return CUPS_BACKEND_STOP; // HOLD/CANCEL/FAILED? XXXX parse error!
}
fflush(stderr);
fflush(logger);
switch (state) {
case S_IDLE:

View file

@ -1072,7 +1072,7 @@ top:
last_state = state;
fflush(stderr);
fflush(logger);
switch (state) {
case S_IDLE:

View file

@ -992,7 +992,7 @@ top:
}
last_state = state;
fflush(stderr);
fflush(logger);
switch (state) {
case S_IDLE:

View file

@ -1647,7 +1647,7 @@ top:
}
last_state = state;
fflush(stderr);
fflush(logger);
switch (state) {
case S_IDLE:

View file

@ -1231,7 +1231,7 @@ top:
}
last_state = state;
fflush(stderr);
fflush(logger);
switch (state) {
case S_IDLE: