Solved

Error using BOOST_LOG_GLOBAL_LOGGER

Posted on 2013-11-20
7
1,231 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

  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 …
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 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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

705 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now