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 8437067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:20:06+00:00 2026-06-10T07:20:06+00:00

Is there a simple api (without loop) to check if varargs contain some value

  • 0

Is there a simple api (without loop) to check if varargs contain some value (char*)?

If there is no simple API , how should i iterate without any args count?

My method should be able to filter the log base on configuration IP ,so i need to check if one of the args is 10.3.2.2 (some configuration IP).

void Logger::Log(const char *format, ...) {
    lock_guard<mutex> guard(mtx_);
    if (!file_) {
        file_ = fopen("application.log", "w");
    }
    time_t current = time(0);
    tm *ptm = localtime(&current);
    stringstream ss;
    ss << "\n[" << ptm->tm_min << ":" << ptm->tm_sec << "]";
    fprintf(file_, ss.str().data());
    va_list argptr;
    va_start(argptr, format);
    vfprintf(file_, format, argptr);
    va_end(argptr);
    fflush(file_);
}

looking on this lesson , show only iterate with given args length and types.
format and than check contain is expensive and logger should be able to support in highly performance demands.

my target is to implement simple logger method. so you will call it like this:

Log("trafic from ip %s to ip %s", "10.1.1.1","1.1.1.1")

and lots of other calls . in the filter i want to check if one of the parameter value is “10.1.1.1” (for example) , so don’t log it.

  • 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-10T07:20:07+00:00Added an answer on June 10, 2026 at 7:20 am

    There isn’t any syntactic sugar to do this because there is no universal way to know the types of the varargs. Without knowing the types, you can’t get their values. So you’d have to write code to do this based on how your functions knows what types its arguments are.

    You want to do this:

    1. Assemble the entire log message in the stringstream.

    2. Check the log message for the desired string.

    3. If you find the string in there, make sure it is not preceded or followed by a digit.

    4. If you found the string and it’s not preceded or followed by a digit, log it.

    You need that last check because “foo bar 12.3.4.5 baz” contains “2.3.4.5” as does “foo 2.3.4.51 bar”. So if you find the string and it’s followed or preceded by a digit, you still want to log the message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple maze game, without using any deprecated OpenGL API
There is a simple http server API that allow you do some simple stuff
I am using JSON-simple API to convert java object array to JSON string without
I thought about building a simple API to let users grab some of our
Are there simple libraries out there (.NET and Java) that are able to validate
There is simple cipher that translates number to series of . ( ) In
There is simple JSON serialization module with name simplejson which easily serializes Python objects
Is there a simple way to insert the current time (like TIME: [2012-07-02 Mon
Is there a simple shuffle function for Scala lists? If not, whats the simplest
Is there a simple way to serialize a single-level structure as a string for

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.