2 * 2008+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <elliptics/cppdef.h>
18 using namespace ioremap::elliptics
;
20 void logger::real_logger(void *priv
, const int level
, const char *msg
)
22 logger
*log
= reinterpret_cast<logger
*> (priv
);
27 log_file::log_file(const char *file
, const int level
) :
31 this->file
= new std::string(file
);
37 stream
= new std::ofstream(file
, std::ios_base::app
);
44 unsigned long log_file::clone(void)
46 return reinterpret_cast<unsigned long>(new log_file (file
->c_str(), get_log_level()));
49 log_file::~log_file(void)
55 void log_file::log(int level
, const char *msg
)
57 if (level
< ll
.log_level
) {
61 char usecs_and_id
[64];
63 gettimeofday(&tv
, NULL
);
64 localtime_r((time_t *)&tv
.tv_sec
, &tm
);
65 strftime(str
, sizeof(str
), "%F %R:%S", &tm
);
67 snprintf(usecs_and_id
, sizeof(usecs_and_id
), ".%06lu %ld/%d : ", tv
.tv_usec
, dnet_get_id(), getpid());
69 (*stream
) << str
<< usecs_and_id
<< msg
;