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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:56:13+00:00 2026-06-10T09:56:13+00:00

I have a linux application running on my desk top, and I wanted to

  • 0

I have a linux application running on my desk top, and I wanted to redirect the syslog() calls to printf() calls.

Note: I do not want to replace the calls, just redirect

So I wrote some code to do this:

#ifndef EMBED
#define syslog(level, stuff) printf("SYSLOG: %s\n", stuff)
#endif

Works great in the one file where I was using it. I moved this to a new file and got an error:

error: macro "syslog" passed 3 arguments, but takes just 2

I know the error is because the calls in the new file are mixed, some are using 2 arguments to syslog, some are using 3. I also know I need to somehow redirect this via variable argument lists, but how exactly do I do this? I haven’t gotten it working yet…

As I understand it, syslog() and printf() should be:

void syslog(int priority, const char *format, ...)
int printf(const char *format, ...)

So I tried:

#define ERR 3
#ifndef EMBED         // This is not defined in my env, btw
#define syslog(pri, fmt, ...) printf(fmt, ...)
#endif
...
void main() {
...
syslog(ERR, "test");

but that gives the error:

error: expected expression before ‘...’ token

Suggestions on how this macro should look/be used?

  • 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-10T09:56:15+00:00Added an answer on June 10, 2026 at 9:56 am

    GCC has an extension in this area, but the most portable way of handling it is:

    #define syslog(priority, ...)    printf(__VA_ARGS__)
    

    The priority is mandatory, but is ignored by the macro expansion. The rest of the arguments (the mandatory format plus optional following arguments) are in the __VA_ARGS__ used in the argument list to printf(). This will be OK whether the format string is a constant (literal) or a variable.


    If you want to tag the output as being for the surrogate of syslog(), I’d call a function other than printf() to do the job:

    #define syslog(priority, ...) syslog_print(__VA_ARGS__)
    

    or even

    #define syslog(priority, ...) syslog_print(__FILE__, __LINE__, __func__, __VA_ARGS__)
    

    These would be declared as:

    extern void syslog_printf(const char *fmt, ...);
    

    or:

    extern void syslog_printf(const char *file, int line, const char *func,
                              const char *fmt, ...);
    

    The implementation is a straight-forward application of the macros in <stdarg.h> plus the v*printf() functions:

    void syslog_printf(const char *file, int line, const char *func,
                       const char *fmt, ...)
    {
        va_list args;
        printf("SYSLOG:%s:%d:%s: ", file, line, func);
        va_start(args, fmt);
        vprintf(fmt, args);
        va_end(args);
    }
    

    You can add timestamps and whatever else you like; you can also rather easily arrange for the output to go to a file instead of standard output; you can also arrange for it to be turned on or off inside the function. So, on average, I would replace syslog() with a surrogate that allows you to tune your codes use of the facilities.

    In fact, since you’ve uncovered a requirement to change the behaviour of logging, I would suggest that instead of using syslog() directly in your code, you should use your own function (for example, the syslog_printf(), but possibly under a different name) in your code, and have various implementations of that function available to you. The only downside to doing so is that calling the real syslog() is now harder — there isn’t a vsyslog() AFAIK. So, the basic call to syslog() would be done by formatting the string in syslog_printf() using vsnprintf() (or vasprintf() if that’s available to you and memory exhaustion isn’t a likely problem), and then calling syslog() with the preformatted string (syslog(priority, "%s", buffer);). Of course, you’d also want the priority passed to the surrogate function for relay to syslog().

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

Sidebar

Related Questions

I have an application running on Linux, catching signals and reporting them to syslog.
I have a java application running on production servers (all linux OS). I want
I have application running for hours in embedded Linux, when suddenly the OOM Killer
I have done strace on my multi-threaded c++ application running on linux after couple
I have created a java application for Debian Linux. Now I want that that
I have J2SE application running in linux. I have stop application script in which
We have Glassfish application server running in Linux servers. Each Glassfish installation hosts 3
I have an application running in cluster mode (two nodes) under tomcat/Linux. Unfortunately I've
I have a java application running on Linux system. Currently we are facing some
I have an existing Java web application running on Linux using embedded Jetty. The

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.