Wowza Community

c-ip and c-client-d don't show up in logging

I have a custom module that extends from ModuleBase. When I write logging statements in the ‘onConnect’, on ‘HTTPSessionCreate’ etc, the fields c-ip and c-client-id are not logged.

My log4Jproperties for the console appender looks like this:

# Console appender
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=com.wowza.wms.logging.ECLFPatternLayout
log4j.appender.stdout.layout.Fields=x-severity,x-category,x-event,x-ctx,x-comment, c-ip, c-client-id
log4j.appender.stdout.layout.OutputHeader=false
log4j.appender.stdout.layout.QuoteFields=false
log4j.appender.stdout.layout.Delimeter=space

I added code to put the c-ip and c-client-id in the logging like this:

/**
	 * puts the client id and ip in the global log values to make sure these are logged
	 * @param clientID that is logged in the c-client-id field
	 * @param ip id address that is logged in the c-ip field
	 * @param message that is logged in the comment field
	 */
	private void logMessage(int clientID, String ip, String message) {
		WMSLoggerFactory.putGlobalLogValue(WMSLoggerIDs.FD_c_ip, ip);
		WMSLoggerFactory.putGlobalLogValue(WMSLoggerIDs.FD_c_client_id, new Integer(clientID));
		logger.info(message);
		//now remove the global log values again, otherwise all the log statements use this
		WMSLoggerFactory.removeGlobalLogValue(WMSLoggerIDs.FD_c_ip);
		WMSLoggerFactory.removeGlobalLogValue(WMSLoggerIDs.FD_c_client_id);
	}

In the ‘onConnect’ message I call the logMessage method.

The logging shows this:

INFO server comment - onConnect - -

Note the - - in the logging statement

Does anybody have any clue why the c-ip and c-client-id don’t show up?

Kind regards

Lonneke

Hi Lonneke,

Dose it work without the “removeGlobalLogValue” statements? Perhaps that is the issue.

Use the debugger to ensure your vars have values. You can search the forums for other WMSLoggerFactory examples. You can request a list of independent consultants by sending an email to support@wowza.com.

Not all log fields are populated necessarily, usually some are not

Richard

Ok, good to know your experience level. So, you’re just trying to add clientID and IP to the console output?

You have seen the onLog() function in the API docs, right?

You probably don’t need to use putGlobalLogValue. It’s for creating a new LoggerID type that you can then use in the log4j.properties file. But, c-ip and c-client-id are already existing types.

You have an ILogNotify class etc…?

http://acculive2.tkb.com.tw/commander/wowza/documentation/serverapi/com/wowza/wms/logging/ILogNotify.html

Hi Randall,

Thanks for the quick response :slight_smile: I really appreciate that.

removeGlobalValue is called the log method is called, so this is not the cause of the problem. I removed the statement to make sure, but that has the same result (as expected). Also, in other methods that are generated by the WOWZA IDE when you create your own module, I don’t set the global values nor do I remove them and I have the same problem:

public void onDisconnect(IClient client) {
		logger.info("onDisconnect: " + client.getClientId());
	}

This gives the following result (a ‘-’ for c-ip and c-client-id):

INFO server comment - onDisconnect: 630698332 - -

The vars have values, I debugged and I can see it when I append them to the comment:

/**
	 * puts the client id and ip in the global log values to make sure these are logged
	 * @param clientID that is logged in the c-client-id field
	 * @param ip id address that is logged in the c-ip field
	 * @param message that is logged in the comment field
	 */
	private void logMessage(int clientID, String ip, String message) {
		WMSLoggerFactory.putGlobalLogValue(WMSLoggerIDs.FD_c_ip, ip);
		WMSLoggerFactory.putGlobalLogValue(WMSLoggerIDs.FD_c_client_id, new Integer(clientID));
		logger.info(message + " for clientId: " + clientID + " and ip address: " + ip);
		//now remove the global log values again, otherwise all the log statements use this
		WMSLoggerFactory.removeGlobalLogValue(WMSLoggerIDs.FD_c_ip);
		WMSLoggerFactory.removeGlobalLogValue(WMSLoggerIDs.FD_c_client_id);
	}

It gives the following log result

INFO server comment - onConnect for clientId: 1342221030 and ip address: 127.0.0.1 - -

so the value is visible in the x-comment field, but still not in the c-ip and c-client-id field.

I have searched the forums and examples. One forum post shows the putGlobalValue and removeGlobalValue example.

I am a certified Java Developer, with Java experience since version 1.1.6 and eclipse experience since 2005. So thanks for pointing me to a list of independent consultants (I am a consultant myself :cool: ), but I’d rather get an answer for this problem :).

It seems that for some events (disconnect, create, connect), the c-ip and c-client-id are displayed, but for the ‘on[Method]’ events they are not, even though I put them in the global values.

Any help, or a pointer in the right direction is greatly appreciated

Regards,

Lonneke

I did some more research: it seems that the x-event “comment” is the culprit here.

When I log:

logger.info("some message")

The c-ip and c-client-id (and more fields) are not displayed.

But, when I log:

logger.info(message,WMSLoggerIDs.CAT_session,WMSLoggerIDs.EVT_connect );

The message, the c-ip and the c-client-id do get displayed in the logging:

INFO session connect - Connection accepted for client 1131432791 127.0.0.1 1131432791

Now as a workaround I could put the event types that do display the c-ip and c-client-id, but that means that I have to do that for every log statement.

Is there a way I change the behavior of the ‘comment’ event so it displays the fields I define for it?

Thanks Lonneke

Yes, I looked at that, but it seems I would use that if I need a custom field, right? I want to display standard fields (c-ip, c-client-id), with standard events (x-comment)

Randall,

Thanks for the respone :slight_smile: I think you are right about the putGlovalLogValue, but as you can see in my previous test, the event that seems to occur when logging something with getLogger().info(…), or getLogger.error(…) etc is ‘comment’. So I could put the events in the event list like you suggested, but as long as I don’t set these in the log statement, it won’t do anything I think.

I actually want to log the fields to the access.log, but I am testing it with the console appender right now.

Also, when I look at the WMSLogger.IDs.EVT_ALL array, onConnect etc doesn’t seem to be an event that exists…

event: connect-pending

event: connect

event: connect-burst

event: disconnect

event: publish

event: unpublish

event: play

event: pause

event: unpause

event: seek

event: stop

event: record

event: recordstop

event: server-start

event: server-stop

event: vhost-start

event: vhost-stop

event: app-start

event: app-stop

event: comment

event: setbuffertime

event: create

event: destroy

event: setstreamtype

event: announce

event: describe

event: decoder-audio-start

event: decoder-audio-stop

event: decoder-video-start

event: decoder-video-stop

event: encoder-audio-start

event: encoder-audio-stop

event: encoder-video-start

event: encoder-video-stop

The work around is to log the comments to a ‘random’ event like ‘connect pending’ or something that seems the most relevant for the situation.

The code in the onConnect method will look like this then:

logger.info(message,WMSLoggerIDs.CAT_session,WMSLoggerIDs.EVT_connect_pending);

The biggest disadvantage I see for this method, is that it is harder for the administrator to filter out the comments that are logged by the custom module from the ‘regular’ logging. :frowning:

That’s why I am still looking for a way to either:

  • change the fields that are outputted for the event ‘comment’ or

  • add custom events to the list of events and log these

Any ideas about this?

Lonneke