public void Log_Data() { UT_INIT(); Log.AddDebugLogger(); Log.SetVerbosity( Log.DebugLogger, Verbosity.Verbose, ALox.InternalDomains ); Log.SetDomain( "Data", Scope.Method ); // LogData Constructors { LogData ld; AString asnull= new AString(); ld= new LogData( ); UT_EQ( asnull, ld.StringValue ); UT_EQ( 0, ld.IntegerValue ); UT_TRUE( ld.ObjectValue == null ); ld= new LogData( 3 ); UT_EQ( asnull, ld.StringValue ); UT_EQ( 3, ld.IntegerValue ); UT_TRUE( ld.ObjectValue == null ); ld= new LogData( 3, this); UT_EQ( asnull, ld.StringValue ); UT_EQ( 3, ld.IntegerValue ); UT_TRUE( ld.ObjectValue == this ); ld= new LogData("ABC" ); UT_EQ( "ABC", ld.StringValue ); UT_EQ( 0, ld.IntegerValue ); UT_TRUE( ld.ObjectValue == null ); ld= new LogData("ABC", 0, this); UT_EQ( "ABC", ld.StringValue ); UT_EQ( 0, ld.IntegerValue ); UT_TRUE( ld.ObjectValue == this ); ld= new LogData("ABC", 3 ); UT_EQ( "ABC", ld.StringValue ); UT_EQ( 3, ld.IntegerValue ); UT_TRUE( ld.ObjectValue == null ); ld= new LogData("ABC", 3, this); UT_EQ( "ABC", ld.StringValue ); UT_EQ( 3, ld.IntegerValue ); UT_TRUE( ld.ObjectValue == this ); } // without key Log.Store( null , Scope.Global ); Log.Store( new LogData( "Replaced" ), Scope.Global ); Log.Store( null , Scope.Global ); Log.Store( null , Scope.Global ); Log.Store( new LogData( "Replaced" ), Scope.Global ); Log.Store( new LogData( "Global" ), Scope.Global ); Log.Store( new LogData( "Replaced" ), Scope.ThreadOuter ); Log.Store( new LogData( "ThreadOuter" ), Scope.ThreadOuter ); Log.Store( new LogData( "Replaced" ), Scope.Path, 1 ); Log.Store( new LogData( "Path1" ), Scope.Path, 1 ); Log.Store( new LogData( "Replaced" ), Scope.Path ); Log.Store( new LogData( "Path" ), Scope.Path ); Log.Store( new LogData( "Replaced" ), Scope.Filename ); Log.Store( new LogData( "FileName" ), Scope.Filename ); Log.Store( new LogData( "Replaced" ), Scope.Method ); Log.Store( new LogData( "Method" ), Scope.Method ); Log.Store( new LogData( "Replaced" ), Scope.ThreadInner ); Log.Store( new LogData( "ThreadInner" ), Scope.ThreadInner ); LogData data= null; data= Log.Retrieve( Scope.Global ); UT_EQ( "Global" , data.StringValue ); data= Log.Retrieve( Scope.ThreadOuter ); UT_EQ( "ThreadOuter" , data.StringValue ); data= Log.Retrieve( Scope.Path, 1 ); UT_EQ( "Path1" , data.StringValue ); data= Log.Retrieve( Scope.Path ); UT_EQ( "Path" , data.StringValue ); data= Log.Retrieve( Scope.Filename ); UT_EQ( "FileName" , data.StringValue ); data= Log.Retrieve( Scope.Method ); UT_EQ( "Method" , data.StringValue ); data= Log.Retrieve( Scope.ThreadInner ); UT_EQ( "ThreadInner" , data.StringValue ); // wit key Log.Store( new LogData( "Replaced" ), "mykey", Scope.Global ); Log.Store( new LogData( "Global" ), "mykey", Scope.Global ); Log.Store( new LogData( "Replaced" ), "mykey", Scope.ThreadOuter ); Log.Store( new LogData( "ThreadOuter" ), "mykey", Scope.ThreadOuter ); Log.Store( new LogData( "Replaced" ), "mykey", Scope.Path, 1 ); Log.Store( new LogData( "Path1" ), "mykey", Scope.Path, 1 ); Log.Store( new LogData( "Replaced" ), "mykey", Scope.Path ); Log.Store( new LogData( "Path" ), "mykey", Scope.Path ); Log.Store( new LogData( "Replaced" ), "mykey", Scope.Filename ); Log.Store( new LogData( "FileName" ), "mykey", Scope.Filename ); Log.Store( new LogData( "Replaced" ), "mykey", Scope.Method ); Log.Store( new LogData( "Method" ), "mykey", Scope.Method ); Log.Store( new LogData( "Replaced" ), "mykey", Scope.ThreadInner ); Log.Store( new LogData( "ThreadInner" ), "mykey", Scope.ThreadInner ); data= Log.Retrieve( "mykey", Scope.Global ); UT_EQ( "Global" , data.StringValue ); data= Log.Retrieve( "mykey", Scope.ThreadOuter ); UT_EQ( "ThreadOuter" , data.StringValue ); data= Log.Retrieve( "mykey", Scope.Path, 1 ); UT_EQ( "Path1" , data.StringValue ); data= Log.Retrieve( "mykey", Scope.Path ); UT_EQ( "Path" , data.StringValue ); data= Log.Retrieve( "mykey", Scope.Filename ); UT_EQ( "FileName" , data.StringValue ); data= Log.Retrieve( "mykey", Scope.Method ); UT_EQ( "Method" , data.StringValue ); data= Log.Retrieve( "mykey", Scope.ThreadInner ); UT_EQ( "ThreadInner" , data.StringValue ); // threaded Log.Store( new LogData( "Main Thread Data" ), Scope.ThreadOuter ); Log.Store( new LogData( "Main Thread Data, keyed" ), "mykey", Scope.ThreadOuter ); Thread thread= new Thread( new ThreadStart( StoreDataTestThreadRun ) ); thread.Start(); while( thread.IsAlive ) ALIB.SleepMicros(1); data= Log.Retrieve( Scope.ThreadOuter ); UT_EQ( "Main Thread Data" , data.StringValue ); data= Log.Retrieve( "mykey", Scope.ThreadOuter ); UT_EQ( "Main Thread Data, keyed" , data.StringValue ); }
public static void Store( LogData data, String key, Scope scope= Scope.Global , int pathLevel= 0, [CallerLineNumber] int cln= 0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="" ) { #if ALOX_DBG_LOG LOX.Store( data, key, scope, pathLevel, cln,csf,cmn); #endif }
public void Store( LogData data, String key, Scope scope= Scope.Global , int pathLevel= 0, [CallerLineNumber] int cln= 0,[CallerFilePath] String csf="",[CallerMemberName] String cmn="" ) { #if ALOX_DBG_LOG || ALOX_REL_LOG try { Acquire(cln, csf, cmn ); // store scope info scopeInfo.Set( cln,csf,cmn, owner ); intMsg._(); // We need a key. If none is given, we use a constant one indicating that storage is // associated exclusively with scope AString aKey= new AString(key); bool keyWasEmtpy; if ( (keyWasEmtpy= aKey.IsEmpty()) ) aKey._NC( noKeyHashKey ); // get the store scopeLogData.InitAccess( scope, pathLevel, null ); Dictionary<AString, LogData> map= (Dictionary<AString, LogData>) scopeLogData.Get(); if( map == null && data != null ) { map= new Dictionary<AString, LogData>(); scopeLogData.Store(map ); } // create map entry LogData previous= null; if ( map != null ) map.TryGetValue( aKey, out previous ); if ( data != null ) { map[aKey]= data; // log info if this was the last time intMsg._NC( "Stored data " ); if ( !keyWasEmtpy ) intMsg._NC( " with key \"" )._NC( tmpAS )._NC( "\" " ); intMsg._NC( "in " ); ALox.ToString(scope, pathLevel, intMsg); intMsg._( '.' ); if ( previous != null ) intMsg._NC( " (Replaced previous.)" ); } else { if ( previous != null ) { map.Remove( aKey ); if ( map.Count == 0 ) scopeLogData.Remove( null ); intMsg._NC( "Deleted map data " ); } else intMsg._NC( "No map data found to delete " ); if ( !keyWasEmtpy ) intMsg._NC( " with key \"" )._NC( tmpAS )._NC( "\" " ); intMsg._NC( "in " ); ALox.ToString(scope, pathLevel, intMsg); } logInternal( Verbosity.Info, "LGD", intMsg ); } finally { Release(); } #endif }