# Create Custom Log and Write to it from Custom Module

**URL:** https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937
**Category:** Wowza Streaming Engine
**Tags:** wowza-streaming-server-java-api, security, java
**Created:** [September 10, 2019, 5:37pm UTC](https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937 "2019-09-10T17:37:53Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Rich\_Sokol](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@Rich\_Sokol](https://community.wowza.com/u/Rich_Sokol)
#### Post date: [September 10, 2019, 5:37pm UTC](https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937/1 "2019-09-10T17:37:53Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [September 10, 2019, 11:03pm UTC](https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937/2 "2019-09-10T23:03:12Z")

</div>

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

```auto
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");

}
}

```

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [September 10, 2019, 11:05pm UTC](https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937/3 "2019-09-10T23:05:22Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Rose\_Power-Wowza\_Com](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/rose_power-wowza_com/32/431_2.png) [@Rose\_Power-Wowza\_Com](https://community.wowza.com/u/Rose_Power-Wowza_Com)
#### Post date: [September 10, 2019, 11:08pm UTC](https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937/4 "2019-09-10T23:08:32Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Rich\_Sokol](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@Rich\_Sokol](https://community.wowza.com/u/Rich_Sokol)
#### Post date: [September 12, 2019, 4:58pm UTC](https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937/5 "2019-09-12T16:58:44Z")

</div>

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

---

<div class="post-metadata">

### Author: ![aries](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@aries](https://community.wowza.com/u/aries)
#### Post date: [August 30, 2021, 5:34am UTC](https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937/6 "2021-08-30T05:34:36Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Rich\_Sokol](https://avatars.discourse-cdn.com/v4/letter/r/d78d45/32.png) [@Rich\_Sokol](https://community.wowza.com/u/Rich_Sokol)
#### Post date: [August 30, 2021, 4:11pm UTC](https://community.wowza.com/t/create-custom-log-and-write-to-it-from-custom-module/53937/7 "2021-08-30T16:11:11Z")

</div>

Most of the information can be found here:[https://www.wowza.com/docs/use-wowza-streaming-engine-java-modules](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.
