This project is read-only.

Installation

  1. Install .NET 4
  2. Either download source and rebuild or download binaries.
  3. Unpack to a directory. There should be these files:
    1. some dlls - basic project libraries, IronPython libraries, Growl libraries
    2. executable -FormsViewer.exe_
    3. python files config.py (configuration - from port to listen on to default colors), definitions.py (custom python classes that add custom actions), uiconfig.py (UI settings like columns widths)
  4. Run FormsViewer.exe (you may be prompted to unblock the application, because it tries to listen on a udp port). The application main window should appear.

Basic usage

Sender configuration

First you have to configure your application to send udp logs. For quick info how the config should look like, find TestUdpEmitor.exe.config and look at the appender.
It is something like this:
<appender name="udpAppender8080" type="log4net.Appender.UdpAppender">
  <param name="RemoteAddress" value="127.0.0.1" />
  <param name="RemotePort" value="8080" />
  <layout type="log4net.Layout.XmlLayout">
    <param name="Prefix" value="" />
  </layout>
</appender>

It means that the application will send the messages to localhost to port 8080.
If you just want to try what UdpLogViewer does, use TestUdpEmitor.exe. It is fully configured and works instantly.

Viewer

Colors
Every message that your application emits, is by default shown in the UdpLogViewer's grid. If the level is DEBUG, the message is grey on black background. INFO message is white on black background etc. You can change the colors in config.py.
If you wonder what values you can pass in, have a look at Color Members at MSDN.

Messages receiving
By default the application listens on the port and shows the messages. If you need to pause it, just check Sleep and nothing will be displayed until you uncheck the check box.
If you select any message from the grid, it is also written into the textbox below the grid. Thus, you can copy the message to your clipboard if you wish.
When you click on Clear, the grid gets cleared.

UI configuration
You can select your custom font via button Font. It is also possible to resize columns and main application window as well.
All the columns widths are remembered as well as application's window size and selected font. The values are stored in file uiconfig.py

Advanced features

Custom rules

UdpLogViewer can be customized using rules. Look at example.rules.py for inspiration how it could look like:
import Growl.Connector
from stej.Tools.UdpLogViewer.CommonRules import Show, Swallow
connector = Growl.Connector.GrowlConnector()
cond = [
	#ToFile('.'),
	#ToGrowl('#25|#35', connector),
	Swallow('warn'),
	Show('debug', Color.Cyan, Color.Black),
	Show('info', Color.Magenta, Color.Black),
	Show('10', Color.BlueViolet, Color.Black),
	Show('11', Color.Brown, Color.Black),
	Show('error', Color.BurlyWood, Color.Black)
]

for c in cond: processor.Add(c)

It is an IronPython script that adds some instances to collection processor. You can see instances of classes Swallow, Show, ToFile and ToGrowl. (Note for devs who are not familiar with IronPython: Swallow('warn') is creating new instance of class Swallow - it is the same as new Swallow('warn') in C#.) Each constructor takes regular expression as its first parameter. This regex will be taken to decide if the rule should be applied.

When a new udp messages is received, it is processed by custom rules one by one. Each rule whose regex matches the message, can stop processing, so that no following rules are applied. The rule can also specify if the message should be shown (and in what colors) or not.

Example
In our example above we have one instance of class Swallow and five instances of class Show .
  • If the incomming message is 'warning and error', it is caught by the first rule of class Swallow . You can find corresponding class in stej.Tools.UdpLogViewer.CommonRules.Swallow . It stops processing and discards the message, because it matches the regex 'warn'.
  • If the incomming message is 'error', all the rules are checked if their regex matches the message up to the last rule. Show('error', Color.BurlyWood, Color.Black) matches the regex, so it is used. It specifies that the message should be shown in BurlyWood/Black colors.

Both classes Swallow and Show are ordinary C# classes to make things faster.
There are two more classes - ToGrowl and ToFile . They are defined in file definitions.py.

Use rules
I hope you understand what rules are and what is their purpose. Now it's time to use them. You need to create file rules.py and place it in the same directory as the executable.
This file should contain IronPython code (as the example above) that fills collection processors . The simples version could look like this:
from stej.Tools.UdpLogViewer.CommonRules import Swallow
processor.Add(Swallow('test')) 

This will discard all messages that match regex 'test'.

If you run UdpLogViewer, you will see file rules.py listed in the list box below label 'Selected rules'.

More rules groups, not only one

In real life you probably use more applications that log. Each application has its own set of messages that could be displayed in UdpLogViewer. That means that each application should have its own file with rules, right?

Yes, it's that easy.
Just create separate files called rules.whatever.py (the file has to begin with string 'rules') and place application specific rules into the file. Keep in mind that each file should fill collection processors.
All the rules files are listed in list box below label 'Selected rules'.

After the application starts, first file (group of rules) is selected and used for message processing. Then if you start development of other application, the only thing you need to do is to select appropriate rules file in the list box. That instructs UdpLogViewer that for all the following messages the selected group of rules should be used.

Reload
If you change content of any file with rules, it is needed to reload them. Click on button Reload and all the rules will be reloaded from all the files. It is not possible to just reload one rules file.

Temporarily turn off some rules

In some cases you will need to disable some rules for the current session. Then click on button Rules. New window will appear and you will see all the currently selected rules and their descriptions.
Next to each row there is a checkbox that indicates whether the rule is active or not. If you need to disable the rule, uncheck it and hit Save&Close.
Every next message will not be processed by the unchecked rule.

What rule matched the message?

Regexes can be tricky, all devs know that. There is some probability that the message will be caught by some other rule than the one you intended and will get unwanted color.
You can find the matching rule very easily: select the row in grid and click on Matching Rules. This will popup a dialog that you have already seen when you clicked on button Rules. The difference is that this time the last column is colored.
  • Orange color means 'no match'.
  • Green color means that the rules regex matches the message.

In case you don't see a message that should be really logged, it is possible that it is swallowed by a greedy rule. Then you can again open the window with current rules and test them - type the logger name and the lost message in the inputs and press Test. Matching rules will be again Green.

How to register UdpLogViewer to Growl

If you would like to send some messages to Growl for Windows, it is needed to register UdpLogViewer. To simplify the step there is one python script prepared. What you need to do:
  • close UdpLogViewer
  • rename support.rules.addGrowl.py to rules.addGrowl.py.
  • run UdpLogViewer. It will execute rules.addGrowl.py where script for registration is located
  • Growl should notify you about the successful registration
  • now it is time to create a processor that sends message to Growl. There is an example in example.rules.py -- ToGrowl('#25|#35', connector) means "send all messages that match given regex to Growl".
  • rename rules.addGrowl.py back to support.rules.addGrowl.py and close UdpLogViewer or click on Reload.

What have you done? You have registered UdpLogViewer under the same name (UdpLogViewer) and one notification type with name lv (its display name is Message).

If you look into definitions.py you will see this row:
 notification = Growl.Connector.Notification(
      'UdpLogViewer', 
      'lv', 
      System.DateTime.Now.Ticks.ToString(), 
      'Log item arrived', 
      logItem.Message) 

You can see we use the same application name (UdpLogViewer) and notification name (lv) as during registration.

Last edited May 24, 2010 at 8:40 PM by stejcz, version 12

Comments

No comments yet.