{"action":"created","issue":{"url":"https://api.github.com/repos/gabime/spdlog/issues/630","repository_url":"https://api.github.com/repos/gabime/spdlog","labels_url":"https://api.github.com/repos/gabime/spdlog/issues/630/labels{/name}","comments_url":"https://api.github.com/repos/gabime/spdlog/issues/630/comments","events_url":"https://api.github.com/repos/gabime/spdlog/issues/630/events","html_url":"https://github.com/gabime/spdlog/issues/630","id":294682956,"number":630,"title":"Logger per class","user":{"login":"thoism","id":524466,"avatar_url":"https://avatars1.githubusercontent.com/u/524466?v=4","gravatar_id":"","url":"https://api.github.com/users/thoism","html_url":"https://github.com/thoism","followers_url":"https://api.github.com/users/thoism/followers","following_url":"https://api.github.com/users/thoism/following{/other_user}","gists_url":"https://api.github.com/users/thoism/gists{/gist_id}","starred_url":"https://api.github.com/users/thoism/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoism/subscriptions","organizations_url":"https://api.github.com/users/thoism/orgs","repos_url":"https://api.github.com/users/thoism/repos","events_url":"https://api.github.com/users/thoism/events{/privacy}","received_events_url":"https://api.github.com/users/thoism/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-06T09:14:46Z","updated_at":"2018-02-06T12:40:22Z","closed_at":null,"author_association":"NONE","body":"Is there a way to have a unique logger per class? I tried creating global sinks for every logger per class but it seems that the log messages are printed X times. When I say X times it depends on the number of class instances having their own logger.\r\n\r\n```\r\nconst std::vector<spdlog::sink_ptr>& GetLogSinks() {\r\n  static std::vector<spdlog::sink_ptr> sinks;\r\n  auto stdout_sink = spdlog::sinks::stdout_sink_mt::instance();\r\n  sinks.push_back(stdout_sink);\r\n  auto daily_file_sink = std::make_shared<spdlog::sinks::daily_file_sink_st>(\"service.log\", 23, 59);\r\n  sinks.push_back(daily_file_sink);\r\n  return sinks;\r\n}\r\n\r\nstd::unique_ptr<spdlog::logger> CreateLogger(const std::string &name){\r\n  const auto& sinks = GetLogSinks();\r\n  auto logger = std::unique_ptr<spdlog::logger>(new spdlog::logger(name, begin(sinks), end(sinks)));\r\n  logger->set_level(spdlog::level::debug);\r\n  return logger;\r\n}\r\n\r\nmy_class(const std::string& name) : m_log(CreateLogger(__FUNCTION__)), m_name(name) {}\r\n\r\n```\r\n\r\nThank you priori for your time."},"comment":{"url":"https://api.github.com/repos/gabime/spdlog/issues/comments/363410176","html_url":"https://github.com/gabime/spdlog/issues/630#issuecomment-363410176","issue_url":"https://api.github.com/repos/gabime/spdlog/issues/630","id":363410176,"user":{"login":"thoism","id":524466,"avatar_url":"https://avatars1.githubusercontent.com/u/524466?v=4","gravatar_id":"","url":"https://api.github.com/users/thoism","html_url":"https://github.com/thoism","followers_url":"https://api.github.com/users/thoism/followers","following_url":"https://api.github.com/users/thoism/following{/other_user}","gists_url":"https://api.github.com/users/thoism/gists{/gist_id}","starred_url":"https://api.github.com/users/thoism/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thoism/subscriptions","organizations_url":"https://api.github.com/users/thoism/orgs","repos_url":"https://api.github.com/users/thoism/repos","events_url":"https://api.github.com/users/thoism/events{/privacy}","received_events_url":"https://api.github.com/users/thoism/received_events","type":"User","site_admin":false},"created_at":"2018-02-06T12:40:22Z","updated_at":"2018-02-06T12:40:22Z","author_association":"NONE","body":"Apologies I found my issue\r\n\r\n```\r\nconst std::vector<spdlog::sink_ptr>& GetLogSinks() {\r\n  static std::vector<spdlog::sink_ptr> sinks;\r\n  // I should check if the sinks container is not empty before adding the sink instances\r\n  if(sinks.size > 0) { return sinks; }\r\n  auto stdout_sink = spdlog::sinks::stdout_sink_mt::instance();\r\n  sinks.push_back(stdout_sink);\r\n  auto daily_file_sink = std::make_shared<spdlog::sinks::daily_file_sink_st>(\"service.log\", 23, 59);\r\n  sinks.push_back(daily_file_sink);\r\n  return sinks;\r\n}\r\n```"}}
{"actor":{"display_login":"thoism"}}