Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Error using BOOST_LOG_GLOBAL_LOGGER

Posted on 2013-11-20
7
Medium Priority
?
1,495 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

886 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