|
| 1 | +#region Copyright notice and license |
| 2 | + |
| 3 | +// Copyright 2019 The gRPC Authors |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, software |
| 12 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +// See the License for the specific language governing permissions and |
| 15 | +// limitations under the License. |
| 16 | + |
| 17 | +#endregion |
| 18 | + |
| 19 | +using System; |
| 20 | +using Grpc.Core; |
| 21 | +using Microsoft.Extensions.Logging; |
| 22 | + |
| 23 | +namespace Grpc.AspNetCore.Server.Internal |
| 24 | +{ |
| 25 | + internal static class GrpcServerLog |
| 26 | + { |
| 27 | + private static readonly Action<ILogger, Exception?> _unableToDisableMaxRequestBodySize = |
| 28 | + LoggerMessage.Define(LogLevel.Debug, new EventId(1, "UnableToDisableMaxRequestBodySizeLimit"), "Unable to disable the max request body size limit."); |
| 29 | + |
| 30 | + private static readonly Action<ILogger, string?, Exception?> _unsupportedRequestContentType = |
| 31 | + LoggerMessage.Define<string?>(LogLevel.Information, new EventId(2, "UnsupportedRequestContentType"), "Request content-type of '{ContentType}' is not supported."); |
| 32 | + |
| 33 | + private static readonly Action<ILogger, string?, Exception?> _unsupportedRequestProtocol = |
| 34 | + LoggerMessage.Define<string?>(LogLevel.Information, new EventId(3, "UnsupportedRequestProtocol"), "Request protocol of '{Protocol}' is not supported."); |
| 35 | + |
| 36 | + private static readonly Action<ILogger, TimeSpan, Exception?> _deadlineExceeded = |
| 37 | + LoggerMessage.Define<TimeSpan>(LogLevel.Debug, new EventId(4, "DeadlineExceeded"), "Request with timeout of {Timeout} has exceeded its deadline."); |
| 38 | + |
| 39 | + private static readonly Action<ILogger, string, Exception?> _invalidTimeoutIgnored = |
| 40 | + LoggerMessage.Define<string>(LogLevel.Debug, new EventId(5, "InvalidTimeoutIgnored"), "Invalid grpc-timeout header value '{Timeout}' has been ignored."); |
| 41 | + |
| 42 | + private static readonly Action<ILogger, string, Exception?> _errorExecutingServiceMethod = |
| 43 | + LoggerMessage.Define<string>(LogLevel.Error, new EventId(6, "ErrorExecutingServiceMethod"), "Error when executing service method '{ServiceMethod}'."); |
| 44 | + |
| 45 | + private static readonly Action<ILogger, StatusCode, Exception?> _rpcConnectionError = |
| 46 | + LoggerMessage.Define<StatusCode>(LogLevel.Information, new EventId(7, "RpcConnectionError"), "Error status code '{StatusCode}' raised."); |
| 47 | + |
| 48 | + private static readonly Action<ILogger, string, Exception?> _encodingNotInAcceptEncoding = |
| 49 | + LoggerMessage.Define<string>(LogLevel.Debug, new EventId(8, "EncodingNotInAcceptEncoding"), "Request grpc-encoding header value '{GrpcEncoding}' is not in grpc-accept-encoding."); |
| 50 | + |
| 51 | + private static readonly Action<ILogger, Exception?> _deadlineCancellationError = |
| 52 | + LoggerMessage.Define(LogLevel.Error, new EventId(9, "DeadlineCancellationError"), "Error occurred while trying to cancel the request due to deadline exceeded."); |
| 53 | + |
| 54 | + private static readonly Action<ILogger, Exception?> _readingMessage = |
| 55 | + LoggerMessage.Define(LogLevel.Debug, new EventId(10, "ReadingMessage"), "Reading message."); |
| 56 | + |
| 57 | + private static readonly Action<ILogger, Exception?> _noMessageReturned = |
| 58 | + LoggerMessage.Define(LogLevel.Trace, new EventId(11, "NoMessageReturned"), "No message returned."); |
| 59 | + |
| 60 | + private static readonly Action<ILogger, int, Type, Exception?> _deserializingMessage = |
| 61 | + LoggerMessage.Define<int, Type>(LogLevel.Trace, new EventId(12, "DeserializingMessage"), "Deserializing {MessageLength} byte message to '{MessageType}'."); |
| 62 | + |
| 63 | + private static readonly Action<ILogger, Exception?> _receivedMessage = |
| 64 | + LoggerMessage.Define(LogLevel.Trace, new EventId(13, "ReceivedMessage"), "Received message."); |
| 65 | + |
| 66 | + private static readonly Action<ILogger, Exception?> _errorReadingMessage = |
| 67 | + LoggerMessage.Define(LogLevel.Error, new EventId(14, "ErrorReadingMessage"), "Error reading message."); |
| 68 | + |
| 69 | + private static readonly Action<ILogger, Exception?> _sendingMessage = |
| 70 | + LoggerMessage.Define(LogLevel.Debug, new EventId(15, "SendingMessage"), "Sending message."); |
| 71 | + |
| 72 | + private static readonly Action<ILogger, Exception?> _messageSent = |
| 73 | + LoggerMessage.Define(LogLevel.Trace, new EventId(16, "MessageSent"), "Message sent."); |
| 74 | + |
| 75 | + private static readonly Action<ILogger, Exception?> _errorSendingMessage = |
| 76 | + LoggerMessage.Define(LogLevel.Error, new EventId(17, "ErrorSendingMessage"), "Error sending message."); |
| 77 | + |
| 78 | + private static readonly Action<ILogger, Type, int, Exception?> _serializedMessage = |
| 79 | + LoggerMessage.Define<Type, int>(LogLevel.Trace, new EventId(18, "SerializedMessage"), "Serialized '{MessageType}' to {MessageLength} byte message."); |
| 80 | + |
| 81 | + private static readonly Action<ILogger, string, Exception?> _compressingMessage = |
| 82 | + LoggerMessage.Define<string>(LogLevel.Trace, new EventId(19, "CompressingMessage"), "Compressing message with '{MessageEncoding}' encoding."); |
| 83 | + |
| 84 | + private static readonly Action<ILogger, string, Exception?> _decompressingMessage = |
| 85 | + LoggerMessage.Define<string>(LogLevel.Trace, new EventId(20, "DecompressingMessage"), "Decompressing message with '{MessageEncoding}' encoding."); |
| 86 | + |
| 87 | + public static void DeadlineExceeded(ILogger logger, TimeSpan timeout) |
| 88 | + { |
| 89 | + _deadlineExceeded(logger, timeout, null); |
| 90 | + } |
| 91 | + |
| 92 | + public static void InvalidTimeoutIgnored(ILogger logger, string timeout) |
| 93 | + { |
| 94 | + _invalidTimeoutIgnored(logger, timeout, null); |
| 95 | + } |
| 96 | + |
| 97 | + public static void ErrorExecutingServiceMethod(ILogger logger, string serviceMethod, Exception ex) |
| 98 | + { |
| 99 | + _errorExecutingServiceMethod(logger, serviceMethod, ex); |
| 100 | + } |
| 101 | + |
| 102 | + public static void RpcConnectionError(ILogger logger, StatusCode statusCode, Exception ex) |
| 103 | + { |
| 104 | + _rpcConnectionError(logger, statusCode, ex); |
| 105 | + } |
| 106 | + |
| 107 | + public static void EncodingNotInAcceptEncoding(ILogger logger, string grpcEncoding) |
| 108 | + { |
| 109 | + _encodingNotInAcceptEncoding(logger, grpcEncoding, null); |
| 110 | + } |
| 111 | + |
| 112 | + public static void DeadlineCancellationError(ILogger logger, Exception ex) |
| 113 | + { |
| 114 | + _deadlineCancellationError(logger, ex); |
| 115 | + } |
| 116 | + |
| 117 | + public static void UnableToDisableMaxRequestBodySize(ILogger logger) |
| 118 | + { |
| 119 | + _unableToDisableMaxRequestBodySize(logger, null); |
| 120 | + } |
| 121 | + |
| 122 | + public static void UnsupportedRequestContentType(ILogger logger, string? contentType) |
| 123 | + { |
| 124 | + _unsupportedRequestContentType(logger, contentType, null); |
| 125 | + } |
| 126 | + |
| 127 | + public static void UnsupportedRequestProtocol(ILogger logger, string? protocol) |
| 128 | + { |
| 129 | + _unsupportedRequestProtocol(logger, protocol, null); |
| 130 | + } |
| 131 | + |
| 132 | + public static void ReadingMessage(ILogger logger) |
| 133 | + { |
| 134 | + _readingMessage(logger, null); |
| 135 | + } |
| 136 | + |
| 137 | + public static void NoMessageReturned(ILogger logger) |
| 138 | + { |
| 139 | + _noMessageReturned(logger, null); |
| 140 | + } |
| 141 | + |
| 142 | + public static void DeserializingMessage(ILogger logger, int messageLength, Type messageType) |
| 143 | + { |
| 144 | + _deserializingMessage(logger, messageLength, messageType, null); |
| 145 | + } |
| 146 | + |
| 147 | + public static void ReceivedMessage(ILogger logger) |
| 148 | + { |
| 149 | + _receivedMessage(logger, null); |
| 150 | + } |
| 151 | + |
| 152 | + public static void ErrorReadingMessage(ILogger logger, Exception ex) |
| 153 | + { |
| 154 | + _errorReadingMessage(logger, ex); |
| 155 | + } |
| 156 | + |
| 157 | + public static void SendingMessage(ILogger logger) |
| 158 | + { |
| 159 | + _sendingMessage(logger, null); |
| 160 | + } |
| 161 | + |
| 162 | + public static void MessageSent(ILogger logger) |
| 163 | + { |
| 164 | + _messageSent(logger, null); |
| 165 | + } |
| 166 | + |
| 167 | + public static void ErrorSendingMessage(ILogger logger, Exception ex) |
| 168 | + { |
| 169 | + _errorSendingMessage(logger, ex); |
| 170 | + } |
| 171 | + |
| 172 | + public static void SerializedMessage(ILogger logger, Type messageType, int messageLength) |
| 173 | + { |
| 174 | + _serializedMessage(logger, messageType, messageLength, null); |
| 175 | + } |
| 176 | + |
| 177 | + public static void CompressingMessage(ILogger logger, string messageEncoding) |
| 178 | + { |
| 179 | + _compressingMessage(logger, messageEncoding, null); |
| 180 | + } |
| 181 | + |
| 182 | + public static void DecompressingMessage(ILogger logger, string messageEncoding) |
| 183 | + { |
| 184 | + _decompressingMessage(logger, messageEncoding, null); |
| 185 | + } |
| 186 | + } |
| 187 | +} |
0 commit comments