Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8393549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:49:11+00:00 2026-06-09T19:49:11+00:00

There is a script, written in Python, which parse sensors data and events from

  • 0

There is a script, written in Python, which parse sensors data and events from number of servers by IPMI. Then it sends graph data to one server and error logs to the other. Logging server is Syslog-ng+Mysql

So the task is to store logs by owner, but not by script host.

Some code example:

import logging
import logging.handlers

loggerCent = logging.getLogger(prodName + 'Remote')
ce = logging.handlers.SysLogHandler(address=('192.168.1.11', 514), facility='daemon')
formatter = logging.Formatter('%(name)s: %(levelname)s: %(message)s')
loggerCent.setLevel(logging.INFO)

loggerCent.addHandler(ce)

loggerCent.warning('TEST MSG')

So I need to extend the code so I could tell to syslog-ng, that the log belongs to the other host. Or some other desigion.

Any ideas?

UPD:

So it looks like there is the way to use LogAdapter. But how can use it:

loggerCent = logging.getLogger(prodName + 'Remote')
ce = logging.handlers.SysLogHandler(address=('192.168.1.11', 514), facility='daemon')
logging.basicConfig(level=logging.DEBUG,
                        format='%(asctime)-15s %(name)-5s %(levelname)-8s host: %(host)-15s %(message)s')
loggerCent.addHandler(ce)
loggerCent2 = logging.LoggerAdapter(loggerCent,
                               {'host': '123.231.231.123'})
loggerCent2.warning('TEST MSG')

Looking for the message through TcpDump I see nothing about host in LoggerAdapter
What am I doing wrong?

UPD2:

Well, I did’t find the way to send host to syslog-ng. Though it is possible to send first host in chain, but I really can’t find the way to sent it through Python Logging.

Anyway, I made parser in syslog-ng:
CSV Parser

parser ipmimon_log {
        csv-parser(
    columns("LEVEL", "UNIT", "MESSAGE")
    flags(escape-double-char,strip-whitespace)
        delimiters(";")
        quote-pairs('""[](){}')
    );
};

log {
    source(s_net);
    parser(ipmimon_log);
    destination(d_mysql_ipmimon);
};

log {
    source(s_net);
    destination(d_mysql_norm);
    flags(fallback);
};

Then I send logs to the syslog-ng delimited by ;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:49:13+00:00Added an answer on June 9, 2026 at 7:49 pm

    edit-rewrite

    You are missing the critical step of actually adding your Formatter to your Handler. Try:

    loggerCent = logging.getLogger(prodName + 'Remote')
    loggerCent.setLevel(logging.DEBUG)
    ce = logging.handlers.SysLogHandler(address=('192.168.1.11', 514), facility='daemon')
    formatter = logging.Formatter('%(host)s;%(message)s')
    ce.setFormatter(formatter)
    loggerCent.addHandler(ce)
    loggerCent2 = logging.LoggerAdapter(loggerCent, {'host': '123.231.231.123'})
    loggerCent2.warning('TEST MSG')
    

    Note that you won’t be running basicConfig any more, so you will be responsible for attaching a Handler and setting a log level for the root logger yourself (or you will get ‘no handler’ errors).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a script that gets data from solr for which date is
The background: I've written a python script to inspect IP packets, specifically the payload/data
I've written a python script that adds student data (name and classes) to a
I have written a Perl script for the following bioinformatics question, but unfortunately there
I've written a bash script on Cygwin which is rather like rsync , although
I've written a small python script to create a file and calculate times. I've
I have some code written in Python which can not be transferred to a
I have an installation script written in Python (in Linux) that runs as root
I have written a Python script that currently is designed to handle traditional CGI
I've written a Python script that uses a package that I've created. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.