Sponsored Content
Operating Systems Linux Ubuntu How redirect syslog message to a specified file? Post 302947530 by Kovalevski on Thursday 18th of June 2015 01:48:37 PM
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!
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
SYSLOG(3)						     Library Functions Manual							 SYSLOG(3)

NAME
syslog , vsyslog , openlog , closelog , setlogmask - control system log SYNOPSIS
#include <syslog.h> #include <varargs.h> void syslog(priority, message, ...); int priority; char *message; void vsyslog(priority, message, args); int priority; char *message; va_list args; void openlog(ident, logopt, facility); char *ident; int logopt; int facility; void closelog(); int setlogmask(maskpri); int maskpri; DESCRIPTION
The syslog() function writes message to the system message logger. The message is then written to the system console, log files, logged-in users, or forwarded to other machines as appropriate. (See syslogd(8)). The message is identical to a printf(3) format string, except that %m is replaced by the current error message as denoted by the global variable errno. See strerror(3)). A trailing newline is added if none is present. The vsyslog() function is an alternate form in which the arguments have already been captured using the variable-length argument facilities of varargs(3). The message is tagged with priority. Priorities are encoded as a facility and a level. The facility describes the part of the system gen- erating the message. The level is selected from the following ordered (high to low) list: LOG_EMERG A panic condition. This is normally broadcast to all users. LOG_ALERT A condition that should be corrected immediately, such as a corrupted system database. LOG_CRIT Critical conditions, e.g., hard device errors. LOG_ERR Errors. LOG_WARNING Warning messages. LOG_NOTICE Conditions that are not error conditions, but should possibly be handled specially. LOG_INFO Informational messages. LOG_DEBUG Messages that contain information normally of use only when debugging a program. The openlog() function provides for more specialized processing of the messages sent by syslog() and vsyslog(). The parameter ident is a string that will be prepended to every message. The logopt argument is a bit field specifying logging options, which is formed by OR'ing one or more of the following values: LOG_CONS If syslog cannot pass the message to syslogd it will attempt to write the message to the console (/dev/console). LOG_NDELAY Open the connection to syslogd immediately. Normally the open is delayed until the first message is logged. Useful for programs that need to manage the order in which file descriptors are allocated. LOG_PERROR Write the message to standard error output as well to the system log. LOG_PID Log the process id with each message: useful for identifying instantiations of daemons. The facility parameter encodes a default facility to be assigned to all messages that do not have an explicit facility encoded: LOG_AUTH The authorization system: login(1), su(1), getty(8), etc. LOG_AUTHPRIV The same as LOG_AUTH , but logged to a file readable only by selected individuals. LOG_CRON The clock daemon. LOG_DAEMON System daemons, such as routed(8), that are not provided for explicitly by other facilities. LOG_KERN Messages generated by the kernel. These cannot be generated by any user processes. LOG_LPR The line printer spooling system: lpr(1), lpc(8), lpd(8), etc. LOG_MAIL The mail system. LOG_NEWS The network news system. LOG_SYSLOG Messages generated internally by syslogd(8). LOG_USER Messages generated by random user processes. This is the default facility identifier if none is specified. LOG_UUCP The uucp system. LOG_LOCAL0 Reserved for local use. Similarly for LOG_LOCAL1 through LOG_LOCAL7. The closelog function can be used to close the log file. The setlogmask function sets the log priority mask to maskpri and returns the previous mask. Calls to syslog with a priority not set in maskpri are rejected. The mask for an individual priority pri is calculated by the macro LOG_MASK(pri). The mask for all priorities up to and including toppri is given by the macro LOG_UPTO(toppri). The default allows all priorities to be logged. RETURN VALUES
The routines closelog(), openlog(), syslog() and vsyslog() return no value. The routine setlogmask() always returns the previous log mask level. EXAMPLES
syslog(LOG_ALERT, "who: internal error 23"); openlog("ftpd", LOG_PID, LOG_DAEMON); setlogmask(LOG_UPTO(LOG_ERR)); syslog(LOG_INFO, "Connection from host %d", CallingHost); syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); SEE ALSO
logger(1), syslogd(8) BUGS
Under 2.11BSD the logfile /usr/adm/messages is used if a non networking kernel has been booted. That file must be publically writeable in this case. HISTORY
These functions appeared in 4.2BSD. 4.2 Berkeley Distribution April 1, 1995 SYSLOG(3)
All times are GMT -4. The time now is 01:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy