Skip to content

Commit

Permalink
Merge branch '44-chnage-program-name-bug' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
HerbertKoelman committed Apr 22, 2019
2 parents 1b5bfdb + da999e3 commit 60f66d0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
- memset issue (#40)
- use CMake build system (#37)
- replace cpp-pthread features by standard C++17 ones (#38)
- Fixed bugs #56, #57, #71
- Fixed bugs #56, #57, #71, #44

1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ endif(BUILD_TESTS)
find_package(Doxygen REQUIRED dot OPTIONAL_COMPONENTS mscgen dia)
if (Doxygen_FOUND)
set(DOXYGEN_EXAMPLE_PATH tests)
set(DOXYGEN_EXTRACT_ALL yes)
set(DOXYGEN_PROJECT_BRIEF "Simple C++ wrapper to pthread functions.")
set(DOXYGEN_USE_MDFILE_AS_MAINPAGE "${CMAKE_SOURCE_DIR}/README.md")
doxygen_add_docs(doxygen README.md src include COMMENT "generate on-line documentation")
Expand Down
3 changes: 3 additions & 0 deletions include/logger/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ namespace logger {
/** @return logger's name */
const std::string &name() const;

/** @return logger's program name */
const std::string &program_name() const;

/** create a logger instance.
*
* @param name logger name
Expand Down
11 changes: 7 additions & 4 deletions include/logger/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ namespace logger {

/** Searches the registry for the wanted logger instance.
*
* If the logger doesn't exist, then a new one is created and registered. Else the existing one is returned.:w
* If the logger doesn't exist, then a new one is created and registered. Else the existing one is returned. The factory
* create instances of stdout_sinks.
*
* @param name unique logger name
* @return a logger instance
* @see stdout_sink sink type used when creating a new instance.
* @see logger::stdout_sink
*/
logger_ptr get (const std::string &name );

Expand All @@ -54,6 +55,8 @@ namespace logger {
* *WARN* This name will be used by loggers created after this call. Pre-existing ones are not affected.
*
* @param pname program name
* @see logger::sink#program_name
* @see logger::logger#program_name
*/
void set_program_name(const std::string &pname);

Expand All @@ -67,7 +70,7 @@ namespace logger {
class registry {
public:

/** registry factory.
/** @return registry singleton
*/
static registry &instance();

Expand Down Expand Up @@ -200,7 +203,7 @@ namespace logger {
* @param name logger instance name
* @param args sink's constructor arguments
* @return a logger instance
* @see sink
* @see logger::sink
*/
template<class T, typename... Args> logger_ptr get( const std::string &name, const Args&... args){
return registry::instance().get<T>(name, args...);
Expand Down
7 changes: 6 additions & 1 deletion include/logger/sinks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,15 @@ namespace logger {
};

/** @return logger name */
std::string name() const {
const std::string &name() const {
return _name;
};

/** @return program name */
const std::string &program_name() const {
return _pname ;
}

/** change the current ecid.
*
* Setting this to an empty string will stop logger to prin
Expand Down
4 changes: 4 additions & 0 deletions src/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace logger {
/** @return logger name */
const std::string &logger::name() const {
return _name;
}

const std::string &logger::program_name() const {
return _sink->program_name();
};

} // namespace logger
13 changes: 6 additions & 7 deletions tests/logger_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,14 @@ TEST(logger, change_ecid) {
EXPECT_EQ(err->ecid(), "[M ECID=\"NEW ECID\"]");
}

TEST(logger, DISABLED_change_program_name) {
logger::logger_ptr out = logger::get<logger::stdout_sink>("stdout-test-logger");
EXPECT_NE(out, nullptr);
EXPECT_EQ(out->name(), "stdout-test-logger");
TEST(logger, program_name) {

auto pname = out->name();
logger::set_program_name("goolge-tests");
logger::set_program_name("google-tests");
logger::logger_ptr out = logger::get<logger::stdout_sink>("stdout-change-pname");

EXPECT_NE(out, nullptr);
EXPECT_EQ(out->program_name(), "google-tests");

EXPECT_EQ(out->name(), "google-tests");
}

TEST(logger, DISABLED_legacy) {
Expand Down

0 comments on commit 60f66d0

Please sign in to comment.