Solved

Error using BOOST_LOG_GLOBAL_LOGGER

Posted on 2013-11-20
7
1,350 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

734 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