Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:57:39+00:00 2026-06-15T01:57:39+00:00

I wrote my own simple class for logging. I understand that I better to

  • 0

I wrote my own simple class for logging. I understand that I better to use some kind of library (boost.log, log4cpp?) but let’s anyway discuss my simple class:

#include "stdafx.h"
#include "Logger.h"


Logger::Logger(std::string fileName)
{
    logFile.open(fileName);
}


Logger::~Logger(void)
{
    logFile.close();
}


void Logger::Error(std::string message) {
    logFile << message << std::endl;
}

void Logger::Debug(std::string message) {
    logFile << message << std::endl;
}
  1. I want my methods to accept variable number of arguments, so I can pass parameters like that "Error code: %x", code. How to do that?
  2. I want Debug method to be excluded if LOG_DEBUG compilation symbol is not set. in C# I can just add [Conditional("LOG_DEBUG")] before the method declaration, but now to do that in c++?

upd Regarding 1 i’ve tried that and it works:

void Logger::Debug(std::string message, ...) {
va_list arglist;
fprintf(pFile, message.c_str(), arglist);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:57:42+00:00Added an answer on June 15, 2026 at 1:57 am

    I want my methods to accept variable number of arguments, so I can pass parameters like that “Error code: %x”, code. How to do that?

    You have two solutions for this:

    1. use printf-like formatting. This would require the usage of va_list, va_arg and va_end macros.

    2. use operator overloading (as in @Joachim’s answer).

    I want Debug method to be excluded if LOG_DEBUG compilation symbol is not set. in C# I can just add [Conditional(“LOG_DEBUG”)] before the method declaration, but now to do that in c++?

    You define a logging macro, in two different ways, depending on DEBUG macro definition (or NDEBUG or something similar):

    #ifdef DEBUG
    #define LOGE(X) Logger::Error(X)
    #define LOGD(X) Logger::Debug(X)
    #else
    #define LOGE(X) 
    #define LOGD(X) 
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Perl script I wrote for my own personal use that fetches
I'm trying to write my own logging class and use it as a stream:
With the upcoming rise of AJAX applications on the web, I wrote some own
Since I'm using Postgresql and can't use LINQ to SQL, I wrote my own
For this assignment I had to create my own string class. I initially wrote
I trying to write my own Event Aggregation class and i go some articles
I want to implement a simple class for logging from multiple threads. The idea
Using the advice of another stack overflow question I wrote my own LogWriter class:
I want to write my own simple DI framework. I want that it perform
Because I prefer a more object oriented approach I wrote my own json class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.