Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit eb7aac0

Browse files
authored
Merge pull request #229 from p-org/LoggingAPI
Logging improvements
2 parents ac4e779 + 562b389 commit eb7aac0

File tree

13 files changed

+950
-316
lines changed

13 files changed

+950
-316
lines changed

Samples/PingPong/PingPong.CustomLogging/Test.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ namespace PingPong.CustomLogging
66
{
77
/// <summary>
88
/// A simple PingPong application written using the P# high-level syntax.
9-
///
9+
///
1010
/// The P# runtime starts by creating the P# machine 'NetworkEnvironment'. The
1111
/// 'NetworkEnvironment' machine then creates a 'Server' and a 'Client' machine,
1212
/// which then communicate by sending 'Ping' and 'Pong' events to each other for
1313
/// a limited amount of turns.
14-
///
14+
///
1515
/// This sample shows how to install a custom logger during testing.
16-
///
16+
///
1717
/// Note: this is an abstract implementation aimed primarily to showcase the testing
1818
/// capabilities of P#.
1919
/// </summary>
@@ -60,13 +60,13 @@ public static void Execute(PSharpRuntime runtime)
6060
/// <summary>
6161
/// Custom logger that just dumps to console.
6262
/// </summary>
63-
class MyLogger : ILogger
63+
class MyLogger : StateMachineLogger
6464
{
6565
/// <summary>
6666
/// Writes the specified string value.
6767
/// </summary>
6868
/// <param name="value">Text</param>
69-
public void Write(string value)
69+
public override void Write(string value)
7070
{
7171
Console.Write(value);
7272
}
@@ -76,7 +76,7 @@ public void Write(string value)
7676
/// </summary>
7777
/// <param name="format">Text</param>
7878
/// <param name="args">Arguments</param>
79-
public void Write(string format, params object[] args)
79+
public override void Write(string format, params object[] args)
8080
{
8181
Console.Write($"MyLogger: {format}", args);
8282
}
@@ -86,7 +86,7 @@ public void Write(string format, params object[] args)
8686
/// current line terminator.
8787
/// </summary>
8888
/// <param name="value">Text</param>
89-
public void WriteLine(string value)
89+
public override void WriteLine(string value)
9090
{
9191
Console.WriteLine($"MyLogger: {value}");
9292
}
@@ -97,14 +97,14 @@ public void WriteLine(string value)
9797
/// </summary>
9898
/// <param name="format">Text</param>
9999
/// <param name="args">Arguments</param>
100-
public void WriteLine(string format, params object[] args)
100+
public override void WriteLine(string format, params object[] args)
101101
{
102102
Console.WriteLine($"MyLogger: {format}", args);
103103
}
104104

105105
/// <summary>
106106
/// Disposes the logger.
107107
/// </summary>
108-
public void Dispose() { }
108+
public override void Dispose() { }
109109
}
110110
}

Source/Core/IO/Logging/ConsoleLogger.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ namespace Microsoft.PSharp.IO
1919
/// <summary>
2020
/// Logger that writes text to the console.
2121
/// </summary>
22-
internal sealed class ConsoleLogger : ILogger
22+
internal sealed class ConsoleLogger : StateMachineLogger
2323
{
2424
/// <summary>
2525
/// Writes the specified string value.
2626
/// </summary>
2727
/// <param name="value">Text</param>
28-
public void Write(string value)
28+
public override void Write(string value)
2929
{
3030
Console.Write(value);
3131
}
@@ -35,7 +35,7 @@ public void Write(string value)
3535
/// </summary>
3636
/// <param name="format">Text</param>
3737
/// <param name="args">Arguments</param>
38-
public void Write(string format, params object[] args)
38+
public override void Write(string format, params object[] args)
3939
{
4040
Console.Write(format, args);
4141
}
@@ -45,7 +45,7 @@ public void Write(string format, params object[] args)
4545
/// current line terminator.
4646
/// </summary>
4747
/// <param name="value">Text</param>
48-
public void WriteLine(string value)
48+
public override void WriteLine(string value)
4949
{
5050
Console.WriteLine(value);
5151
}
@@ -56,14 +56,14 @@ public void WriteLine(string value)
5656
/// </summary>
5757
/// <param name="format">Text</param>
5858
/// <param name="args">Arguments</param>
59-
public void WriteLine(string format, params object[] args)
59+
public override void WriteLine(string format, params object[] args)
6060
{
6161
Console.WriteLine(format, args);
6262
}
6363

6464
/// <summary>
6565
/// Disposes the logger.
6666
/// </summary>
67-
public void Dispose() { }
67+
public override void Dispose() { }
6868
}
6969
}

Source/Core/IO/Logging/DisposingLogger.cs

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,26 @@
1212
// </copyright>
1313
//-----------------------------------------------------------------------
1414

15+
using Microsoft.PSharp.Utilities;
16+
using System;
17+
1518
namespace Microsoft.PSharp.IO
1619
{
1720
/// <summary>
1821
/// Logger that disposes all written text.
1922
/// </summary>
2023
internal sealed class DisposingLogger : ILogger
2124
{
25+
/// <summary>
26+
/// The configuration that sets the logging verbosity.
27+
/// </summary>
28+
public Configuration Configuration { get; set; }
29+
30+
/// <summary>
31+
/// The minimum logging verbosity level (should be >= 0, use 0 to log all messages).
32+
/// </summary>
33+
public int LoggingVerbosity { get; set; }
34+
2235
/// <summary>
2336
/// Writes the specified string value.
2437
/// </summary>
@@ -47,6 +60,179 @@ public void WriteLine(string value) { }
4760
/// <param name="args">Arguments</param>
4861
public void WriteLine(string format, params object[] args) { }
4962

63+
/// <summary>
64+
/// Called when an event is about to be enqueued to a machine.
65+
/// </summary>
66+
/// <param name="machineId">Id of the machine that the event is being enqueued to.</param>
67+
/// <param name="currentStateName">The name of the current state of <paramref name="machineId"/>, if any.</param>
68+
/// <param name="eventName">Name of the event.</param>
69+
public void OnEnqueue(MachineId machineId, string currentStateName, string eventName) { }
70+
71+
/// <summary>
72+
/// Called when an event is dequeued by a machine.
73+
/// </summary>
74+
/// <param name="machineId">Id of the machine that the event is being dequeued by.</param>
75+
/// <param name="currentStateName">The name of the current state of <paramref name="machineId"/>, if any.</param>
76+
/// <param name="eventName">Name of the event.</param>
77+
public void OnDequeue(MachineId machineId, string currentStateName, string eventName) { }
78+
79+
/// <summary>
80+
/// Called when the default event handler for a state is about to be executed.
81+
/// </summary>
82+
/// <param name="machineId">Id of the machine that the state will execute in.</param>
83+
/// <param name="currentStateName">Name of the current state of the machine.</param>
84+
public void OnDefault(MachineId machineId, string currentStateName) { }
85+
86+
/// <summary>
87+
/// Called when a machine is being pushed to a state.
88+
/// </summary>
89+
/// <param name="machineId">Id of the machine being pushed to the state.</param>
90+
/// <param name="currentStateName">The name of the current state of <paramref name="machineId"/>, if any.</param>
91+
/// <param name="newStateName">The state the machine is pushed to.</param>
92+
public void OnPush(MachineId machineId, string currentStateName, string newStateName) { }
93+
94+
/// <summary>
95+
/// Called when a machine has been popped from a state.
96+
/// </summary>
97+
/// <param name="machineId">Id of the machine that the pop executed in.</param>
98+
/// <param name="currentStateName">The name of the current state of <paramref name="machineId"/>, if any.</param>
99+
/// <param name="restoredStateName">The name of the state being restored, if any.</param>
100+
public void OnPop(MachineId machineId, string currentStateName, string restoredStateName) { }
101+
102+
/// <summary>
103+
/// When an event cannot be handled in the current state, its exit handler is executed and then the state is
104+
/// popped and any previous "current state" is reentered. This handler is called when that pop has been done.
105+
/// </summary>
106+
/// <param name="machineId">Id of the machine that the pop executed in.</param>
107+
/// <param name="currentStateName">The name of the current state of <paramref name="machineId"/> (which is being re-entered), if any.</param>
108+
/// <param name="eventName">The name of the event that cannot be handled.</param>
109+
public void OnPopUnhandledEvent(MachineId machineId, string currentStateName, string eventName) { }
110+
111+
/// <summary>
112+
/// Called when an event is received by a machine.
113+
/// </summary>
114+
/// <param name="machineId">Id of the machine that received the event.</param>
115+
/// <param name="eventName">The name of the event.</param>
116+
/// <param name="currentStateName">The name of the current state of <paramref name="machineId"/>, if any.</param>
117+
/// <param name="wasBlocked">The machine was waiting for one or more specific events, and <paramref name="eventName"/> was one of them.</param>
118+
public void OnReceive(MachineId machineId, string currentStateName, string eventName, bool wasBlocked) { }
119+
120+
/// <summary>
121+
/// Called when a machine enters a wait state.
122+
/// </summary>
123+
/// <param name="machineId">Id of the machine that is entering the wait state.</param>
124+
/// <param name="currentStateName">The name of the current state of <paramref name="machineId"/>, if any.</param>
125+
/// <param name="eventNames">The names of the specific events being waited for, if any.</param>
126+
public void OnWait(MachineId machineId, string currentStateName, string eventNames) { }
127+
128+
/// <summary>
129+
/// Called when an event is sent to a target machine.
130+
/// </summary>
131+
/// <param name="targetMachineId">Id of the target machine.</param>
132+
/// <param name="targetStateName">The name of the current state of the target machine.</param>
133+
/// <param name="senderId">The machine that sent the event, if any.</param>
134+
/// <param name="senderStateName">The name of the current state of the sender machine, if applicable
135+
/// (if it is a non-Machine specialization of an AbstractMachine, it is not applicable).</param>
136+
/// <param name="eventName">The event being sent.</param>
137+
/// <param name="operationGroupId">The operation group id, if any.</param>
138+
/// <param name="isTargetHalted">Is the target machine halted.</param>
139+
public void OnSend(MachineId targetMachineId, string targetStateName, MachineId senderId, string senderStateName,
140+
string eventName, Guid? operationGroupId, bool isTargetHalted) { }
141+
142+
/// <summary>
143+
/// Called when a machine has been created.
144+
/// </summary>
145+
/// <param name="machineId">The id of the machine that has been created.</param>
146+
public void OnCreateMachine(MachineId machineId) { }
147+
148+
/// <summary>
149+
/// Called when a monitor has been created.
150+
/// </summary>
151+
/// <param name="monitorTypeName">The name of the type of the monitor that has been created.</param>
152+
/// <param name="monitorId">The id of the monitor that has been created.</param>
153+
public void OnCreateMonitor(string monitorTypeName, MachineId monitorId) { }
154+
155+
/// <summary>
156+
/// Called when a machine has been halted.
157+
/// </summary>
158+
/// <param name="machineId">The id of the machine that has been halted.</param>
159+
public void OnHalt(MachineId machineId) { }
160+
161+
/// <summary>
162+
/// Called when a random result has been obtained.
163+
/// </summary>
164+
/// <param name="machineId">The id of the source machine, if any; otherwise, the runtime itself was the source.</param>
165+
/// <param name="result">The random result (may be bool or int).</param>
166+
public void OnRandom(MachineId machineId, object result) { }
167+
168+
/// <summary>
169+
/// Called when a machine enters or exits a state.
170+
/// </summary>
171+
/// <param name="machineId">The id of the machine entering or exiting the state.</param>
172+
/// <param name="stateName">The name of the state being entered or exited.</param>
173+
/// <param name="isEntry">If true, this is called for a state entry; otherwise, exit.</param>
174+
public void OnMachineState(MachineId machineId, string stateName, bool isEntry) { }
175+
176+
/// <summary>
177+
/// Called when a machine raises an event.
178+
/// </summary>
179+
/// <param name="machineId">The id of the machine raising the event.</param>
180+
/// <param name="currentStateName">The name of the current state of the machine raising the event.</param>
181+
/// <param name="eventName">The name of the event being raised.</param>
182+
public void OnMachineEvent(MachineId machineId, string currentStateName, string eventName) { }
183+
184+
/// <summary>
185+
/// Called when a machine executes an action.
186+
/// </summary>
187+
/// <param name="machineId">The id of the machine executing the action.</param>
188+
/// <param name="currentStateName">The name of the state in which the action is being executed.</param>
189+
/// <param name="actionName">The name of the action being executed.</param>
190+
public void OnMachineAction(MachineId machineId, string currentStateName, string actionName) { }
191+
192+
/// <summary>
193+
/// Called when a monitor enters or exits a state.
194+
/// </summary>
195+
/// <param name="monitorTypeName">The name of the monitor entering or exiting the state.</param>
196+
/// <param name="monitorId">The id of the monitor entering or exiting the state.</param>
197+
/// <param name="stateName">The name of the state being entered or exited; if <paramref name="isInHotState"/>
198+
/// is not null, then the temperature is appended to the statename in brackets, e.g. "stateName[hot]".</param>
199+
/// <param name="isEntry">If true, this is called for a state entry; otherwise, exit.</param>
200+
/// <param name="isInHotState">If true, the monitor is in a hot state; if false, the monitor is in a cold state;
201+
/// else no liveness state is available.</param>
202+
public void OnMonitorState(string monitorTypeName, MachineId monitorId, string stateName, bool isEntry, bool? isInHotState) { }
203+
204+
/// <summary>
205+
/// Called when a monitor is about to process or has raised an event.
206+
/// </summary>
207+
/// <param name="monitorTypeName">Name of type of the monitor that will process or has raised the event.</param>
208+
/// <param name="monitorId">Id of the monitor that will process or has raised the event.</param>
209+
/// <param name="currentStateName">The name of the state in which the event is being raised.</param>
210+
/// <param name="eventName">The name of the event.</param>
211+
/// <param name="isProcessing">If true, the monitor is processing the event; otherwise it has raised it.</param>
212+
public void OnMonitorEvent(string monitorTypeName, MachineId monitorId, string currentStateName, string eventName, bool isProcessing) { }
213+
214+
/// <summary>
215+
/// Called when a monitor executes an action.
216+
/// </summary>
217+
/// <param name="monitorTypeName">Name of type of the monitor that is executing the action.</param>
218+
/// <param name="monitorId">Name of type of the monitor that is executing the action.</param>
219+
/// <param name="currentStateName">The name of the state in which the action is being executed.</param>
220+
/// <param name="actionName">The name of the action being executed.</param>
221+
public void OnMonitorAction(string monitorTypeName, MachineId monitorId, string currentStateName, string actionName) { }
222+
223+
/// <summary>
224+
/// Called for general error reporting via pre-constructed text.
225+
/// </summary>
226+
/// <param name="text">The text of the error report.</param>
227+
public void OnError(string text) { }
228+
229+
/// <summary>
230+
/// Called for errors detected by a specific scheduling strategy.
231+
/// </summary>
232+
/// <param name="strategy">The scheduling strategy that was used.</param>
233+
/// <param name="strategyDescription">More information about the scheduling strategy.</param>
234+
public void OnStrategyError(SchedulingStrategy strategy, string strategyDescription) { }
235+
50236
/// <summary>
51237
/// Disposes the logger.
52238
/// </summary>

0 commit comments

Comments
 (0)