Flex中使用日志 Use Log In Flex

Categories: Flex; Tagged with: ; @ October 15th, 2008 14:55

需求: 为每个类获得一个ILogger实例,为了保证可配置与可控性, 不要为每个类使用一个单独的Log实例.

譬如在某个app[SchoolMangement]中, 我们有Person类, Teacher类, Student类等, 理论上来说, 应该为每一个类获得一个ILogger实例, 除非你不需要在这个类中使用日志.

如在Person类中:
private var log:ILogger = Log.getLogger(“com.liguoliang.Person”);
使用该实例:
log.info(“新增加一个Person’);

同样在Teacher类,Student类中都使用
private var log:ILogger = Log.getLogger(“com.insprise.xx”);
实例化对应的类.
这便是为每一个类获得一个ILogger实例.

为了便于统一配置与控制,我们在App中我们为上面的所有ILogger提供一个统一的Log实例:

如,在SchoolMangement.mxml,或main.mxml或是其他的入口中, 在其初始化时实例化一个Log类:

	var traceTraget:TraceTarget = new TraceTarget();
	traceTraget.includeCategory = true;
	traceTraget.includeLevel = true;
	Log.addTarget(traceTraget);

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.