<commit_before>/* $Id$ */

/*
 * Logging routines.
 * Notes:
 *	(o) We cannot use psc_fatal() for fatal errors here.  Instead use err(3).
 */

#include <sys/param.h>
#include <sys/time.h>
#include <sys/syscall.h>

#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "psc_util/alloc.h"
#include "pfl/cdefs.h"
#include "psc_util/fmtstr.h"
#include "psc_util/log.h"

#ifndef APP_STRERROR
#define APP_STRERROR strerror
#else
char *APP_STRERROR(int);
#endif

#ifndef PSC_LOG_FMT
#define PSC_LOG_FMT "[%s:%06u %n:%i:%F:%l] "
#endif

struct fuse_context {
	uid_t uid;
	gid_t gid;
	pid_t pid;
};

const char			*psc_logfmt = PSC_LOG_FMT;
__static int			 psc_loglevel = PLL_TRACE;
__static struct psclog_data	*psc_logdata;
char				 psclog_eol[8] = "\n";

void
psc_log_init(void)
{
	char *ep, *p;
	long l;

	if ((p = getenv("PSC_LOG_FILE")) != NULL)
		freopen(p, "w", stderr);
	if ((p = getenv("PSC_LOG_FORMAT")) != NULL)
		psc_logfmt = p;
	if ((p = getenv("PSC_LOG_LEVEL")) != NULL) {
		ep = NULL;
		errno = 0;
		l = strtol(p, &ep, 10);
		if (p[0] == '\0' || ep == NULL || *ep != '\0')<commit_msg>add subsystem name to default log format<commit_after>/* $Id$ */

/*
 * Logging routines.
 * Notes:
 *	(o) We cannot use psc_fatal() for fatal errors here.  Instead use err(3).
 */

#include <sys/param.h>
#include <sys/time.h>
#include <sys/syscall.h>

#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <pthread.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "psc_util/alloc.h"
#include "pfl/cdefs.h"
#include "psc_util/fmtstr.h"
#include "psc_util/log.h"

#ifndef APP_STRERROR
#define APP_STRERROR strerror
#else
char *APP_STRERROR(int);
#endif

#ifndef PSC_LOG_FMT
#define PSC_LOG_FMT "[%s:%06u %n:%i:%T:%F:%l] "
#endif

struct fuse_context {
	uid_t uid;
	gid_t gid;
	pid_t pid;
};

const char			*psc_logfmt = PSC_LOG_FMT;
__static int			 psc_loglevel = PLL_TRACE;
__static struct psclog_data	*psc_logdata;
char				 psclog_eol[8] = "\n";	/* overrideable with ncurses EOL */

void
psc_log_init(void)
{
	char *ep, *p;
	long l;

	if ((p = getenv("PSC_LOG_FILE")) != NULL)
		freopen(p, "w", stderr);
	if ((p = getenv("PSC_LOG_FORMAT")) != NULL)
		psc_logfmt = p;
	if ((p = getenv("PSC_LOG_LEVEL")) != NULL) {
		ep = NULL;
		errno = 0;
		l = strtol(p, &ep, 10);
		if (p[0] == '\0' || ep == NULL || *ep != '\0')
{'fraction_non_alphanumeric': 0.1819632881085395, 'fraction_numerical': 0.007980845969672785, 'mean_word_length': 4.233820459290188, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7462358', 'n_tokens_mistral': 1169, 'n_tokens_neox': 1109, 'n_words': 265}