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

**URL:** <https://community.wowza.com/t/how-to-make-getlogger-log-to-a-specific-file/43816>\
**Category:** Wowza Streaming Engine\
**Created:** [September 25, 2014, 12:37pm UTC](https://community.wowza.com/t/how-to-make-getlogger-log-to-a-specific-file/43816 "2014-09-25T12:37:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mauricio\_Antunes](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@Mauricio\_Antunes](https://community.wowza.com/u/Mauricio_Antunes)\
**Post date:** [September 25, 2014, 12:37pm UTC](https://community.wowza.com/t/how-to-make-getlogger-log-to-a-specific-file/43816/1 "2014-09-25T12:37:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Emre\_Karatasoglu\_Adv](https://avatars.discourse-cdn.com/v4/letter/e/0ea827/32.png) [@Emre\_Karatasoglu\_Adv](https://community.wowza.com/u/Emre_Karatasoglu_Adv)\
**Post date:** [September 25, 2014, 10:30pm UTC](https://community.wowza.com/t/how-to-make-getlogger-log-to-a-specific-file/43816/2 "2014-09-25T22:30:39Z")

</div>

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](http://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](https://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

---

<div class="post-metadata">

**Author:** ![Andrew\_Kennedy1](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@Andrew\_Kennedy1](https://community.wowza.com/u/Andrew_Kennedy1)\
**Post date:** [September 26, 2014, 12:27am UTC](https://community.wowza.com/t/how-to-make-getlogger-log-to-a-specific-file/43816/3 "2014-09-26T00:27:11Z")

</div>

Hi,

Please see this thread

> [@Logging custom module to a different file](http://community.wowza.com/t/-/43813):
>
> Is there any way to log (getLogger) to a different file? Wowza logs every information inside access.log. I would like to log my custom module to a different file.

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

Andrew.

---

<div class="post-metadata">

**Author:** ![Mauricio\_Antunes](https://avatars.discourse-cdn.com/v4/letter/m/5daacb/32.png) [@Mauricio\_Antunes](https://community.wowza.com/u/Mauricio_Antunes)\
**Post date:** [September 25, 2014, 6:44pm UTC](https://community.wowza.com/t/how-to-make-getlogger-log-to-a-specific-file/43816/4 "2014-09-25T18:44:27Z")

</div>

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).
