void osrfLogInit( int type, const char* appname, int maxlevel );
+void osrfLogSetLogTag( const char* logtag );
+
void osrfLogSetSyslogFacility( int facility );
void osrfLogSetSyslogActFacility( int facility );
static char* _osrfLogFile = NULL;
/** Application name. This string will preface every log message. */
static char* _osrfLogAppname = NULL;
+static char* _osrfLogTag = NULL;
/** Maximum message level. Messages of higher levels will be suppressed.
Default: OSRF_LOG_INFO. */
static int _osrfLogLevel = OSRF_LOG_INFO;
- log type (reset to OSRF_LOG_TYPE_STDERR)
*/
void osrfLogCleanup( void ) {
+ if (_osrfLogTag)
+ free(_osrfLogTag);
+ _osrfLogTag = NULL;
free(_osrfLogAppname);
_osrfLogAppname = NULL;
free(_osrfLogFile);
*/
void osrfLogSetAppname( const char* appname ) {
if(!appname) return;
+
+ char buf[256];
+ if(_osrfLogTag) {
+ snprintf(buf, sizeof(buf), "%s/%s", appname, _osrfLogTag);
+ } else {
+ snprintf(buf, sizeof(buf), "%s", appname);
+ }
+
if(_osrfLogAppname) free(_osrfLogAppname);
- _osrfLogAppname = strdup(appname);
+ _osrfLogAppname = strdup(buf);
/* if syslogging, re-open the log with the appname */
if( _osrfLogType == OSRF_LOG_TYPE_SYSLOG) {
}
/**
+ @brief Store an arbitrary program name tag for future use.
+ @param logtag The string to be stored.
+
+ A log tag is a short string that is appended to the appname
+ we log under. This can be used to segregate logs from different
+ users in, for instance, rsyslogd.
+*/
+
+void osrfLogSetLogTag( const char* logtag ) {
+ if (logtag) _osrfLogTag = strdup(logtag);
+}
+
+/**
@brief Store a facility number for future use for activity messages.
@param facility The facility number to be stored.
char* unixpath = osrfConfigGetValue( NULL, "/unixpath" );
char* facility = osrfConfigGetValue( NULL, "/syslog" );
char* actlog = osrfConfigGetValue( NULL, "/actlog" );
+ char* logtag = osrfConfigGetValue( NULL, "/logtag" );
/* if we're a source-client, tell the logger */
char* isclient = osrfConfigGetValue(NULL, "/client");
if(log_level) llevel = atoi(log_level);
if(!strcmp(log_file, "syslog")) {
+ if(logtag) osrfLogSetLogTag(strdup(logtag));
osrfLogInit( OSRF_LOG_TYPE_SYSLOG, contextnode, llevel );
osrfLogSetSyslogFacility(osrfLogFacilityToInt(facility));
if(actlog) osrfLogSetSyslogActFacility(osrfLogFacilityToInt(actlog));
free(unixpath);
free(facility);
free(actlog);
+ free(logtag);
return 0;
}
my $actfac; # activity log syslog facility
my $actfile; # activity log file
my $service = $0; # default service name
+my $service_tag = ''; # default service name
my $syslog_enabled = 0; # is syslog enabled?
my $act_syslog_enabled = 0; # is syslog enabled?
my $logfile_enabled = 1; # are we logging to a file?
$max_log_msg_len = $config->bootstrap->loglength;
}
+ $service_tag = $config->bootstrap->logtag;
+
$logfile = $config->bootstrap->logfile;
if($logfile =~ /^syslog/) {
$syslog_enabled = 1;
sub set_service {
my( $self, $svc ) = @_;
$service = $svc;
+ $service .= '/' . $service_tag if (defined $service_tag);
if( is_syslog() ) {
closelog();
openlog($service, 0, $facility);