2
2
// Licensed under the MIT License.
3
3
4
4
import * as types from '@azure/functions' ;
5
- import { ContextBindings , Logger , RetryContext , TraceContext , TriggerMetadata } from '@azure/functions' ;
5
+ import { ContextBindings , RetryContext , TraceContext , TriggerMetadata } from '@azure/functions' ;
6
6
import { RpcInvocationRequest , RpcLog , RpcParameterBinding } from '@azure/functions-core' ;
7
7
import { convertKeysToCamelCase } from './converters/convertKeysToCamelCase' ;
8
8
import { fromRpcRetryContext , fromRpcTraceContext , fromTypedData } from './converters/RpcConverters' ;
@@ -58,9 +58,9 @@ class InvocationContext implements types.InvocationContext {
58
58
triggerMetadata : TriggerMetadata ;
59
59
traceContext ?: TraceContext ;
60
60
retryContext ?: RetryContext ;
61
- log : Logger ;
62
61
req ?: Request ;
63
62
res ?: Response ;
63
+ #userLogCallback: UserLogCallback ;
64
64
65
65
constructor ( info : FunctionInfo , request : RpcInvocationRequest , userLogCallback : UserLogCallback ) {
66
66
this . invocationId = < string > request . invocationId ;
@@ -72,16 +72,33 @@ class InvocationContext implements types.InvocationContext {
72
72
if ( request . traceContext ) {
73
73
this . traceContext = fromRpcTraceContext ( request . traceContext ) ;
74
74
}
75
+ this . #userLogCallback = userLogCallback ;
75
76
76
77
this . bindings = { } ;
78
+ }
79
+
80
+ log ( ...args : any [ ] ) : void {
81
+ this . #userLogCallback( RpcLog . Level . Information , ...args ) ;
82
+ }
83
+
84
+ trace ( ...args : any [ ] ) : void {
85
+ this . #userLogCallback( RpcLog . Level . Trace , ...args ) ;
86
+ }
87
+
88
+ debug ( ...args : any [ ] ) : void {
89
+ this . #userLogCallback( RpcLog . Level . Debug , ...args ) ;
90
+ }
91
+
92
+ info ( ...args : any [ ] ) : void {
93
+ this . #userLogCallback( RpcLog . Level . Information , ...args ) ;
94
+ }
95
+
96
+ warn ( ...args : any [ ] ) : void {
97
+ this . #userLogCallback( RpcLog . Level . Warning , ...args ) ;
98
+ }
77
99
78
- // Log message that is tied to function invocation
79
- this . log = Object . assign ( ( ...args : any [ ] ) => userLogCallback ( RpcLog . Level . Information , ...args ) , {
80
- error : ( ...args : any [ ] ) => userLogCallback ( RpcLog . Level . Error , ...args ) ,
81
- warn : ( ...args : any [ ] ) => userLogCallback ( RpcLog . Level . Warning , ...args ) ,
82
- info : ( ...args : any [ ] ) => userLogCallback ( RpcLog . Level . Information , ...args ) ,
83
- verbose : ( ...args : any [ ] ) => userLogCallback ( RpcLog . Level . Trace , ...args ) ,
84
- } ) ;
100
+ error ( ...args : any [ ] ) : void {
101
+ this . #userLogCallback( RpcLog . Level . Error , ...args ) ;
85
102
}
86
103
}
87
104
0 commit comments