Wowza Community

How to make getLogger() log to a specific file?

Also, I have a module that has only one line of getLogger.

This getLogger is a info().

I would like to log ONLY this piece to my new file.

There are others thread about this subject but they got no answers.

Hi maugzoide , do you want to record all the getLogger’s info methods input to a file ? Do you develop a custom module or ask for configuration ?

Connection counts , active streams , published streams can be handled with custom modules .

Here is an example of logging connection info to C:/file.txt .

package com.letheasoftware.tutorial;

import java.io.BufferedWriter;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

import com.wowza.wms.application.*;

import com.wowza.wms.amf.*;

import com.wowza.wms.client.*;

import com.wowza.wms.module.*;

import com.wowza.wms.request.*;

import com.wowza.wms.stream.*;

import com.wowza.wms.rtp.model.*;

import com.wowza.wms.httpstreamer.model.*;

import com.wowza.wms.httpstreamer.cupertinostreaming.httpstreamer.*;

import com.wowza.wms.httpstreamer.smoothstreaming.httpstreamer.*;

public class HelloWowza extends ModuleBase {

private IApplicationInstance appInstance = null;

public void doSomething(IClient client, RequestFunction function,

AMFDataList params) {

getLogger().info(“doSomething”);

sendResult(client, params, “Hello Wowza”);

}

public void onAppStart(IApplicationInstance appInstance) {

String fullname = appInstance.getApplication().getName() + “/”

  • appInstance.getName();

getLogger().info("onAppStart: " + fullname);

getLogger().info("letheasoftware.com \n " + fullname);

this.appInstance = appInstance;

}

public void onAppStop(IApplicationInstance appInstance) {

String fullname = appInstance.getApplication().getName() + “/”

  • appInstance.getName();

getLogger().info("onAppStop: " + fullname);

}

public void onConnect(IClient client, RequestFunction function,

AMFDataList params) {

getLogger().info("this is working noww " + client.getClientId());

MediaStreamMap streams = appInstance.getStreams();

List streamNames = streams.getPublishStreamNames();

Map<String, Integer> flashCounts = appInstance.getPlayStreamCountsByName();

Map<String, Integer> smoothCounts = appInstance.getHTTPStreamerSessionCountsByName(IHTTPStreamerSession.SESSIONPROTOCOL_SMOOTHSTREAMING);

Map<String, Integer> cupertinoCounts = appInstance.getHTTPStreamerSessionCountsByName(IHTTPStreamerSession.SESSIONPROTOCOL_CUPERTINOSTREAMING);

Map<String, Integer> rtspCounts = appInstance.getRTPSessionCountsByName();

Iterator iter = streamNames.iterator();

StringBuffer metaDataStr = new StringBuffer();

while(iter.hasNext())

{

String streamName = iter.next();

IMediaStream stream = streams.getStream(streamName);

if (stream == null)

continue;

IMediaStreamMetaDataProvider metaDataProvider = stream.getMetaDataProvider();

List metaData = new ArrayList();

metaDataProvider.onStreamStart(metaData, 0);

int rtmpCount = toCount(flashCounts.get(streamName));

int cupertinoCount = toCount(cupertinoCounts.get(streamName));

int smoothCount = toCount(smoothCounts.get(streamName));

int rtspCount = toCount(rtspCounts.get(streamName));

int count = rtmpCount+cupertinoCount+smoothCount+rtspCount; //listeners.size();

metaDataStr.append(“viewers”+": “”+count+""");

metaDataStr.append(", viewersRTMP"+": “”+rtmpCount+""");

metaDataStr.append(", viewersCupertino"+": “”+cupertinoCount+""");

metaDataStr.append(", viewersSmooth"+": “”+smoothCount+""");

metaDataStr.append(", viewersRTSP"+": “”+rtspCount+""");

Map<String, String> metaList = getMetadataInfo(stream);

Iterator iter2 = metaList.keySet().iterator();

while(iter2.hasNext())

{

String key = iter2.next();

String value = metaList.get(key);

metaDataStr.append(", “+key+”: “”+value+""");

}

getLogger().info(“here we go”);

String metaDataStrStr = metaDataStr.toString().replace("\n", “”);

}

try {

BufferedWriter out = new BufferedWriter(new FileWriter(“c:/file.txt”));

out.write(metaDataStr.toString());

out.close();

} catch (IOException e) {}

}

private Map<String, String> getMetadataInfo(IMediaStream stream)

{

Map<String, String> ret = new HashMap<String, String>();

try

{

IMediaStreamMetaDataProvider metaDataProvider = stream.getMetaDataProvider();

while (true)

{

if (metaDataProvider == null)

break;

List metaDataList = new ArrayList();

long firstTimecode = 0;

AMFPacket packet = stream.getLastPacket();

firstTimecode = packet==null?0:packet.getAbsTimecode();

metaDataProvider.onStreamStart(metaDataList, firstTimecode);

if (metaDataList.size() <= 0)

break;

for(int i=0;i<metaDataList.size();i++)

{

AMFPacket metaPacket = (AMFPacket)metaDataList.get(i);

AMFDataList dataList = new AMFDataList(metaPacket.getData());

if (dataList.size() < 2)

break;

if (dataList.get(1).getType() == AMFData.DATA_TYPE_MIXED_ARRAY)

{

AMFDataMixedArray arr = (AMFDataMixedArray)dataList.get(1);

Iterator iter = arr.getKeys().iterator();

while(iter.hasNext())

{

String key = iter.next();

String value = arr.getString(key);

if (value == null)

continue;

ret.put(key, value);

}

}

else if (dataList.get(1).getType() == AMFData.DATA_TYPE_OBJECT)

{

AMFDataObj obj = (AMFDataObj)dataList.get(1);

Iterator iter = obj.getKeys().iterator();

while(iter.hasNext())

{

String key = iter.next();

String value = obj.getString(key);

if (value == null)

continue;

ret.put(key, value);

}

}

}

break;

}

}

catch (Exception e)

{

}

return ret;

}

public void onConnectAccept(IClient client) {

getLogger().info("onConnectAccept: " + client.getClientId());

}

public void onConnectReject(IClient client) {

getLogger().info("onConnectReject: " + client.getClientId());

}

public void onDisconnect(IClient client) {

getLogger().info("onDisconnect: " + client.getClientId());

}

private int toCount(Integer intObj)

{

int ret = intObj==null?0:intObj.intValue();

return ret;

}

}

Regards,

Emre Karataşoğlu

Hi,

Please see this thread

You will need to go through the example provided to implement for your environment.

Andrew.

Thanks for the answer.

I am developing a custom module.

Sorry, I forgot to mention that I would like to use log4j to rotate my logs.

The way the above snippet acts does not use log4j so I would manually rotate it (a thing that I don’t want to).