Add Sumologic and Sentry to the run parameters
This commit is contained in:
parent
f23b8099f1
commit
3213e10b88
5 changed files with 21 additions and 12 deletions
|
@ -18,13 +18,13 @@ namespace Geekbot.net.Lib.ErrorHandling
|
|||
private readonly IRavenClient _raven;
|
||||
private readonly bool _errorsInChat;
|
||||
|
||||
public ErrorHandler(IGeekbotLogger logger, ITranslationHandler translation, bool errorsInChat)
|
||||
public ErrorHandler(IGeekbotLogger logger, ITranslationHandler translation, RunParameters runParameters)
|
||||
{
|
||||
_logger = logger;
|
||||
_translation = translation;
|
||||
_errorsInChat = errorsInChat;
|
||||
_errorsInChat = runParameters.ExposeErrors;
|
||||
|
||||
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY");
|
||||
var sentryDsn = runParameters.SentryEndpoint;
|
||||
if (!string.IsNullOrEmpty(sentryDsn))
|
||||
{
|
||||
_raven = new RavenClient(sentryDsn) { Release = Constants.BotVersion(), Environment = "Production" };
|
||||
|
|
|
@ -9,10 +9,10 @@ namespace Geekbot.net.Lib.Logger
|
|||
private readonly NLog.Logger _logger;
|
||||
private readonly JsonSerializerSettings _serializerSettings;
|
||||
|
||||
public GeekbotLogger(RunParameters runParameters, bool sumologicActive)
|
||||
public GeekbotLogger(RunParameters runParameters)
|
||||
{
|
||||
_logAsJson = sumologicActive || runParameters.LogJson;
|
||||
_logger = LoggerFactory.CreateNLog(runParameters, sumologicActive);
|
||||
_logAsJson = !string.IsNullOrEmpty(runParameters.SumologicEndpoint) || runParameters.LogJson;
|
||||
_logger = LoggerFactory.CreateNLog(runParameters);
|
||||
_serializerSettings = new JsonSerializerSettings
|
||||
{
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
|
||||
|
|
|
@ -9,18 +9,18 @@ namespace Geekbot.net.Lib.Logger
|
|||
{
|
||||
public class LoggerFactory
|
||||
{
|
||||
public static NLog.Logger CreateNLog(RunParameters runParameters, bool sumologicActive)
|
||||
public static NLog.Logger CreateNLog(RunParameters runParameters)
|
||||
{
|
||||
var config = new LoggingConfiguration();
|
||||
|
||||
if (sumologicActive)
|
||||
if (!string.IsNullOrEmpty(runParameters.SumologicEndpoint))
|
||||
{
|
||||
Console.WriteLine("Logging Geekbot Logs to Sumologic");
|
||||
config.LoggingRules.Add(
|
||||
new LoggingRule("*", LogLevel.Debug, LogLevel.Fatal,
|
||||
new SumoLogicTarget()
|
||||
{
|
||||
Url = Environment.GetEnvironmentVariable("GEEKBOT_SUMO"),
|
||||
Url = runParameters.SumologicEndpoint,
|
||||
SourceName = "GeekbotLogger",
|
||||
Layout = "${message}",
|
||||
UseConsoleLog = false,
|
||||
|
|
|
@ -67,6 +67,16 @@ namespace Geekbot.net.Lib
|
|||
[Option("api-port", HelpText = "Port on which the WebApi listens (default: 12995) (env: API_PORT)")]
|
||||
public string ApiPort { get; set; } = ParamFallback("API_PORT", "12995");
|
||||
|
||||
/************************************
|
||||
* Intergrations *
|
||||
************************************/
|
||||
|
||||
[Option("sumologic", HelpText = "Sumologic endpoint for logging (default: null) (env: SUMOLOGIC)")]
|
||||
public string SumologicEndpoint { get; set; } = ParamFallback("SUMOLOGIC");
|
||||
|
||||
[Option("sentry", HelpText = "Sentry endpoint for error reporting (default: null) (env: SENTRY)")]
|
||||
public string SentryEndpoint { get; set; } = ParamFallback("SENTRY");
|
||||
|
||||
/************************************
|
||||
* Helper Functions *
|
||||
************************************/
|
||||
|
|
|
@ -58,8 +58,7 @@ namespace Geekbot.net
|
|||
logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
||||
logo.AppendLine($"Version {Constants.BotVersion()} ".PadRight(41, '='));
|
||||
Console.WriteLine(logo.ToString());
|
||||
var sumologicActive = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GEEKBOT_SUMO"));
|
||||
var logger = new GeekbotLogger(runParameters, sumologicActive);
|
||||
var logger = new GeekbotLogger(runParameters);
|
||||
logger.Information(LogSource.Geekbot, "Starting...");
|
||||
try
|
||||
{
|
||||
|
@ -169,7 +168,7 @@ namespace Geekbot.net
|
|||
var randomNumberGenerator = new RandomNumberGenerator();
|
||||
var kvMemoryStore = new KvInInMemoryStore();
|
||||
var translationHandler = new TranslationHandler(_logger, _guildSettingsManager);
|
||||
var errorHandler = new ErrorHandler(_logger, translationHandler, _runParameters.ExposeErrors);
|
||||
var errorHandler = new ErrorHandler(_logger, translationHandler, _runParameters);
|
||||
|
||||
services.AddSingleton(_userRepository);
|
||||
services.AddSingleton<IGeekbotLogger>(_logger);
|
||||
|
|
Loading…
Reference in a new issue