Skip to content

Commit

Permalink
Merge pull request #1447 from Framstag/split_logger
Browse files Browse the repository at this point in the history
Split logger into interface and implementation, reducing the number o…
  • Loading branch information
Framstag committed Jun 11, 2023
2 parents 0fc6c75 + 59eb56f commit 65221c1
Show file tree
Hide file tree
Showing 15 changed files with 257 additions and 164 deletions.
1 change: 1 addition & 0 deletions Demos/src/DrawMapDirectX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ src/DrawMapDirectX ../maps/nordrhein-westfalen ../stylesheets/standard.oss 51.51
#include <dwrite.h>

#include <iostream>
#include <sstream>

#include <osmscoutmap/MapService.h>

Expand Down
1 change: 1 addition & 0 deletions Demos/src/DrawMapGDI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ src/DrawMapGDI ../maps/nordrhein-westfalen ../stylesheets/standard.oss 51.51241
*/

#include <iostream>
#include <sstream>

#include <osmscoutmap/MapService.h>

Expand Down
1 change: 1 addition & 0 deletions Demos/src/Routing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <iostream>
#include <iomanip>
#include <list>
#include <sstream>
#include <fstream>

#include <osmscout/db/Database.h>
Expand Down
1 change: 1 addition & 0 deletions Tests/src/PerformanceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <iostream>
#include <iomanip>
#include <sstream>
#include <limits>
#include <tuple>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
*/

#include <osmscoutclientqt/ElevationChartWidget.h>
#include <osmscoutclientqt/OSMScoutQt.h>
#include <osmscout/util/String.h>

#include <QPainterPath>

#include <limits>
#include <sstream>

#include <osmscout/util/String.h>

#include <osmscoutclientqt/OSMScoutQt.h>

namespace osmscout {

ElevationChartWidget::ElevationChartWidget(QQuickItem* parent):
Expand Down
1 change: 1 addition & 0 deletions libosmscout-gpx/src/osmscoutgpx/Export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>

using namespace osmscout;
using namespace osmscout::gpx;
Expand Down
3 changes: 1 addition & 2 deletions libosmscout-map/src/osmscoutmap/MapPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

#include <osmscoutmap/MapPainter.h>

#include <cstdint>

#include <algorithm>
#include <limits>
#include <sstream>

#include <osmscout/system/Math.h>

Expand Down
2 changes: 2 additions & 0 deletions libosmscout/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ set(HEADER_FILES_UTIL
include/osmscout/util/GeoBox.h
include/osmscout/util/Geometry.h
include/osmscout/util/Logger.h
include/osmscout/util/LoggerImpl.h
include/osmscout/util/Magnification.h
include/osmscout/util/MemoryMonitor.h
include/osmscout/util/NodeUseMap.h
Expand Down Expand Up @@ -273,6 +274,7 @@ set(SOURCE_FILES
src/osmscout/util/GeoBox.cpp
src/osmscout/util/Geometry.cpp
src/osmscout/util/Logger.cpp
src/osmscout/util/LoggerImpl.cpp
src/osmscout/util/Magnification.cpp
src/osmscout/util/MemoryMonitor.cpp
src/osmscout/util/NodeUseMap.cpp
Expand Down
1 change: 1 addition & 0 deletions libosmscout/include/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ osmscoutHeader = [
'osmscout/util/GeoBox.h',
'osmscout/util/Geometry.h',
'osmscout/util/Logger.h',
'osmscout/util/LoggerImpl.h',
'osmscout/util/Magnification.h',
'osmscout/util/MemoryMonitor.h',
'osmscout/util/NodeUseMap.h',
Expand Down
66 changes: 3 additions & 63 deletions libosmscout/include/osmscout/util/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <string_view>

#include <osmscout/CoreFeatures.h>

#include <osmscout/CoreImportExport.h>

#include <ostream>
#include <sstream>

#include <osmscout/util/StopClock.h>
#include <osmscout/util/Distance.h>
#include <osmscout/util/StopClock.h>

// Since we have a DEBUG enumeration member
#ifdef DEBUG
Expand Down Expand Up @@ -345,65 +344,6 @@ namespace osmscout {
}
};

/**
* \ingroup Logging
* The StreamLogger allows to direct logging output to a standard library std::ostream.
* IT allows to assign one stream for DEBUG and INFO logging and a different stream
* for WARN and ERROR log output.
*/
class OSMSCOUT_API StreamLogger : public Logger
{
private:
/**
* \ingroup Logging
* Special Destination implementation that delegates printing to the assigned
* std::ostream.
*/
class OSMSCOUT_API StreamDestination : public Destination
{
private:
std::ostream& stream;

public:
explicit StreamDestination(std::ostream& stream);

void Print(const std::string& value) override;
void Print(const std::string_view& value) override;
void Print(const char* value) override;
void Print(bool value) override;
void Print(short value) override;
void Print(unsigned short value) override;
void Print(int value) override;
void Print(unsigned int value) override;
void Print(long value) override;
void Print(unsigned long value) override;
void Print(long long value) override;
void Print(unsigned long long value) override;
void PrintLn() override;
};

private:
StreamDestination infoDestination;
StreamDestination errorDestination;

public:
StreamLogger(std::ostream& infoStream,
std::ostream& errorStream);

Line Log(Level level) override;
};

/**
* \ingroup Logging
* The console logger extends the StreamLogger by assigning std::cout for normal
* loging output and std::cerr for error output.
*/
class OSMSCOUT_API ConsoleLogger : public StreamLogger
{
public:
ConsoleLogger();
};

/**
* \ingroup Logging
* Simple logging proxy object that encapsulates one exchangeable global
Expand Down
113 changes: 113 additions & 0 deletions libosmscout/include/osmscout/util/LoggerImpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#ifndef OSMSCOUT_UTIL_LOGGER_IMPL_H
#define OSMSCOUT_UTIL_LOGGER_IMPL_H

/*
This source is part of the libosmscout library
Copyright (C) 2015 Tim Teulings
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include <osmscout/CoreImportExport.h>

#include <osmscout/util/Logger.h>

#include <sstream>

namespace osmscout {

/**
* \ingroup Logging
* The StreamLogger allows to direct logging output to a standard library std::ostream.
* IT allows to assign one stream for DEBUG and INFO logging and a different stream
* for WARN and ERROR log output.
*/
class OSMSCOUT_API StreamLogger : public Logger
{
private:
/**
* \ingroup Logging
* Special Destination implementation that delegates printing to the assigned
* std::ostream.
*/
class OSMSCOUT_API StreamDestination : public Destination
{
private:
std::ostream& stream;

public:
explicit StreamDestination(std::ostream& stream);

void Print(const std::string& value) override;
void Print(const std::string_view& value) override;
void Print(const char* value) override;
void Print(bool value) override;
void Print(short value) override;
void Print(unsigned short value) override;
void Print(int value) override;
void Print(unsigned int value) override;
void Print(long value) override;
void Print(unsigned long value) override;
void Print(long long value) override;
void Print(unsigned long long value) override;
void PrintLn() override;
};

private:
StreamDestination infoDestination;
StreamDestination errorDestination;

public:
StreamLogger(std::ostream& infoStream,
std::ostream& errorStream);

Line Log(Level level) override;
};

/**
* \ingroup Logging
* The console logger extends the StreamLogger by assigning std::cout for normal
* loging output and std::cerr for error output.
*/
class OSMSCOUT_API ConsoleLogger : public StreamLogger
{
public:
ConsoleLogger();
};

/**
* \ingroup Logging
* The one an donly global instance of the logger that should get used
* for all logging output.
*/
extern OSMSCOUT_API Log log;
}

/**
* \defgroup Logging
*
* A logger is a special output stream, that is used by the library.
*
* The logger has a uniform interface independent of the actual
* data sink the information is stored to.
*
* This allows the application developer (and library user) to
* redirect logging output either to the console, to some special
* OS information sink, to "nowhere", to a file or any other location.
*
* The actual logger used can get exchanged by using Log::SetLogger.
*/

#endif
1 change: 1 addition & 0 deletions libosmscout/src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ osmscoutSrc = [
'src/osmscout/util/GeoBox.cpp',
'src/osmscout/util/Geometry.cpp',
'src/osmscout/util/Logger.cpp',
'src/osmscout/util/LoggerImpl.cpp',
'src/osmscout/util/Magnification.cpp',
'src/osmscout/util/MemoryMonitor.cpp',
'src/osmscout/util/NodeUseMap.cpp',
Expand Down
4 changes: 3 additions & 1 deletion libosmscout/src/osmscout/util/HTMLWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@

#include <osmscout/util/HTMLWriter.h>

#include <locale>
#include <sstream>

#include <osmscout/system/Assert.h>
#include <osmscout/util/Logger.h>
#include <locale>

namespace osmscout {

Expand Down
Loading

0 comments on commit 65221c1

Please sign in to comment.