Solved

cygwin1.dll - Redirect syslog() calls to file instead of Windows Event Log

Posted on 2011-02-15
4
665 Views
Last Modified: 2013-11-15
Hi there,

I have an app that is built against cygwin, producing an x86 WIN32 executable. This is a console app. However, its default behaviour (presumably because it uses functions in cygwin1.dll) is to send any calls to syslog() under a Windows environment to the Windows Event Log (can be seen in Event Viewer).

Is there a simple way, without changing the source code, say by placing a config file somewhere, that changes this behaviour such that any log information is redirected to a file not the Windows Event log? Or alternatively, sends nothing at all (some /dev/null equivalent)?

Hoping I can avoid removing all such calls and recompiling...

Kind regards,

Xav.
0
Comment
Question by:xavier_da
  • 3
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 34901009
Hi,

I'm not very familiar with Cygwin, but it seems that you need a running syslogd to capture the messages to a logfile.

As far as I know there is a syslogd in inetutils
http://sourceware.org/cygwin/packages/inetutils/ (package list)


and a syslog-ng implementation is also available:
http://sourceware.org/cygwin/packages/syslog-ng/ (package list)

Both packages should contain READMEs to give you a start.

wmp



0
 

Author Comment

by:xavier_da
ID: 34903135
Hi woolmilkporc,

Thanks for your response. However, this is a standalone executable built using Cygwin - I have no actual Cygwin environment installed.

My understanding is that the cygwin1.dll provides a layer to abstract services and features typical of a Unix environment, such that calls to normal functions (such as syslog()) are portable, and can run under Windows. In this case, code that under a Unix environment would cause a message to be sent to the syslog daemon is passed onto the Windows equivalent (Event Viewer).

Is there a cygwin1.dll file with different logging functionality? I'd be happy to remove any logging, yet keep the calls in there, so it essentially calls a stub function of some kind.

I assume the Windows implementation of the syslog() function call does some checks to see how to send messages. Maybe it checks for the presence of a file in the same directory as the calling application (with cygwin1.dll), a text file that alters the logging behaviour?

Or failing that, is the only way to do what I want to:
a) alter the cygwin1.dll to exclude syslog()
b) add conditional code and a command line option to NOT send any messages.
c) ???

What other alternatives are there?

Regards,

Xav.
0
 

Accepted Solution

by:
xavier_da earned 0 total points
ID: 34977158
Okay,

As mentioned, any call to syslog() in a Cygwin app gets shunted to the Windows event log in the absence of a syslog daemon. To suppress these messages, I made a simple alteration to the source code, using setlogmask():

setlogmask ( ~(LOG_MASK(LOG_INFO) | LOG_MASK(LOG_ERR)) );
openlog("app", LOG_CONS, LOG_DAEMON);

Open in new window


In this case, the LOG_MASK macro is used with the complement operator to suppress INFO and ERR event messages.

Downside is that I cannot see any messages dumped to the console, but I wanted silent operation anyway.

Just made the above change and recompiled using Cygwin. No more messages appear!

Kind regards,

Xav.
0
 

Author Closing Comment

by:xavier_da
ID: 35005382
Solution found independently of wider EE community; meets original goal.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

If your app took Google’s lash recently, here are the 5 most likely reasons.
The article will include the best Data Recovery Tools along with their Features, Capabilities, and their Download Links. Hope you’ll enjoy it and will choose the one as required by you.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

919 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

13 Experts available now in Live!

Get 1:1 Help Now