How redirect syslog message to a specified file?


 
Thread Tools Search this Thread
Operating Systems Linux Ubuntu How redirect syslog message to a specified file?
# 1  
Old 06-18-2015
How redirect syslog message to a specified file?

Hello to everyone! I have a question about syslog.
I want put the messages of log in a particular file
but really i don't know how to do that or i don't get the results
that I want.

I do this:

Code:
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>

int main (void)
{
    openlog("Test",LOG_PID,LOG_USER);
    syslog(LOG_INFO,"LOG!!");
    closelog();
}

And in 50-default.conf I add this line

Code:
if $programname=='Test' then /home/me/var.log

But the file var.log is empty after i ran the program (Obviously I do a rsyslogd restart before run the program).

What is wrong with this?

Bye!
# 2  
Old 06-18-2015
have you tried putting a space on either end of ==?
Code:
if $programname == 'Test' then /home/me/var.log

# 3  
Old 06-18-2015
No Smilie still not working.

The file that I modified is /etc/rsyslog.d/50-default.conf

It is right?

Thank you

Last edited by rbatte1; 06-18-2015 at 06:56 PM..
# 4  
Old 06-18-2015
oh i don't know i don't have a split config. I assume you have $IncludeConfig /etc/rsyslog.d/*.conf in your /etc/rsyslogd.conf? And that you didn't add the rule within another rule?

To be honest I've never used the expression-based scripting of rsyslogd. If a program needs its own separate log file, usually it will handle it on its own rather than use the syslog.
# 5  
Old 06-18-2015
Oh...ok. I only supossed that the correct way is use syslog , cause is a daemon built for that.

Thank you for all.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Generate message in syslog.log

Dear Concern, Is there any command to generate message in /var/adm/syslog/syslog.log file in HP-UX. With Best Regards, Kauser (2 Replies)
Discussion started by: makauser
2 Replies

2. AIX

Message redirected from syslog

Hi. recently in many of our lpars we are getting a message in errpt as "C6ACA566 0315094014 U S dtc MESSAGE REDIRECTED FROM SYSLOG". I have also checked the /etc/syslog.conf file. It doesn't point to error log. Can someone please advise about how to fix this error ? pmut3:/> errpt -aj... (4 Replies)
Discussion started by: newtoaixos
4 Replies

3. Red Hat

Syslog Message

All thanks for the help in advance. I'm current have my syslog server built on RHEL5.7. I'm wondering how to I have the syslog messages categorized by hostname? Is that an option I can add to the syslog.conf? (1 Reply)
Discussion started by: aojmoj
1 Replies

4. UNIX for Dummies Questions & Answers

Syslog Message Columns

Hi all, I need your help with syslog columns. Currently I have a script as follows: (extract) for messages in `cat syslog_message_list.txt`; \ do \ grep $messages syslog.`date +%d%m%y`.log | \ tr -s " " | \ cut -d" " -f4,9- | \ sort -k3.2,3 -k2,2 -k1nr,1 | \ uniq -c | \ sort -k3.2,3... (6 Replies)
Discussion started by: wthomas
6 Replies

5. UNIX for Advanced & Expert Users

Q on <user> of syslog message generated by logger command

Generally(at least on AIX5.3, Solaris9, OS X)'logger' command would create syslog messages which carry <login name> . On Solaris9, I have experienced two circumstances in which 'logname' command fails. In this circumstance I saw the 'logger' command generated syslog messages which carry... (0 Replies)
Discussion started by: masaki
0 Replies

6. AIX

Syslog - Message forwarded from

I am not a Unix / AIX admin, but am working with one that doesn't seem to know how to set up syslog to forward messages to me the way I need them. Every message they send me has "Message forwarded from <insert host name here>:" but I need it to only have the host name. In the examples below,... (2 Replies)
Discussion started by: mlbillow
2 Replies

7. Programming

why I can't get syslog message?

I read Unix network programming by richard,in chap12.3,it say if call syslog() by using parameter LOG_USER,it should write a message in /var/adm/messages in Solaris,such as "connected from 10.1.1.2",example file inet/daytimetcpsrv2.c.I want to know which syslog file in FreeBSD7.0?I look for... (1 Reply)
Discussion started by: konvalo
1 Replies

8. HP-UX

How to Redirect the error messages from Syslog file to our own Application Log File

Hello, I am New to Unix. I am Using HP-UX 9000 Series for my Application. I am Currently Facing an Issue that the error messages are being written in the syslog file instead of the Application Log File. The Codes for that Syslog.h is written in Pro*C. I want to know how to Redirect these... (3 Replies)
Discussion started by: balasubramaniam
3 Replies

9. Solaris

syslog message..!

I got my system sun fire 6800 hung later reboot after generating these message can any one help me on this to review these message..!! nfssrv: WARNING: nfsauth upcall failed: RPC: Operation in progress mountd: cannot accept connection: 19: error unknown (current state -1) KAVE00166-W The... (13 Replies)
Discussion started by: nicknihal
13 Replies

10. Programming

How to redirect error message?

Hi, I was trying to cat some files but not all of them exist. I would get some messages like below: cat: cannot open /mil2_usr1/time_logs/investigator/6334 cat: cannot open /mil3_usr1/time_logs/investigator/6334 cat: cannot open /mil3_usr1/time_logs/investigator/6352 I don't want to see... (1 Reply)
Discussion started by: whatisthis
1 Replies
Login or Register to Ask a Question