2
2
// Licensed under the MIT License. See License.txt in the project root for license information.
3
3
4
4
using System ;
5
- using System . Diagnostics . Tracing ;
6
5
using Microsoft . Extensions . Logging ;
7
6
8
7
namespace Microsoft . Azure . WebJobs . Script . WebHost . Diagnostics
9
8
{
10
- internal class LinuxContainerEventGenerator : IEventGenerator
9
+ internal class LinuxContainerEventGenerator : LinuxEventGenerator
11
10
{
12
- private const string EventTimestampFormat = "MM/dd/yyyy hh:mm:ss.fff tt" ;
13
11
private readonly Action < string > _writeEvent ;
14
12
private readonly bool _consoleEnabled = true ;
15
13
@@ -31,7 +29,7 @@ public LinuxContainerEventGenerator(Action<string> writeEvent = null)
31
29
32
30
public static string DetailsEventRegex { get ; } = $ "{ ScriptConstants . LinuxFunctionDetailsEventStreamName } (?<AppName>[^,]*),(?<FunctionName>[^,]*),\\ \\ \" (?<InputBindings>.*)\\ \\ \" ,\\ \\ \" (?<OutputBindings>.*)\\ \\ \" ,(?<ScriptType>[^,]*),(?<IsDisabled>[0|1])";
33
31
34
- public void LogFunctionTraceEvent ( LogLevel level , string subscriptionId , string appName , string functionName , string eventName , string source , string details , string summary , string exceptionType , string exceptionMessage , string functionInvocationId , string hostInstanceId , string activityId )
32
+ public override void LogFunctionTraceEvent ( LogLevel level , string subscriptionId , string appName , string functionName , string eventName , string source , string details , string summary , string exceptionType , string exceptionMessage , string functionInvocationId , string hostInstanceId , string activityId )
35
33
{
36
34
string eventTimestamp = DateTime . UtcNow . ToString ( EventTimestampFormat ) ;
37
35
string hostVersion = ScriptHost . Version ;
@@ -40,23 +38,23 @@ public void LogFunctionTraceEvent(LogLevel level, string subscriptionId, string
40
38
_writeEvent ( $ "{ ScriptConstants . LinuxLogEventStreamName } { ( int ) ToEventLevel ( level ) } ,{ subscriptionId } ,{ appName } ,{ functionName } ,{ eventName } ,{ source } ,{ NormalizeString ( details ) } ,{ NormalizeString ( summary ) } ,{ hostVersion } ,{ eventTimestamp } ,{ exceptionType } ,{ NormalizeString ( exceptionMessage ) } ,{ functionInvocationId } ,{ hostInstanceId } ,{ activityId } ") ;
41
39
}
42
40
43
- public void LogFunctionMetricEvent ( string subscriptionId , string appName , string functionName , string eventName , long average , long minimum , long maximum , long count , DateTime eventTimestamp )
41
+ public override void LogFunctionMetricEvent ( string subscriptionId , string appName , string functionName , string eventName , long average , long minimum , long maximum , long count , DateTime eventTimestamp )
44
42
{
45
43
string hostVersion = ScriptHost . Version ;
46
44
47
45
_writeEvent ( $ "{ ScriptConstants . LinuxMetricEventStreamName } { subscriptionId } ,{ appName } ,{ functionName } ,{ eventName } ,{ average } ,{ minimum } ,{ maximum } ,{ count } ,{ hostVersion } ,{ eventTimestamp . ToString ( EventTimestampFormat ) } ") ;
48
46
}
49
47
50
- public void LogFunctionDetailsEvent ( string siteName , string functionName , string inputBindings , string outputBindings , string scriptType , bool isDisabled )
48
+ public override void LogFunctionDetailsEvent ( string siteName , string functionName , string inputBindings , string outputBindings , string scriptType , bool isDisabled )
51
49
{
52
50
_writeEvent ( $ "{ ScriptConstants . LinuxFunctionDetailsEventStreamName } { siteName } ,{ functionName } ,{ NormalizeString ( inputBindings ) } ,{ NormalizeString ( outputBindings ) } ,{ scriptType } ,{ ( isDisabled ? 1 : 0 ) } ") ;
53
51
}
54
52
55
- public void LogFunctionExecutionAggregateEvent ( string siteName , string functionName , long executionTimeInMs , long functionStartedCount , long functionCompletedCount , long functionFailedCount )
53
+ public override void LogFunctionExecutionAggregateEvent ( string siteName , string functionName , long executionTimeInMs , long functionStartedCount , long functionCompletedCount , long functionFailedCount )
56
54
{
57
55
}
58
56
59
- public void LogFunctionExecutionEvent ( string executionId , string siteName , int concurrency , string functionName , string invocationId , string executionStage , long executionTimeSpan , bool success )
57
+ public override void LogFunctionExecutionEvent ( string executionId , string siteName , int concurrency , string functionName , string invocationId , string executionStage , long executionTimeSpan , bool success )
60
58
{
61
59
}
62
60
@@ -67,43 +65,5 @@ private void ConsoleWriter(string evt)
67
65
Console . WriteLine ( evt ) ;
68
66
}
69
67
}
70
-
71
- internal static string NormalizeString ( string value )
72
- {
73
- // need to remove newlines for csv output
74
- value = value . Replace ( Environment . NewLine , " " ) ;
75
-
76
- // Wrap string literals in enclosing quotes
77
- // For string columns that may contain quotes and/or
78
- // our delimiter ',', before writing the value we
79
- // enclose in quotes. This allows us to define matching
80
- // groups based on quotes for these values.
81
- return $ "\" { value } \" ";
82
- }
83
-
84
- /// <summary>
85
- /// Performs the same mapping from <see cref="LogLevel"/> to <see cref="EventLevel"/>
86
- /// that is performed for ETW event logging in <see cref="EtwEventGenerator"/>, so we
87
- /// have consistent log levels across platforms.
88
- /// </summary>
89
- internal static EventLevel ToEventLevel ( LogLevel level )
90
- {
91
- switch ( level )
92
- {
93
- case LogLevel . Trace :
94
- case LogLevel . Debug :
95
- return EventLevel . Verbose ;
96
- case LogLevel . Information :
97
- return EventLevel . Informational ;
98
- case LogLevel . Warning :
99
- return EventLevel . Warning ;
100
- case LogLevel . Error :
101
- return EventLevel . Error ;
102
- case LogLevel . Critical :
103
- return EventLevel . Critical ;
104
- default :
105
- return EventLevel . LogAlways ;
106
- }
107
- }
108
68
}
109
69
}
0 commit comments