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 IRavenClient _raven;
|
||||||
private readonly bool _errorsInChat;
|
private readonly bool _errorsInChat;
|
||||||
|
|
||||||
public ErrorHandler(IGeekbotLogger logger, ITranslationHandler translation, bool errorsInChat)
|
public ErrorHandler(IGeekbotLogger logger, ITranslationHandler translation, RunParameters runParameters)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_translation = translation;
|
_translation = translation;
|
||||||
_errorsInChat = errorsInChat;
|
_errorsInChat = runParameters.ExposeErrors;
|
||||||
|
|
||||||
var sentryDsn = Environment.GetEnvironmentVariable("SENTRY");
|
var sentryDsn = runParameters.SentryEndpoint;
|
||||||
if (!string.IsNullOrEmpty(sentryDsn))
|
if (!string.IsNullOrEmpty(sentryDsn))
|
||||||
{
|
{
|
||||||
_raven = new RavenClient(sentryDsn) { Release = Constants.BotVersion(), Environment = "Production" };
|
_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 NLog.Logger _logger;
|
||||||
private readonly JsonSerializerSettings _serializerSettings;
|
private readonly JsonSerializerSettings _serializerSettings;
|
||||||
|
|
||||||
public GeekbotLogger(RunParameters runParameters, bool sumologicActive)
|
public GeekbotLogger(RunParameters runParameters)
|
||||||
{
|
{
|
||||||
_logAsJson = sumologicActive || runParameters.LogJson;
|
_logAsJson = !string.IsNullOrEmpty(runParameters.SumologicEndpoint) || runParameters.LogJson;
|
||||||
_logger = LoggerFactory.CreateNLog(runParameters, sumologicActive);
|
_logger = LoggerFactory.CreateNLog(runParameters);
|
||||||
_serializerSettings = new JsonSerializerSettings
|
_serializerSettings = new JsonSerializerSettings
|
||||||
{
|
{
|
||||||
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
|
ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
|
||||||
|
|
|
@ -9,18 +9,18 @@ namespace Geekbot.net.Lib.Logger
|
||||||
{
|
{
|
||||||
public class LoggerFactory
|
public class LoggerFactory
|
||||||
{
|
{
|
||||||
public static NLog.Logger CreateNLog(RunParameters runParameters, bool sumologicActive)
|
public static NLog.Logger CreateNLog(RunParameters runParameters)
|
||||||
{
|
{
|
||||||
var config = new LoggingConfiguration();
|
var config = new LoggingConfiguration();
|
||||||
|
|
||||||
if (sumologicActive)
|
if (!string.IsNullOrEmpty(runParameters.SumologicEndpoint))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Logging Geekbot Logs to Sumologic");
|
Console.WriteLine("Logging Geekbot Logs to Sumologic");
|
||||||
config.LoggingRules.Add(
|
config.LoggingRules.Add(
|
||||||
new LoggingRule("*", LogLevel.Debug, LogLevel.Fatal,
|
new LoggingRule("*", LogLevel.Debug, LogLevel.Fatal,
|
||||||
new SumoLogicTarget()
|
new SumoLogicTarget()
|
||||||
{
|
{
|
||||||
Url = Environment.GetEnvironmentVariable("GEEKBOT_SUMO"),
|
Url = runParameters.SumologicEndpoint,
|
||||||
SourceName = "GeekbotLogger",
|
SourceName = "GeekbotLogger",
|
||||||
Layout = "${message}",
|
Layout = "${message}",
|
||||||
UseConsoleLog = false,
|
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)")]
|
[Option("api-port", HelpText = "Port on which the WebApi listens (default: 12995) (env: API_PORT)")]
|
||||||
public string ApiPort { get; set; } = ParamFallback("API_PORT", "12995");
|
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 *
|
* Helper Functions *
|
||||||
************************************/
|
************************************/
|
||||||
|
|
|
@ -58,8 +58,7 @@ namespace Geekbot.net
|
||||||
logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
logo.AppendLine(@" \____|_____|_____|_|\_\____/ \___/ |_|");
|
||||||
logo.AppendLine($"Version {Constants.BotVersion()} ".PadRight(41, '='));
|
logo.AppendLine($"Version {Constants.BotVersion()} ".PadRight(41, '='));
|
||||||
Console.WriteLine(logo.ToString());
|
Console.WriteLine(logo.ToString());
|
||||||
var sumologicActive = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GEEKBOT_SUMO"));
|
var logger = new GeekbotLogger(runParameters);
|
||||||
var logger = new GeekbotLogger(runParameters, sumologicActive);
|
|
||||||
logger.Information(LogSource.Geekbot, "Starting...");
|
logger.Information(LogSource.Geekbot, "Starting...");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -169,7 +168,7 @@ namespace Geekbot.net
|
||||||
var randomNumberGenerator = new RandomNumberGenerator();
|
var randomNumberGenerator = new RandomNumberGenerator();
|
||||||
var kvMemoryStore = new KvInInMemoryStore();
|
var kvMemoryStore = new KvInInMemoryStore();
|
||||||
var translationHandler = new TranslationHandler(_logger, _guildSettingsManager);
|
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(_userRepository);
|
||||||
services.AddSingleton<IGeekbotLogger>(_logger);
|
services.AddSingleton<IGeekbotLogger>(_logger);
|
||||||
|
|
Loading…
Reference in a new issue