Wowza Community

Create Custom Log and Write to it from Custom Module

This topic has been bounced around, but to me does not seem like its been fully answered. I want to be able to create a custom log (which I have done by modifying the log4j.properties file), and write to this log from my custom module (which I have already created) with specific programmatic values by doing a getLogger().MyLog(obj) or the equivalent? I need to be able to write to that specific log from my module. Can this be done? Is it done by adding additional JMXOptions in the /bin/startup.bat? But from there it does not appear to allow me to write to the log file, rather just collect the values that were defined in the custom class? I guess I could try to create all my variables in that class as well and log them there, seems very disconnected not being able to access the log via the custom module?

Hi @Rich Sokol, I have this from one of our top engineers- let me know if it helps you out:

public class MyOwnLogger

{

private DailyRollingFileAppender appender = null;   

 private Logger logger = null;   

 public MyOwnLogger(String LogBaseLocation)

{

logger = WMSLogger.getLogger("myownlog");  

String pattern = "%d{ISO8601} %m%n"; 

PatternLayout layout = new PatternLayout(pattern); 

appender = new DailyRollingFileAppender();        

appender.setAppend(true);        

appender.setLayout(layout);        

appender.setFile(LogBaseLocation + "/logs/myownlog.log");        

appender.activateOptions();

logger.addAppender(appender);        

logger.setLevel((Level)Level.INFO);

  }

public void logMessage(String Message)

{

this.logger.info("MyPrefixtoMyLog :" + Message + "'");
}

public void close()

{

this.appender.close();        

this.logger.removeAppender("myownlog");

}
}

Step 2. Then you can do:

String baseLocation = Bootstrap.getServerHome(Bootstrap.CONFIGHOME);
MyOwnLoggerlog = new MyOwnLogger(baseLocation);

Now you can do
log.logMessage(“Hello there”);

You should find a file in your logs/ folder call myownlog.log, with an entry of the following
2010-09-10 21:13:00,891 MyPrefixtoMyLog: ‘Hello There’
It is configured to the daily rotation so the filename will change to
myownlog.log.2019-09-10
when tomorrow comes along and you write to the file.
When you are finished remember to call log.close

Please ignore the numbers to the left in the code above! This code would not paste correctly into the forum layout. Copy the code, but not the numbers in the left margin .Thanks.

WOW, WOW, WOW, FANTASTIC!!! Took me 10 minutes to port this class into my solution and it worked almost perfectly first shot!!! Thank you very much @Rose Power-Wowza Community Manager

So, how might one adapt this in order to allow the log file details to be configured within log4j.properties versus being hard coded into the MyOwnLogger class?

PS- I know this thread is old; I came across it while researching a similar need.

Most of the information can be found here:https://www.wowza.com/docs/use-wowza-streaming-engine-java-modules. We use Eclipse with the WSE plug-in. You create a new module, which pre-populates a bunch of events in the module. What we did, was once we got everything to compile and deployed it to our Dev instance, we started logging different things to test values and see what we wanted to capture. Remember you have to add it to your modules list in your respective application via WSE Manager, and restart the services to make sure you get your latest and greatest version of your module.