Results 1 to 4 of 4

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

  1. #1
    Join Date
    Sep 2014
    Posts
    23

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

  2. #2

    Default

    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<String> 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_CUPERTINOSTREAMI NG);
    Map<String, Integer> rtspCounts = appInstance.getRTPSessionCountsByName();

    Iterator<String> 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<AMFPacket> metaData = new ArrayList<AMFPacket>();
    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<String> 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?0acket.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<String> 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<String> 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

  3. #3
    Join Date
    Sep 2014
    Posts
    23

    Default

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

  4. #4

    Default

    Hi,

    Please see this thread

    http://www.wowza.com/forums/showthre...different-file

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

    Andrew.

Similar Threads

  1. getLogger().info and System.out.print into a log file
    By chocking_u in forum Live Streaming and Encoder Discussion
    Replies: 1
    Last Post: 11-07-2013, 06:39 AM
  2. Logger to file getLogger().info("MESSAGE")
    By MARY2006 in forum Server Administration Discussion
    Replies: 0
    Last Post: 04-19-2013, 12:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •