Solved

Error using BOOST_LOG_GLOBAL_LOGGER

Posted on 2013-11-20
7
1,285 Views
Last Modified: 2013-12-11
I try to add this line to the below code after all me namespace declaration.

BOOST_LOG_GLOBAL_LOGGER(my_logger, boost::log::sources::severity_logger_mt)

I got a lot of errors (see below). I am not sure how to look into this problem. Any idea? Error C2955: 'boost::log::v2s_mt_nt5::sources::severity_logger_mt' : use of class template requires template argument list

/*
    *          Copyright Andrey Semashev 2007 - 2013.
    * Distributed under the Boost Software License, Version 1.0.
    *    (See accompanying file LICENSE_1_0.txt or copy at
    *          http://www.boost.org/LICENSE_1_0.txt)
    */

#include <boost/move/utility.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/global_logger_storage.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace keywords = boost::log::keywords;

BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::logger_mt)

void logging_function1()
{
    src::logger lg;

//[ example_tutorial_logging_manual_logging
    logging::record rec = lg.open_record();
    if (rec)
    {
        logging::record_ostream strm(rec);
        strm << "Hello, World!";
        strm.flush();
        lg.push_record(boost::move(rec));
    }
//]
}

void logging_function2()
{
    src::logger_mt& lg = my_logger::get();
    BOOST_LOG(lg) << "Greetings from the global logger!";
}

int main(int, char*[])
{
    logging::add_file_log("sample.log");
    logging::add_common_attributes();

    logging_function1();
    logging_function2();

    return 0;
}
0
Comment
Question by:tommym121
  • 4
  • 3
7 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39666204
'severity_logger_mt' is a template class, see http://boost-log.sourceforge.net/libs/log1/doc/html/log/detailed/sources.html - however, you can just use it like

BOOST_LOG_GLOBAL_LOGGER(my_logger, boost::log::sources::severity_logger_mt< >)

Open in new window

0
 

Author Comment

by:tommym121
ID: 39672165
It complain my_logger
This is the code
#include "stdafx.h"

/*
*          Copyright Andrey Semashev 2007 - 2013.
* Distributed under the Boost Software License, Version 1.0.
*    (See accompanying file LICENSE_1_0.txt or copy at
*          http://www.boost.org/LICENSE_1_0.txt)
*/



#include <boost/move/utility.hpp>
#include <boost/log/sources/logger.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/sources/global_logger_storage.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>

namespace logging = boost::log;
namespace src = boost::log::sources;
namespace keywords = boost::log::keywords;

//BOOST_LOG_GLOBAL_LOGGER(my_logger, boost::log::sources::severity_logger_mt)
BOOST_LOG_GLOBAL_LOGGER(my_logger, boost::log::sources::severity_logger_mt< >)

BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::logger_mt)

void logging_function1()
{
      src::logger lg;

      //[ example_tutorial_logging_manual_logging
      logging::record rec = lg.open_record();
      if (rec)
      {
            logging::record_ostream strm(rec);
            strm << "Hello, World! ";
            strm.flush();
            lg.push_record(boost::move(rec));
      }
      //]
}

void logging_function2()
{
      src::logger_mt& lg = my_logger::get();
      BOOST_LOG(lg) << "Greetings from the global logger! ";
}

int main(int, char*[])
{
      logging::add_file_log("sample.log");
      logging::add_common_attributes();

      logging_function2();
      logging_function1();

      return 0;
}

///////////////////////////////////////////////////////////////////////////////
This is the error
///////////////////////////////////////////////////////////////////////////////
1>------ Build started: Project: global_log, Configuration: Debug Win32 ------
1>  global_log.cpp
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(30): error C2011: 'my_logger' : 'struct' type redefinition
1>          c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(28) : see declaration of 'my_logger'
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(30): error C2027: use of undefined type 'my_logger'
1>          c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(28) : see declaration of 'my_logger'
1>          c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(28) : see declaration of 'my_logger'
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(30): error C2146: syntax error : missing ';' before identifier 'construct_logger'
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(30): error C2433: 'logger_type' : 'inline' not permitted on data declarations
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(30): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(30): error C2064: term does not evaluate to a function taking 0 arguments
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(30): warning C4508: 'construct_logger' : function should return a value; 'void' return type assumed
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(50): error C2027: use of undefined type 'my_logger'
1>          c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(28) : see declaration of 'my_logger'
1>c:\users\tommy\documents\visual studio 2013\projects\boost\global_log\global_log.cpp(50): error C3861: 'get': identifier not found
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
0
 
LVL 86

Expert Comment

by:jkr
ID: 39672178
Well, if the line numbers would match what you posted, we could get ahead (hint: that what's the 'code' part in the formatting options is for). So, what exactly is line 30?
0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 

Author Comment

by:tommym121
ID: 39683524
This is the line
BOOST_LOG_GLOBAL_LOGGER(my_logger, boost::log::sources::severity_logger_mt< >)
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39684230
Ahh, I see. Well, you can only use one of

// either this one
BOOST_LOG_GLOBAL_LOGGER(my_logger, boost::log::sources::severity_logger_mt< >)

// OR that one
BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(my_logger, src::logger_mt)

Open in new window


but not both - see http://www.boost.org/doc/libs/1_54_0/boost/log/sources/global_logger_storage.hpp

//! The macro declares a global logger with a custom initialization
#define BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(tag_name, logger)\
    BOOST_LOG_GLOBAL_LOGGER(tag_name, logger)\
    inline BOOST_LOG_GLOBAL_LOGGER_INIT(tag_name, logger)

//! The macro declares a global logger that will be default-constructed
#define BOOST_LOG_INLINE_GLOBAL_LOGGER_DEFAULT(tag_name, logger)\
    BOOST_LOG_INLINE_GLOBAL_LOGGER_INIT(tag_name, logger)\
    {\
        return logger_type();\
    }

Open in new window


The latter statement creates another 'BOOST_LOG_GLOBAL_LOGGER()', thus the error.
0
 
LVL 86

Expert Comment

by:jkr
ID: 39709872
Still having problems with this one?
0
 

Author Closing Comment

by:tommym121
ID: 39710944
Jkr,

Thanks. Almost forget to close it. It works.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question