Esempio n. 1
0
/******************************************************************************
 * @brief    Set global log destination
 *****************************************************************************/
void
setup_logging(int    id,
              char   log_path[],
              FILE **logfile)
{
    //170630LML extern FILE *LOG_DEST;
    char         logfilename[MAXSTRING];

    if (strcmp(log_path, "MISSING") != 0) {
        // Create logfile name
        get_logname(log_path, id, logfilename);

        // Open Logfile
        *logfile = open_file(logfilename, "w");

        // Print log file name to stderr
        log_info("Initialized Log File: %s", logfilename);

        // Set Log Destination
        LOG_DEST = *logfile;

        // Write first line of log file
        log_info("Initialized Log File: %s", logfilename);
    }
    else {
        log_info("Logging to stderr");
    }
}
Esempio n. 2
0
void alog(const char *fmt, ...)
{
	if (!smtp_debug || !fmt)
		return;

	std::fstream file;
	file.open(get_logname().c_str(), std::ios_base::out | std::ios_base::app);

	if (!file.is_open())
		return;

	va_list args;
	va_start(args, fmt);

	time_t t = time(NULL);
	struct tm *tm = localtime(&t);

	char buf[256];
	strftime(buf, sizeof(buf) - 1, "[%b %d %H:%M:%S %Y] ", tm);
	file << buf;
	vsnprintf(buf, sizeof(buf), fmt, args);
	file << buf << std::endl;
	va_end(args);
	va_end(args);

	file.close();
}
Esempio n. 3
0
int open_log(void)
{
    char name[PATH_MAX];

    if (logfile)
        return 0;

    /* if removed again.. get_logname is always 1 */
    get_logname(name, sizeof(name), NULL);
    logfile = fopen(name, "a");

    if (logfile)
        setbuf(logfile, NULL);
    return logfile != NULL ? 0 : -1;
}
Esempio n. 4
0
int open_log(void)
{
    char name[PATH_MAX];
    if (logfile)
        return 0;

    if (!get_logname(name, sizeof(name), NULL))
        return 0;

    logfile = FileOpen(name, FILE_APPEND);

    if (logfile)
        setvbuf(logfile, NULL, _IONBF, BUFSIZE);

    return logfile != NULL ? 0 : -1;
}
Esempio n. 5
0
static void remove_log(void)
{
    time_t t;
    struct tm tm;

    char name[PATH_MAX];

    if (!KeepLogs)
        return;

    time(&t);
    t -= (60 * 60 * 24 * KeepLogs);
    tm = *localtime(&t);
    if (!get_logname(name, sizeof(name), &tm))
        return;
    unlink(name);
}
Esempio n. 6
0
File: fmd_log.c Progetto: kadoma/fms
int
fmd_log_open(const char *dir, int type)
{
	char datename[PATH_MAX];
	char filename[PATH_MAX];
	int fd;
	struct dirent *dp;
	const char *logname;
	DIR *dirp;

	if (access(dir, 0) != 0) {
		wr_log("", WR_LOG_ERROR, 
			"FMD: Log Directory %s isn't exist, so create it.\n", dir);
		mkdir(dir, 0777 );
	}

	if ((dirp = opendir(dir)) == NULL) {
		wr_log("", WR_LOG_ERROR, 
			"FMD: failed to open directory %s\n", dir);
		return (-1);
	}

	logname = get_logname(datename, type);
	snprintf(filename, sizeof(filename), "%s/%s", dir, logname);

	if (access(filename, 0) != 0) {
		if ((fd = open(filename, O_RDWR | O_CREAT | O_SYNC | O_APPEND, S_IREAD | S_IWRITE)) < 0) {
			wr_log("", WR_LOG_ERROR, 
				"FMD: failed to create log file %s\n", filename);
			(void) closedir(dirp);
			return (-1);
		}
        } else {
		if ((fd = open(filename, O_RDWR | O_SYNC | O_APPEND)) < 0) {
			wr_log("", WR_LOG_ERROR, 
				"FMD: failed to open log file %s\n", filename);
			(void) closedir(dirp);
			return (-1);
		}
	}
        (void) closedir(dirp);

	return fd;
}
Esempio n. 7
0
//-------------------------------------------------------------------------------------------------
Logger *Configuration::create_logger(const XmlElement *from, const Logtype ltype, const SessionID *sid) const
{
	string name;
	if (from && from->GetAttr(ltype == session_log ? "session_log" : "protocol_log", name))
	{
		const XmlElement *which(find_logger(name));
		if (which)
		{
			string type;
			if (which->GetAttr("type", type)
				&& ((type % "session" && ltype == session_log) || (type % "protocol" && ltype == protocol_log)))
			{
				string logname("logname_not_set.log");
				which->FindAttrRef("filename", logname);
				trim(logname);

				if (logname[0] == '|')
#ifndef HAVE_POPEN
					throw f8Exception("popen not supported on your platform");
#endif
					return new PipeLogger(logname, get_logflags(which));

				RegMatch match;
				if (_ipexp.SearchString(match, logname, 3) == 3)
				{
					f8String ip, port;
					_ipexp.SubExpr(match, logname, ip, 0, 1);
					_ipexp.SubExpr(match, logname, port, 0, 2);
					BCLogger *bcl(new BCLogger(ip, get_value<unsigned>(port), get_logflags(which)));
					if (*bcl)
						return bcl;
				}

				get_logname(which, logname, sid); // only applies to file loggers
				return new FileLogger(logname, get_logflags(which), get_logfile_rotation(which));
			}
		}
	}

	return 0;
}
Esempio n. 8
0
static void remove_log(void)
{
    time_t t;
    struct tm tm;

    char name[PATH_MAX];

    if (!KeepLogs)
        return;

    time(&t);
    t -= (60 * 60 * 24 * KeepLogs);
    tm = *localtime(&t);

    /* removed if from here cause get_logchan is always 1 */
    get_logname(name, sizeof(name), &tm);
#ifndef _WIN32
    unlink(name);
#else
    DeleteFile(name);
#endif
}
Esempio n. 9
0
//-------------------------------------------------------------------------------------------------
Logger *Configuration::create_logger(const XmlEntity *from, const Logtype ltype) const
{
	string name;
	if (from && from->GetAttr(ltype == session_log ? "session_log" : "protocol_log", name))
	{
		const XmlEntity *which(find_logger(name));
		if (which)
		{
			string type;
			if (which->GetAttr("type", type)
				&& ((type % "session" && ltype == session_log) || (type % "protocol" && ltype == protocol_log)))
			{
				string logname("logname_not_set.log");
				trim(get_logname(which, logname));

				if (logname[0] == '|' || logname[0] == '!')
					return new PipeLogger(logname, get_logflags(which));

				RegMatch match;
				if (_ipexp.SearchString(match, logname, 3) == 3)
				{
					f8String ip, port;
					_ipexp.SubExpr(match, logname, ip, 0, 1);
					_ipexp.SubExpr(match, logname, port, 0, 2);
					BCLogger *bcl(new BCLogger(ip, GetValue<unsigned>(port), get_logflags(which)));
					if (*bcl)
						return bcl;
				}

				return new FileLogger(logname, get_logflags(which), get_logfile_rotation(which));
			}
		}
	}

	return 0;
}