-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
164 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
namespace blackhole { | ||
inline namespace v1 { | ||
namespace sink { | ||
namespace file { | ||
|
||
class rotate_t { | ||
public: | ||
virtual ~rotate_t() = default; | ||
virtual auto should_rotate() -> bool = 0; | ||
}; | ||
|
||
class rotate_factory_t { | ||
public: | ||
virtual ~rotate_factory_t() = default; | ||
virtual auto create(const std::string& filename) const -> std::unique_ptr<rotate_t> = 0; | ||
}; | ||
|
||
} // namespace file | ||
} // namespace sink | ||
} // namespace v1 | ||
} // namespace blackhole |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include "../../../memory.hpp" | ||
#include "../rotate.hpp" | ||
|
||
namespace blackhole { | ||
inline namespace v1 { | ||
namespace sink { | ||
namespace file { | ||
namespace rotate { | ||
|
||
class null_rotate_t : public rotate_t { | ||
public: | ||
auto should_rotate() -> bool override { | ||
return false; | ||
} | ||
}; | ||
|
||
class null_factory_t : public rotate_factory_t { | ||
public: | ||
auto create(const std::string&) const -> std::unique_ptr<rotate_t> override { | ||
return blackhole::make_unique<null_rotate_t>(); | ||
} | ||
}; | ||
|
||
} // namespace rotate | ||
} // namespace file | ||
} // namespace sink | ||
} // namespace v1 | ||
} // namespace blackhole |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#pragma once | ||
|
||
#include <sys/stat.h> | ||
|
||
#include <string> | ||
#include <system_error> | ||
|
||
#include "../rotate.hpp" | ||
|
||
namespace blackhole { | ||
inline namespace v1 { | ||
namespace sink { | ||
namespace file { | ||
namespace rotate { | ||
|
||
class stat_rotate_t : public rotate_t { | ||
std::string filename; | ||
std::int64_t inode; | ||
|
||
public: | ||
explicit stat_rotate_t(std::string filename) : | ||
filename(std::move(filename)), | ||
inode(0) | ||
{ | ||
struct stat buf = {}; | ||
auto rc = ::stat(this->filename.c_str(), &buf); | ||
if (rc == -1) { | ||
throw std::system_error(errno, std::system_category()); | ||
} | ||
|
||
inode = std::int64_t(buf.st_ino); | ||
} | ||
|
||
auto should_rotate() -> bool override { | ||
struct stat buf = {}; | ||
auto rc = ::stat(filename.c_str(), &buf); | ||
|
||
return !(rc == 0 && std::int64_t(buf.st_ino) == inode); | ||
} | ||
}; | ||
|
||
class stat_factory_t : public rotate_factory_t { | ||
public: | ||
auto create(const std::string& filename) const -> std::unique_ptr<rotate_t> override { | ||
return blackhole::make_unique<stat_rotate_t>(filename); | ||
} | ||
}; | ||
|
||
} // namespace rotate | ||
} // namespace file | ||
} // namespace sink | ||
} // namespace v1 | ||
} // namespace blackhole |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters