Overview

Logging is the process of printing out run-time information to the console or to a file. In the context of Red5 Pro, logging occurs at the global server level and or the applicaiton level by using custom logback files. In this tutorial, we will be adding custom logging to our example application that we have been building throughout this series.

Download the Red5 Pro Server Download the latest Red5 Pro Server!

Register A Red5 Pro Account

If you have not done so already, register for an account at https://account.red5pro.com.

* A Trial Account allows for up to 10 concurrent connections, while the Professional license has no connection limit.


Requirements

The following are required to setup the Red5 Pro Server and to follow along with this example:

The Red5 Pro server requires Java 1.7+ or higher. Install Java 1.7+ or higher if not already installed on your machine.


Red Pro Server Installation

  1. Download the Red5 Pro server from the downloads section of the Red5 Pro Accounts site.
  2. Unzip into a location on your local system. For the purposes of this tutorial, we will unzip the Red5 Pro server to: /Users/red5pro-user/red5pro on OSX or /home/red5pro-user/red5pro on Linux.
  3. Start the Red5 Pro server: •  On OSX & Linux: Open Terminal, cd into your Red5 Pro install directory and issue this command: ./red5.sh •  On Windows: Navigate to the Red5 Pro install directory in a File Browser and double-click on red5.bat
  4. After the server has started, open a web browser and navigate to http://localhost:5080
  5. If the server has started successfully, you should see the default landing page for the Red5 Pro server install •  The landing page can be found at /webapps/root/index.jsp of your Red5 Pro installation. You can modify or remove it as desired. For now, we will use it to navigate around and demonstrate what the Red5 Pro server can do!

Eclipse IDE

For the examples, we will be demonstrating how to set up the project in the Eclipse IDE. The steps for setup should be transferrable to the IDE of your choice, as it is the code and method of deployment that we will be more focused on.

Source Code

The source for this example can be checked out from the following Github repository: https://github.com/red5pro/red5pro-dev-series.git

Video Walk-Through

This documentation has an accompanying video walk through that you can follow as you are developing.

Red5 Pro Application Level Logging


Setup Workspace

In this section, you will setup your workspace by cloning the github repository and set up Eclipse.

Watch a demonstration of the current section
  1. Clone the Developer Series Github Repository
    1. Open a browser window and navigate to https://github.com/red5pro/red5pro-dev-series
    2. Click on the green Clone or download button to the right of the page
    3. Click on the Copy to clipboard icon to the right of the git URL
      View Screenshot
  2. Open Eclipse to a clean workspace and import the example project
    1. Open Eclipse
    2. Create a new workspace. ie: /Users/daccattato/eclipse-workspace
    3. Click Launch
  3. Import the example projec
    1. Right-Click inside the Project Explorer and select Import > import...
    2. Expand the Maven folder and select Existing Maven Projects
    3. Click Browse to the right of the Root Directory: field
    4. Navigate to where you cloned the repository and select the subdirectory 05-authenticating-connections
    5. Under the Projects: list, select the example/pom.xml
    6. Click Finish and let Maven resolve any errors you receive
  4. Verify that your workspace has no errors

Configure Logger

Watch a demonstration of the current section
  1. In the Project Explorer view, expand _example > src > main
  2. Right-Click the main folder and select New > Folder
  3. In the Folder Name: field type resources
  4. In the newly created folder, create a file named logback-example.xml
  5. Add the following contents to the file

     <?xml version="1.0" encoding="UTF-8"?>
     <configuration scan="true" scanPeriod="5 seconds">
    
         <contextName>example</contextName>
    
         <jmxConfigurator contextName="example" />
    
         <appender name="EXAMPLE_APPENDER" class="ch.qos.logback.core.rolling.RollingFileAppender">
             <File>log/example.log</File>
             <Append>true</Append>
             <Encoding>UTF-8</Encoding>
             <BufferedIO>false</BufferedIO>
             <ImmediateFlush>true</ImmediateFlush>
    
             <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
                 <FileNamePattern>example.%i.log</FileNamePattern>
                 <MinIndex>1</MinIndex>
                 <MaxIndex>10</MaxIndex>
             </rollingPolicy>
    
             <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
                 <MaxFileSize>5MB</MaxFileSize>
             </triggeringPolicy>
    
             <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
                 <pattern>%msg%n</pattern>
             </encoder>
         </appender>
    
         <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
             <encoder>
                 <pattern>[%p] [%thread] %logger - %msg%n</pattern>
             </encoder>
         </appender>
    
         <root>
             <level value="DEBUG" />
             <appender-ref ref="CONSOLE" />
             <appender-ref ref="EXAMPLE_APPENDER" />
         </root>
    
         <logger name="com.red5pro.example" level="DEBUG">
             <appender-ref ref="CONSOLE" />
             <appender-ref ref="EXAMPLE_APPENDER" />
         </logger>
    
     </configuration>
    
  6. Save the file

Add Log Statements

Watch a demonstration of the current section
  1. Inside of eclipse, navigate to src > main > java
  2. Open ExampleApplication.java
  3. Add the following code inside of the appStart method.

         ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    
         Runnable task = () -> log.debug("Scheduling: " + System.nanoTime());
    
         int initialDelay = 0;
         int period = 1;
         executor.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
    
  4. Verify that the code looks the same as https://github.com/red5pro/red5pro-dev-series/blob/master/06-application-level-logging/example/src/main/java/com/red5pro/example/ExampleApplication.java

Package And Deploy

Watch a demonstration of the current section
  1. Right-Click the example application from the Project Explorer
  2. Select Run As > Maven install
  3. Deploy the Application
    1. From the Project Explorer view, expand example > target
    2. Right-Click the example folder and select Copy
    3. From your file system, navigate to $RED5PRO_HOME/webapps/_
    4. Paste the copied example folder into the webapps directory

Start Server

Watch a demonstration of the current section
  1. Open a command prompt and navigate to $RED5_PRO_HOME
  2. Issue the following command sudo ./red5.sh

View Appliction Level Logs

Watch a demonstration of the current section
  1. View Application Level Logs
    1. From the command line, navigate to the logs directroy: ie: $RED5_PRO_HOME/logs
    2. issue the following command tail -f -n 100 example.log

Conclusion

Congratulations! You have just added connection custom application level logs to your example Red5 Pro Server Application!


Troubleshooting

The following sections may aide in troubleshooting any issues may come across in trying the previous examples.

If you have further questions, please contact us at red5pro@infrared5.com

Required open ports

The following default ports are required to be open in order to allow for Live Streaming and Second Screen:

  • 5080 : default web access of Red5
  • 1935 : default Red5 RTMP port
  • 8554 : default RTSP port
  • 8088 : default Second Screen Client registry
  • 6262 : default Second Screen Host registry