- Package:
- liblog4cpp5
- Source:
- log4cpp
- Submitter:
- Daniel Pocock
- Date:
- 2023-04-17 12:12:33 UTC
- Severity:
- normal
I used the examples that I found online to instantiate
RemoteSyslogHandler and BasicLayout
I observed that the UDP messages sent to the Syslog host don't include
the Syslog header information in either the RFC-3164 or RFC-5424 formats.
I was able to workaround this by manually adding the header information
in a PatternLayout (see below)
As this header information is mandatory for the Syslog protocol, it
should probably be implemented in RemoteSyslogHandler.cpp
log4cpp::Appender *appender1 =
new log4cpp::RemoteSyslogAppender("default", argv[0], "log-host");
// Configure pattern for log messages
bool useRfc5424 = true;
std::stringstream logpattern;
const char* progname = rindex(argv[0], '/');
if(progname == 0) {
progname = argv[0];
} else {
progname++;
}
if(useRfc5424) {
// create a Syslog RFC-5424 compliant layout for log strings
char _hostname[512];
if(gethostname(_hostname, 510) < 0) {
strcpy(_hostname, "unknown-hostname");
}
logpattern << "%d{%Y-%m-%dT%H:%M:%SZ} "
<< _hostname << " " << progname << " " << getpid()
<< " - - %m";
} else {
// create a Syslog RFC-3164 compliant layout for log strings
logpattern << progname << '[' << getpid() << "]: %m";
}
log4cpp::PatternLayout *pl = new log4cpp::PatternLayout();
pl->setConversionPattern(logpattern.str());
appender1->setLayout(pl);
RFC-5424 also adds a version[1] code, which is "1" for RFC-5424 and may
be incremented in future versions of the SysLog spec. This should have
been included in my previous code sample. It involves amending the
pattern line like this:
logpattern << "1 %d{%Y-%m-%dT%H:%M:%SZ} "
<< _hostname << " " << progname << " " << getpid()
<< " - - %m";
The log4cplus project (also packaged[2]) states in the API docs that it
supports 5424 natively[3]
The fully revised sample:
log4cpp::Appender *appender1 =
new log4cpp::RemoteSyslogAppender("default", argv[0], "log-host");
// Configure pattern for log messages
bool useRfc5424 = true;
std::stringstream logpattern;
const char* progname = rindex(argv[0], '/');
if(progname == 0) {
progname = argv[0];
} else {
progname++;
}
if(useRfc5424) {
// create a Syslog RFC-5424 compliant layout for log strings
char _hostname[512];
if(gethostname(_hostname, 510) < 0) {
strcpy(_hostname, "unknown-hostname");
}
logpattern << "1 %d{%Y-%m-%dT%H:%M:%SZ} "
<< _hostname << " " << progname << " " << getpid()
<< " - - %m";
} else {
// create a Syslog RFC-3164 compliant layout for log strings
logpattern << progname << '[' << getpid() << "]: %m";
}
log4cpp::PatternLayout *pl = new log4cpp::PatternLayout();
pl->setConversionPattern(logpattern.str());
appender1->setLayout(pl);
1. https://tools.ietf.org/html/rfc5424#section-6.2.2
2. https://packages.qa.debian.org/l/log4cplus.html
3.
http://log4cplus.sourceforge.net/docs/html/classlog4cplus_1_1SysLogAppender.html
Laba diena, Noriu Jus informuoti apie šių metų pasikeitimą dėl atnaujintos visos Lietuvos įmonių bazės 2018 metų sausio vidurio. Visi juridiniai asmenys pateikti bazėje yra veikiantys, realiai vykdantys veiklą, turintys įdarbintų darbuotojų. Duomenys pagal Sodrą, Registrų centrą. Bazėje nurodoma ir apyvarta, darbuotojų atlyginimai, darbuotojų skaičius, transporto skaičius ir daug kitų duomenų, kuriuos matysite pavyzdyje. Duomenis galima filtruoti pagal veiklas, miestus ir kitus duomenis. Šią bazę verta turėti visoms įmonėms. Pateiksiu priežastis: 1) Kontaktai pateikti bazėje direktorių ir kitų atsakingų asmenų, didelė tikimybė Jums surasti naujų klientų, partnerių, tiekėjų, kai tiesiogiai bendrausite su direktoriais, komercijos vadovais. 2) Konkurentų analizavimas, tiekėjų atsirinkimas pagal Jums reikalingus kriterijus, galite atsifiltruoti pagal įmonės dydį, bazėje nurodoma kiek įmonės skolingos Sodrai. 3) Lengva, greita ir patogu dirbti su šia baze, elektroninius pašto adresus galite importuoti į elektroninių laiškų siuntimo programas ar sistemas iš kurių siunčiate elektroninius laiškus. Taip pat galite importuoti mobiliųjų telefonų numerius į SMS siuntimo programas. Išsirinkite iš "Veiklų sąrašo" veiklas kurių Jums reikia. ( Sąrašas prisegtas laiške excel faile ) Parašykite, kurias veiklas išsirinkote ir atsiųsime pavyzdį ir pasiūlymą su sąlygomis įmonių bazei įsigyti Pagarbiai, Tadas Giedraitis Tel. nr. +37067881041