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
Solved

Error using BOOST_LOG_GLOBAL_LOGGER

Posted on 2013-11-20
7
1,305 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C++ assignment question 7 236
I could not build boost code, 10 95
Unable to start eclipse ? 17 153
Safe conversion? 4 72
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

856 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