Skip to content

Commit 3dbfdbc

Browse files
committed
added config file for infoLogger clients
1 parent 3ddeca9 commit 3dbfdbc

5 files changed

Lines changed: 65 additions & 12 deletions

File tree

doc/README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,10 @@ The InfoLogger library allows to inject messages directly from programs, as show
237237
## Configuration
238238
239239
* Description and example of parameters for each InfoLogger component can be found in /opt/o2-InfoLogger/etc/*.cfg.
240-
The parameters can usually be mixed in a single configuration file, as they are grouped in sections ([infoLoggerServer], [infoLoggerD], [infoBrowser], ...).
240+
The parameters can usually be mixed in a single configuration file, as they are grouped in sections ([infoLoggerServer], [infoLoggerD], [infoBrowser], [client] ...).
241+
242+
* Path to configuration file can be defined as startup parameter for the infoLoggerServer and infoLoggerD daemons. Processes using the client library can also be
243+
configured by defining the INFOLOGGER_CONFIG environment variable, pointing to the selected config file. The path should be in the form: "file:/etc/infoLogger.cfg"
241244
242245
* On multiple-hosts systems, the serverHost configuration key should be set for infoLoggerD and infoBrowser, so that they are able to connect infoLoggerServer
243246
if not running locally.
@@ -265,3 +268,12 @@ achieved on CentOS 7 with e.g. (as root):
265268
During development phase, it can be useful to set mode to "stdout", to allow using the infoLogger interface
266269
and printing messages without infoLoggerD/infoLoggerServer.
267270
When "infoLoggerD" mode is selected and no infoLoggerD connection can be established, the mode falls back to "stdout".
271+
272+
* infoLoggerD local socket
273+
274+
The connection between a client process using infoLogger API and the local infoLoggerD is done through a UNIX named socket.
275+
By default, it uses a Linux abstract socket name.
276+
On systems where such sockets are not available, one can configure it to a named socket associated with the filesystem.
277+
This can be done by specifying in infoLoggerD configuration the rxSocketPath parameter, and name it with a path starting with '/', e.g. '/tmp/infoLoggerD.socket'.
278+
The same value has to be set for the client configuration, in the txSocketPath key.
279+
User is responsible to ensure that file access permissions are configured properly.

infoLoggerClient.cfg

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Example configuration file for infoLogger clients
2+
# i.e. processes using the infoLogger library.
3+
# Lines starting with # are comments
4+
5+
# On standard systems, this is usually not necessary to create this file,
6+
# the default values usually work without need to redefine them
7+
# and the infoLogger clients find their way to infoLoggerD alone.
8+
9+
# When defined, path to this file should usually be provided by setting the environment variable
10+
# INFOLOGGER_CONFIG=file:/etc/infoLogger.cfg
11+
12+
13+
[client]
14+
# see ConfigInfoLoggerClient::ConfigInfoLoggerClient() definition
15+
# for exhaustive list of config parameters accepted
16+
17+
# specify communication channel to infoLoggerD
18+
# it should be the same value as rxSocketPath parameter in infoLoggerD configuration
19+
# defining this value might be needed e.g. on Mac OS, which does not support the default abstract named socket used by infologgerD
20+
#txSocketPath=/tmp/infoLoggerD.socket
21+

src/InfoLoggerClient.cxx

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#include <string.h>
1919

2020
#include <Common/SimpleLog.h>
21+
#include <Common/Configuration.h>
2122

2223
#include "InfoLoggerClient.h"
24+
#include "infoLoggerDefaults.h"
2325

2426

2527

@@ -32,19 +34,35 @@ ConfigInfoLoggerClient::ConfigInfoLoggerClient(const char*configPath) {
3234
// setup default configuration
3335
resetConfig();
3436
// load configuration, if defined
37+
if (configPath==nullptr) {
38+
// when not specified directly, check environment to get path to config file
39+
configPath=getenv(INFOLOGGER_ENV_CONFIG_PATH);
40+
}
3541
if (configPath!=nullptr) {
42+
//printf("Using infoLogger configuration %s\n",configPath);
43+
// get configuration information from file
44+
ConfigFile config;
45+
try {
46+
config.load(configPath);
47+
}
48+
catch(std::string err) {
49+
printf("Error reading configuration file %s : %s",configPath,err.c_str());
50+
return;
51+
}
52+
config.getOptionalValue<std::string>(INFOLOGGER_CONFIG_SECTION_NAME_CLIENT ".txSocketPath", txSocketPath);
53+
config.getOptionalValue<int>(INFOLOGGER_CONFIG_SECTION_NAME_CLIENT ".txSocketOutBufferSize", txSocketOutBufferSize);
54+
config.getOptionalValue<std::string>(INFOLOGGER_CONFIG_SECTION_NAME_CLIENT ".logFile", logFile);
3655
}
3756
}
3857

3958
ConfigInfoLoggerClient::~ConfigInfoLoggerClient(){
40-
// release resources
41-
delete txSocketPath;
4259
}
4360

4461
void ConfigInfoLoggerClient::resetConfig() {
4562
// assign default values to all config parameters
46-
txSocketPath=new std::string("infoLoggerD");
63+
txSocketPath=INFOLOGGER_DEFAULT_LOCAL_SOCKET;
4764
txSocketOutBufferSize=-1;
65+
logFile="/dev/null";
4866
}
4967

5068
//////////////////////////////////////////////////////
@@ -63,12 +81,12 @@ InfoLoggerClient::InfoLoggerClient() {
6381
txSocket=-1;
6482

6583
isInitialized=0;
66-
log.setLogFile("/dev/null");
84+
log.setLogFile(cfg.logFile.c_str());
6785

6886
try {
6987

7088
// create receiving socket for incoming messages
71-
log.info("Creating transmission socket named %s",cfg.txSocketPath->c_str());
89+
log.info("Creating transmission socket named %s",cfg.txSocketPath.c_str());
7290
txSocket=socket(PF_LOCAL,SOCK_STREAM,0);
7391
if (txSocket==-1) {
7492
log.error("Could not create socket: %s",strerror(errno));
@@ -110,17 +128,17 @@ InfoLoggerClient::InfoLoggerClient() {
110128
struct sockaddr_un socketAddrr;
111129
bzero(&socketAddrr, sizeof(socketAddrr));
112130
socketAddrr.sun_family = PF_LOCAL;
113-
if (cfg.txSocketPath->length()+2>sizeof(socketAddrr.sun_path)) {
131+
if (cfg.txSocketPath.length()+2>sizeof(socketAddrr.sun_path)) {
114132
log.error("Socket name too long: max allowed is %d",(int)sizeof(socketAddrr.sun_path)-2);
115133
throw __LINE__;
116134
}
117135
// if name starts with '/', use normal socket name. if not, use an abstract socket name
118136
// this is to allow non-abstract sockets on systems not supporting them.
119-
if (cfg.txSocketPath->c_str()[0]=='/') {
120-
strncpy(&socketAddrr.sun_path[0], cfg.txSocketPath->c_str(), cfg.txSocketPath->length());
137+
if (cfg.txSocketPath.c_str()[0]=='/') {
138+
strncpy(&socketAddrr.sun_path[0], cfg.txSocketPath.c_str(), cfg.txSocketPath.length());
121139
} else {
122140
// leave first char 0, to get abstract socket name - see man 7 unix
123-
strncpy(&socketAddrr.sun_path[1], cfg.txSocketPath->c_str(), cfg.txSocketPath->length());
141+
strncpy(&socketAddrr.sun_path[1], cfg.txSocketPath.c_str(), cfg.txSocketPath.length());
124142
}
125143
if (connect(txSocket, (struct sockaddr *)&socketAddrr, sizeof(socketAddrr))) {
126144
log.error("Failed to connect to infoLoggerD: %s",strerror(errno));

src/InfoLoggerClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ class ConfigInfoLoggerClient {
1111

1212
void resetConfig(); // set default configuration parameters
1313

14-
std::string *txSocketPath; // name of socket used to receive log messages from clients
14+
std::string txSocketPath; // name of socket used to receive log messages from clients
1515
int txSocketOutBufferSize;
16+
std::string logFile; // log file for internal library logs
1617
};
1718

1819

src/infoLoggerDefaults.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#define INFOLOGGER_DEFAULT_CONFIG_PATH "/etc/infoLogger.cfg"
2+
#define INFOLOGGER_ENV_CONFIG_PATH "INFOLOGGER_CONFIG"
23

34
// name of the section where to find parameters
45
#define INFOLOGGER_CONFIG_SECTION_NAME_ADMIN "admin"
56
#define INFOLOGGER_CONFIG_SECTION_NAME_SERVER "infoLoggerServer"
67
#define INFOLOGGER_CONFIG_SECTION_NAME_INFOLOGGERD "infoLoggerD"
8+
#define INFOLOGGER_CONFIG_SECTION_NAME_CLIENT "client"
79

810

911
// Infologger DB: name of the main message table
@@ -15,7 +17,6 @@
1517
// default infoLoggerServer listening port for infoBrowser
1618
#define INFOLOGGER_DEFAULT_SERVER_TX_PORT 6102
1719

18-
1920
// default listening socket name for infoLoggerD
2021
#define INFOLOGGER_DEFAULT_LOCAL_SOCKET "infoLoggerD"
2122

0 commit comments

Comments
 (0)