On Thu, Nov 12, 2009 at 1:25 PM, <[email protected]> wrote: > On Thu, 12 Nov 2009, Lukasz Szybalski wrote: > >>>>>>> >>>>>>> >>>>>>> Here is a sample test case....in python. >>>>>>> Save below to a file and run it. >>>>>>> python testfile.py >>>>>>> >>>>>>> >>>>>>> #----testfile.py----- >>>>>>> from logging.handlers import SysLogHandler >>>>>>> >>>>>>> import logging >>>>>>> >>>>>>> >>>>>>> # create logger >>>>>>> logger = logging.getLogger("myapp") >>>>>>> logger.setLevel(logging.DEBUG) >>>>>>> ch = SysLogHandler('/dev/log') >>>>>>> ch.setLevel(logging.DEBUG) >>>>>>> # create formatter >>>>>>> formatter = logging.Formatter("%(asctime)s - %(name)s- >>>> %(levelname)s - >>>>>>> %(message)s") >>>>>>> # add formatter to ch >>>>>>> ch.setFormatter(formatter) >>>>>>> logger.addHandler(ch) >>>>>>> logger.info('This is a message') >>>>>>> >>>>>>> >>>>>>> How can I setup rsyslog to filter "myapp" and save the messages to >> >> 1. >> So in my code I've defined a formatter to be: >> formatter = logging.Formatter("%(asctime)s - %(name)s- %(levelname)s - >> %(message)s") >> >> I don't care how it looks as long as it has a date, time, name of the >> app, level, and message. Is there a standard formatting I should be >> using? I don't want to create a custom solution if I can use standard >> one? > > the format over the wire should be > > <priority> date server tag message > > if the message does not have this format, rsyslog will add a priority, > date and server to the message > > in addition, the date you are setting is not formatted appropriately > > the date should be > > MMM DD HH:MM:SS > > I am not familiar enough with the logger package in python to tell you how > to format it this way. > > however, based on the message that you sent earlier, if you set your > format to be > > formatter = logging.Formatter("%(name)s %(message)s")
This works.... nice... > > it may be close enough to the correct thing to work. > >> 2. What about saving the file with todays date. I don't want to rotate >> the logs, but I want to have a file for each day saved in >> /home/lucas/$year$month$date.txt >> Above does not work, unless I'm missing some escape characters/parentheses? > > look in the section on dynafiles. I have not used this feature, so I can't > help directly. Now I just have to find the proper syntax to get the file to save to :syslogtag, contains, "myapp" /home/lucas/20091112.txt to /home/lucas/$year$month$date.txt Lucas _______________________________________________ rsyslog mailing list http://lists.adiscon.net/mailman/listinfo/rsyslog http://www.rsyslog.com

