com. kelvinluck. util. SOSLogPublisher

IPublisher
com.kelvinluck.util.SOSLogPublisher

Class to add the ability to output logged data to the PowerFlasher Socket Output Server.

Mostly just a simple conversion of Pablo Costantini’s LuminicBox.Log.TracePublisher code.

Requirements

This code requires that the LuminicBox.Log classes are in your classpath when you compile it and that you have a SOS Server running to see the output on.  Also bear in mind that connections to the SOS Server are subject to Flash’s security restrictions.

Usage

import com.kelvinluck.util.LogWrapper;
import com.kelvinluck.util.SOSLogPublisher;
LogWrapper.getInstance().init();
LogWrapper.getLog().addPublisher(new SOSLogPublisher("myAppsName"));
LogWrapper.getLog().fatal("This is a fatal error :'(");
LogWrapper.getLog().error("This is an error :(");
LogWrapper.getLog().warn("This is a warning, warning, warning");
LogWrapper.getLog().info("This is information");
LogWrapper.getLog().debug("This is debugging info");
LogWrapper.getLog().debug([1,2,3,{a:"Part A", b:"Part B"}, "Some text", 99]);

See Also

http://sos.powerflasher.com/

http://sos.powerflasher.de/doc/1-04/

http://www.luminicbox.com- /blog- /?page=post- &id=2

http://kelvinluck.com/article/logging-from-fame

Author

Kelvin Luck derived from the work of Pablo Costantini

License

Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the “License”); you may not use this file except in compliance with the License.  You may obtain a copy of the License at

http://www.mozilla.org/MPL/MPL-1.1.html

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the specific language governing permissions and limitations under the License.

Subversion Id

$Id: SOSLogPublisher.as 37 2006-05-10 19:29:32Z kluck $

Summary
com. kelvinluck. util. SOSLogPublisherClass to add the ability to output logged data to the PowerFlasher Socket Output Server.
COL_FATALThe colour of the background of log messages with a severity of FATAL
COL_ERRORThe colour of the background of log messages with a severity of ERROR
COL_WARNThe colour of the background of log messages with a severity of WARN
COL_INFOThe colour of the background of log messages with a severity of INFO
COL_DEBUGThe colour of the background of log messages with a severity of DEBUG
indentSets the string that is used to indent object blocks.
maxDepthThe maximum inspection depth.
SOSLogPublisherCreates a SOSLogPublisher instance.
_sendCommandInternal, private function that makes it easier to send a command without worrying about the null byte or other implementation details.
publishSends a log event through the socket to the SOS Server
analyzeObjTakes an anything and returns a pretty printed version by recursively moving down the object tree
closeAllSocketsLoops over all created SOSLogPublishers and shuts down their connections.
toStringThe name of the class of this object.

COL_FATAL

private static var COL_FATAL: Number

The colour of the background of log messages with a severity of FATAL

COL_ERROR

private static var COL_ERROR: Number

The colour of the background of log messages with a severity of ERROR

COL_WARN

private static var COL_WARN: Number

The colour of the background of log messages with a severity of WARN

COL_INFO

private static var COL_INFO: Number

The colour of the background of log messages with a severity of INFO

COL_DEBUG

private static var COL_DEBUG: Number

The colour of the background of log messages with a severity of DEBUG

indent

var indent: String

Sets the string that is used to indent object blocks.  Defaults to a tab but you can use anything you like (“| “ is good if you are logging to a monospace font in SOS)

maxDepth

function set maxDepth(value: Number)

The maximum inspection depth.

The default value is 4.  The max. valid value is 255.

SOSLogPublisher

function SOSLogPublisher(appName: String,
sosServer: String,
sosPort: Number,
maxDepth: Number)

Creates a SOSLogPublisher instance.  Also initalises communications with SOS through an XMLSocket.

Parameters

appNameThe name of this app.  [defaults to “UNKNOWN”]
sosServerThe IP address of the SOS server.  [defaults to localhost]
sosPortThe command port of the SOS server to connect to.
[defaults to 4444the default Log-Port];
maxDepthThe maximum depth to inspect into objects / arrays.  [defaults to 4]

_sendCommand

private function _sendCommand(command: String)

Internal, private function that makes it easier to send a command without worrying about the null byte or other implementation details.

Also makes it easier to switch between sending the command on the Command-Port (which seems to make sense but doesn’t activate the userful “Bring to front > During connection” functionality of SOS) and sending commands on the Log-Port (which has the overhead of 4 bytes per command).

Arguments

commandThe XML to send as the command.

publish

function publish(e: LogEvent):Void

Sends a log event through the socket to the SOS Server

Parameters

eThe <LogEvent> to log...

analyzeObj

private function analyzeObj(o, 
depth: Number):String

Takes an anything and returns a pretty printed version by recursively moving down the object tree

Taken from the original LuminicBox.Log.TracePublisher code and slightly modified...

Parameters

oThe object to analyse
depthHow deep into the object tree we currently are

See Also

<LuminicBox.Log.TracePublisher>

closeAllSockets

public static function closeAllSockets():Void

Loops over all created SOSLogPublishers and shuts down their connections.  Use if e.g. you want to kill the connection to the SOS Server (so that it stops sitting on top) without killing the swf you are testing...

toString

function toString():String

Returns

The name of the class of this object.

private static var COL_FATAL: Number
The colour of the background of log messages with a severity of FATAL
private static var COL_ERROR: Number
The colour of the background of log messages with a severity of ERROR
private static var COL_WARN: Number
The colour of the background of log messages with a severity of WARN
private static var COL_INFO: Number
The colour of the background of log messages with a severity of INFO
private static var COL_DEBUG: Number
The colour of the background of log messages with a severity of DEBUG
var indent: String
Sets the string that is used to indent object blocks.
function set maxDepth(value: Number)
The maximum inspection depth.
function SOSLogPublisher(appName: String,
sosServer: String,
sosPort: Number,
maxDepth: Number)
Creates a SOSLogPublisher instance.
private function _sendCommand(command: String)
Internal, private function that makes it easier to send a command without worrying about the null byte or other implementation details.
function publish(e: LogEvent):Void
Sends a log event through the socket to the SOS Server
private function analyzeObj(o, 
depth: Number):String
Takes an anything and returns a pretty printed version by recursively moving down the object tree
public static function closeAllSockets():Void
Loops over all created SOSLogPublishers and shuts down their connections.
function toString():String
The name of the class of this object.