filelogger.cpp 1.11 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
/*******************************************************************************
 * Copyright 2019 UChicago Argonne, LLC.
 * (c.f. AUTHORS, LICENSE)
 *
 * This file is part of the Argo containers project.
 * For more info, see https://xgitlab.cels.anl.gov/argo/containers
 *
 * SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/

Swann Perarnau's avatar
Swann Perarnau committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "filelogger.hpp"
#include "common.hpp"
#include <string>
#include "utils.hpp"
#include "trace.hpp"

Filelogger::Filelogger(uid_t ruid, const string& filename, Log_type log_type,
		bool append):
	ILogger(ruid, log_type)
{
	std::ios_base::openmode mode = std::ofstream::out;
	if(append)
		mode |= std::ofstream::app;
	_file.open (filename.c_str(), mode);
	TRACE_LOC_ON_MASK(LOGGING_MASK, 
			"Built Filelogger with log_type = %s; and filename = %s\n",
			log_type_to_str(log_type).c_str(), filename.c_str());
}

Filelogger::~Filelogger()
{
	_file.close();
}

void Filelogger::log(Log_type type, const string& message, int errnum)
{
	std::string msg_out;
	if(prepare_log(type, message, msg_out, errnum))
		_file<<msg_out<<std::endl;
}