Solved

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

Posted on 2011-02-15
4
663 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I use more than 1 computer in my office for various reasons. Multiple keyboards and mice take up more than just extra space, they make working a little more complicated. Using one mouse and keyboard for all of my computers makes life easier. This co…
In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.

705 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

19 Experts available now in Live!

Get 1:1 Help Now