Skip to content

Commit

Permalink
Merge pull request #614 from muflihun/develop
Browse files Browse the repository at this point in the history
9.96.1
  • Loading branch information
abumq authored Feb 23, 2018
2 parents 89f61e5 + ac1a71c commit a7b9d65
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 11 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [9.96.1] - 23-02-2018
### Fixes
- Two loggers writing to same file is undefined behaviour #613

## [9.96.0] - 14-02-2018
### Fixes
- Potential deadlocks in extreme edge case #609
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ option(lib_utc_datetime "Build library with UTC date/time logging" OFF)

set(ELPP_MAJOR_VERSION "9")
set(ELPP_MINOR_VERSION "96")
set(ELPP_PATCH_VERSION "0")
set(ELPP_PATCH_VERSION "1")
set(ELPP_VERSION_STRING "${ELPP_MAJOR_VERSION}.${ELPP_MINOR_VERSION}.${ELPP_PATCH_VERSION}")

set(ELPP_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in")
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

![banner]

> **Manual For v9.96.0**
> **Manual For v9.96.1**
[![Build Status (Master)](https://img.shields.io/travis/muflihun/easyloggingpp/master.svg)](https://travis-ci.org/muflihun/easyloggingpp) [![Build Status (Develop)](https://img.shields.io/travis/muflihun/easyloggingpp/develop.svg)](https://travis-ci.org/muflihun/easyloggingpp) [![Version](https://img.shields.io/github/release/muflihun/easyloggingpp.svg)](https://github.com/muflihun/easyloggingpp/releases/latest)

Expand Down Expand Up @@ -100,7 +100,7 @@
# Overview
Easylogging++ is single header efficient logging library for C++ applications. It is extremely powerful, highly extendable and configurable to user's requirements. It provides ability to [write your own _sinks_](/samples/send-to-network) (via featured referred as `LogDispatchCallback`). This library is currently used by [hundreds of open-source projects on github](https://github.com/search?q=%22easylogging%2B%2B.h%22&type=Code&utf8=%E2%9C%93) and other open-source source control management sites.

This manual is for Easylogging++ v9.96.0. For other versions please refer to corresponding [release](https://github.com/muflihun/easyloggingpp/releases) on github.
This manual is for Easylogging++ v9.96.1. For other versions please refer to corresponding [release](https://github.com/muflihun/easyloggingpp/releases) on github.

> You may also be interested in [Residue](https://github.com/muflihun/residue/) logging server.
Expand Down
39 changes: 39 additions & 0 deletions samples/STL/multi-loggers-to-same-file.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// This file is part of Easylogging++ samples
//
// Revision 1.0
//

#include <thread>
#include "easylogging++.h"

INITIALIZE_EASYLOGGINGPP

void def() {
for (int i = 0; i < 10000; ++i)
CLOG(INFO, "first") << "This is from first " << i;
}

void second() {
for (int i = 0; i < 10000; ++i)
CLOG(INFO, "second") << "This is from second" << i;
}

int main(int,char**){
el::Loggers::addFlag(el::LoggingFlag::CreateLoggerAutomatically);

el::Configurations confFromFile("../default-logger.conf");

el::Loggers::setDefaultConfigurations(confFromFile, true);

LOG(INFO)<<"The program has started!";

std::thread t1(def);
std::thread t2(second);

t1.join();
t2.join();

LOG(INFO) << "Shutting down.";
return 0;
}
2 changes: 1 addition & 1 deletion samples/default-logger.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
* GLOBAL:
FORMAT = "%datetime | %level | %msg"
FORMAT = "%datetime | %level | %logger | %msg"
FILENAME = "/tmp/logs/myeasylog-configuration.cpp.log"
ENABLED = true
TO_FILE = true
Expand Down
28 changes: 25 additions & 3 deletions src/easylogging++.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Bismillah ar-Rahmaan ar-Raheem
//
// Easylogging++ v9.96.0
// Easylogging++ v9.96.1
// Cross-platform logging library for C++ applications
//
// Copyright (c) 2012-2018 Muflihun Labs
Expand Down Expand Up @@ -2096,9 +2096,31 @@ void Storage::setApplicationArguments(int argc, char** argv) {
#endif // defined(ELPP_LOGGING_FLAGS_FROM_ARG)
}

} // namespace base

// LogDispatchCallback
void LogDispatchCallback::handle(const LogDispatchData* data) {
#if defined(ELPP_THREAD_SAFE)
base::threading::ScopedLock scopedLock(m_fileLocksMapLock);
std::string filename = data->logMessage()->logger()->typedConfigurations()->filename(data->logMessage()->level());
auto lock = m_fileLocks.find(filename);
if (lock == m_fileLocks.end()) {
m_fileLocks.emplace(std::make_pair(filename, new base::threading::Mutex));
}
#endif
}

base::threading::Mutex& LogDispatchCallback::fileHandle(const LogDispatchData* data) {
auto it = m_fileLocks.find(data->logMessage()->logger()->typedConfigurations()->filename(data->logMessage()->level()));
return *(it->second.get());
}

namespace base {
// DefaultLogDispatchCallback

void DefaultLogDispatchCallback::handle(const LogDispatchData* data) {
LogDispatchCallback::handle(data);
base::threading::ScopedLock scopedLock(fileHandle(data));
m_data = data;
dispatch(m_data->logMessage()->logger()->logBuilder()->build(m_data->logMessage(),
m_data->dispatchAction() == base::DispatchAction::NormalLog));
Expand Down Expand Up @@ -2982,11 +3004,11 @@ void Loggers::clearVModules(void) {
// VersionInfo

const std::string VersionInfo::version(void) {
return std::string("9.96.0");
return std::string("9.96.1");
}
/// @brief Release date of current version
const std::string VersionInfo::releaseDate(void) {
return std::string("14-02-2018 1629hrs");
return std::string("23-02-2018 1708hrs");
}

} // namespace el
11 changes: 7 additions & 4 deletions src/easylogging++.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Bismillah ar-Rahmaan ar-Raheem
//
// Easylogging++ v9.96.0
// Easylogging++ v9.96.1
// Single-header only, cross-platform logging library for C++ applications
//
// Copyright (c) 2012-2018 Muflihun Labs
Expand Down Expand Up @@ -380,6 +380,7 @@ ELPP_INTERNAL_DEBUGGING_OUT_INFO << ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStre
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <utility>
#include <functional>
#include <algorithm>
Expand Down Expand Up @@ -417,9 +418,6 @@ ELPP_INTERNAL_DEBUGGING_OUT_INFO << ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStre
# if defined(ELPP_LOG_STD_ARRAY)
# include <array>
# endif // defined(ELPP_LOG_STD_ARRAY)
# if defined(ELPP_LOG_UNORDERED_MAP)
# include <unordered_map>
# endif // defined(ELPP_LOG_UNORDERED_MAP)
# if defined(ELPP_LOG_UNORDERED_SET)
# include <unordered_set>
# endif // defined(ELPP_UNORDERED_SET)
Expand Down Expand Up @@ -2238,8 +2236,13 @@ class LogDispatchData {
}
};
class LogDispatchCallback : public Callback<LogDispatchData> {
protected:
virtual void handle(const LogDispatchData* data);
base::threading::Mutex& fileHandle(const LogDispatchData* data);
private:
friend class base::LogDispatcher;
std::unordered_map<std::string, std::unique_ptr<base::threading::Mutex>> m_fileLocks;
base::threading::Mutex m_fileLocksMapLock;
};
class PerformanceTrackingCallback : public Callback<PerformanceTrackingData> {
private:
Expand Down

0 comments on commit a7b9d65

Please sign in to comment.