Exemple #1
0
        private bool ChangeLoggerLevel(HttpRequest request, string path)
        {
            PathString epPath = new PathString(path);

            if (request.Path.StartsWithSegments(epPath, out PathString remaining))
            {
                if (remaining.HasValue)
                {
                    string loggerName = remaining.Value.TrimStart('/');

                    var change = ((LoggersEndpoint)_endpoint).DeserializeRequest(request.Body);

                    change.TryGetValue("configuredLevel", out string level);

                    _logger?.LogDebug("Change Request: {0}, {1}", loggerName, level ?? "RESET");
                    if (!string.IsNullOrEmpty(loggerName))
                    {
                        var changeReq = new LoggersChangeRequest(loggerName, level);
                        HandleRequest(changeReq);
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #2
0
        internal protected async Task HandleLoggersRequestAsync(HttpContext context)
        {
            HttpRequest  request  = context.Request;
            HttpResponse response = context.Response;

            if (context.Request.Method.Equals("POST"))
            {
                // POST - change a logger level
                logger?.LogDebug("Incoming path: {0}", request.Path.Value);
                PathString epPath = new PathString(endpoint.Path);
                PathString remaining;
                if (request.Path.StartsWithSegments(epPath, out remaining))
                {
                    if (remaining.HasValue)
                    {
                        string loggerName = remaining.Value.TrimStart('/');

                        var change = Deserialize(request.Body);

                        string level = null;
                        change.TryGetValue("configuredLevel", out level);

                        logger?.LogDebug("Change Request: {0}, {1}", loggerName, level);
                        if (!string.IsNullOrEmpty(loggerName) && !string.IsNullOrEmpty(level))
                        {
                            var changeReq = new LoggersChangeRequest(loggerName, level);
                            base.HandleRequest(changeReq);
                            response.StatusCode = (int)HttpStatusCode.OK;
                            return;
                        }
                    }
                }

                response.StatusCode = (int)HttpStatusCode.BadRequest;
                return;
            }

            // GET request
            var serialInfo = base.HandleRequest(null);

            logger?.LogDebug("Returning: {0}", serialInfo);
            response.Headers.Add("Content-Type", "application/vnd.spring-boot.actuator.v1+json");
            await context.Response.WriteAsync(serialInfo);
        }
        public virtual Dictionary <string, object> DoInvoke(IDynamicLoggerProvider provider, LoggersChangeRequest request)
        {
            Dictionary <string, object> result = new Dictionary <string, object>();

            if (request != null)
            {
                SetLogLevel(provider, request.Name, request.Level);
            }
            else
            {
                AddLevels(result);
                var configuration = GetLoggerConfigurations(provider);
                Dictionary <string, LoggerLevels> loggers = new Dictionary <string, LoggerLevels>();
                foreach (var c in configuration.OrderBy(entry => entry.Name))
                {
                    _logger.LogTrace("Adding " + c.ToString());
                    LoggerLevels lv = new LoggerLevels(c.ConfiguredLevel, c.EffectiveLevel);
                    loggers.Add(c.Name, lv);
                }

                result.Add("loggers", loggers);
            }

            return(result);
        }
        public override Dictionary <string, object> Invoke(LoggersChangeRequest request)
        {
            _logger?.LogDebug("Invoke({0})", request);

            return(DoInvoke(_cloudFoundryLoggerProvider, request));
        }
        public override Dictionary <string, object> Invoke(LoggersChangeRequest request)
        {
            _logger?.LogDebug("Invoke({0})", SecurityUtilities.SanitizeInput(request?.ToString()));

            return(DoInvoke(_cloudFoundryLoggerProvider, request));
        }