1//////////////////////////////////////////////////////////////////////////////// 2// 3// ADOBE SYSTEMS INCORPORATED 4// Copyright 2005-2007 Adobe Systems Incorporated 5// All Rights Reserved. 6// 7// NOTICE: Adobe permits you to use, modify, and distribute this file 8// in accordance with the terms of the license agreement accompanying it. 9// 10//////////////////////////////////////////////////////////////////////////////// 11 12package mx.logging 13{ 14 15import flash.events.EventDispatcher; 16import mx.managers.ISystemManager; 17import mx.managers.SystemManager; 18import mx.resources.IResourceManager; 19import mx.resources.ResourceManager; 20 21[ResourceBundle("logging")] 22 23/** 24 * The logger that is used within the logging framework. 25 * This class dispatches events for each message logged using the <code>log()</code> method. 26 * 27 * @langversion 3.0 28 * @playerversion Flash 9 29 * @playerversion AIR 1.1 30 * @productversion Flex 3 31 */ 32public class LogLogger extends EventDispatcher implements ILogger 33{ 34 include "../core/Version.as"; 35 36 //-------------------------------------------------------------------------- 37 // 38 // Constructor 39 // 40 //-------------------------------------------------------------------------- 41 42 /** 43 * Constructor. 44 * 45 * @param category The category for which this log sends messages. 46 * 47 * @langversion 3.0 48 * @playerversion Flash 9 49 * @playerversion AIR 1.1 50 * @productversion Flex 3 51 */ 52 public function LogLogger(category:String) 53 { 54 super(); 55 56 _category = category; 57 } 58 59 //-------------------------------------------------------------------------- 60 // 61 // Variables 62 // 63 //-------------------------------------------------------------------------- 64 65 /** 66 * @private 67 * Used for accessing localized Error messages. 68 */ 69 private var resourceManager:IResourceManager = 70 ResourceManager.getInstance(); 71 72 //-------------------------------------------------------------------------- 73 // 74 // Properties 75 // 76 //-------------------------------------------------------------------------- 77 78 //---------------------------------- 79 // category 80 //---------------------------------- 81 82 /** 83 * @private 84 * Storage for the category property. 85 */ 86 private var _category:String; 87 88 /** 89 * The category this logger send messages for. 90 * 91 * @langversion 3.0 92 * @playerversion Flash 9 93 * @playerversion AIR 1.1 94 * @productversion Flex 3 95 */ 96 public function get category():String 97 { 98 return _category; 99 } 100 101 //-------------------------------------------------------------------------- 102 // 103 // Methods 104 // 105 //-------------------------------------------------------------------------- 106 107 /** 108 * @inheritDoc 109 * 110 * @langversion 3.0 111 * @playerversion Flash 9 112 * @playerversion AIR 1.1 113 * @productversion Flex 3 114 */ 115 public function log(level:int, msg:String, ... rest):void 116 { 117 // we don't want to allow people to log messages at the 118 // Log.Level.ALL level, so throw a RTE if they do 119 if (level < LogEventLevel.DEBUG) 120 { 121 var message:String = resourceManager.getString( 122 "logging", "levelLimit"); 123 throw new ArgumentError(message); 124 } 125 126 if (hasEventListener(LogEvent.LOG)) 127 { 128 // replace all of the parameters in the msg string 129 for (var i:int = 0; i < rest.length; i++) 130 { 131 msg = msg.replace(new RegExp("\\{"+i+"\\}", "g"), rest[i]); 132 } 133 134 dispatchEvent(new LogEvent(msg, level)); 135 } 136 } 137 138 /** 139 * @inheritDoc 140 * 141 * @langversion 3.0 142 * @playerversion Flash 9 143 * @playerversion AIR 1.1 144 * @productversion Flex 3 145 */ 146 public function debug(msg:String, ... rest):void 147 { 148 if (hasEventListener(LogEvent.LOG)) 149 { 150 // replace all of the parameters in the msg string 151 for (var i:int = 0; i < rest.length; i++) 152 { 153 msg = msg.replace(new RegExp("\\{"+i+"\\}", "g"), rest[i]); 154 } 155 156 dispatchEvent(new LogEvent(msg, LogEventLevel.DEBUG)); 157 } 158 } 159 160 /** 161 * @inheritDoc 162 * 163 * @langversion 3.0 164 * @playerversion Flash 9 165 * @playerversion AIR 1.1 166 * @productversion Flex 3 167 */ 168 public function error(msg:String, ... rest):void 169 { 170 if (hasEventListener(LogEvent.LOG)) 171 { 172 // replace all of the parameters in the msg string 173 for (var i:int = 0; i < rest.length; i++) 174 { 175 msg = msg.replace(new RegExp("\\{"+i+"\\}", "g"), rest[i]); 176 } 177 178 dispatchEvent(new LogEvent(msg, LogEventLevel.ERROR)); 179 } 180 } 181 182 /** 183 * @inheritDoc 184 * 185 * @langversion 3.0 186 * @playerversion Flash 9 187 * @playerversion AIR 1.1 188 * @productversion Flex 3 189 */ 190 public function fatal(msg:String, ... rest):void 191 { 192 if (hasEventListener(LogEvent.LOG)) 193 { 194 // replace all of the parameters in the msg string 195 for (var i:int = 0; i < rest.length; i++) 196 { 197 msg = msg.replace(new RegExp("\\{"+i+"\\}", "g"), rest[i]); 198 } 199 200 dispatchEvent(new LogEvent(msg, LogEventLevel.FATAL)); 201 } 202 } 203 204 /** 205 * @inheritDoc 206 * 207 * @langversion 3.0 208 * @playerversion Flash 9 209 * @playerversion AIR 1.1 210 * @productversion Flex 3 211 */ 212 public function info(msg:String, ... rest):void 213 { 214 if (hasEventListener(LogEvent.LOG)) 215 { 216 // replace all of the parameters in the msg string 217 for (var i:int = 0; i < rest.length; i++) 218 { 219 msg = msg.replace(new RegExp("\\{"+i+"\\}", "g"), rest[i]); 220 } 221 222 dispatchEvent(new LogEvent(msg, LogEventLevel.INFO)); 223 } 224 } 225 226 /** 227 * @inheritDoc 228 * 229 * @langversion 3.0 230 * @playerversion Flash 9 231 * @playerversion AIR 1.1 232 * @productversion Flex 3 233 */ 234 public function warn(msg:String, ... rest):void 235 { 236 if (hasEventListener(LogEvent.LOG)) 237 { 238 // replace all of the parameters in the msg string 239 for (var i:int = 0; i < rest.length; i++) 240 { 241 msg = msg.replace(new RegExp("\\{"+i+"\\}", "g"), rest[i]); 242 } 243 244 dispatchEvent(new LogEvent(msg, LogEventLevel.WARN)); 245 } 246 } 247} 248 249} 250