Skip to content

Commit ddf6239

Browse files
author
mwatson
committed
Changes for project sasquatch
1 parent 279aae7 commit ddf6239

File tree

6 files changed

+63
-13
lines changed

6 files changed

+63
-13
lines changed

Src/StackifyLib.log4net.v1_2_10/StackifyAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ protected override void Append(LoggingEvent loggingEvent)
107107
//make sure the buffer isn't overflowing
108108
//if it is skip since we can't do anything with the message
109109

110-
if (_logClient.CanQueue())
110+
if (_logClient.CanQueue() || Logger.SasquatchEnabled())
111111
{
112112
var logMsg = Translate(loggingEvent);
113113
if (logMsg != null)

Src/StackifyLib.log4net/StackifyAppender.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ protected override void Append(LoggingEvent loggingEvent)
9999
//make sure the buffer isn't overflowing
100100
//if it is skip since we can't do anything with the message
101101

102-
if (_logClient.CanQueue())
102+
if (_logClient.CanQueue() || Logger.SasquatchEnabled())
103103
{
104104
var logMsg = Translate(loggingEvent);
105105
if (logMsg != null)

Src/StackifyLib.nLog/StackifyTarget.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ protected override void Write(LogEventInfo logEvent)
7979
{
8080
//make sure the buffer isn't overflowing
8181
//if it is skip since we can't do anything with the message
82-
if (_logClient.CanQueue())
82+
if (_logClient.CanQueue() || Logger.SasquatchEnabled())
8383
{
8484
var logMsg = Translate(logEvent);
8585
if (logMsg != null)

Src/StackifyLib/Internal/Logs/LogClient.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,28 @@ public bool ErrorShouldBeSent(StackifyError error)
125125

126126
public void QueueMessage(LogMsg msg)
127127
{
128-
if (msg.id == null)
128+
if (msg == null) return;
129+
130+
int isError = 0;
131+
132+
if (msg.id == null) //should be null unless someone is using our API directly and setting it
129133
{
130-
int isError = 0;
134+
msg.id = SequentialGuid.NewGuid().ToString();
135+
}
131136

132-
if (msg.Ex != null)
133-
{
134-
isError = 1;
135-
}
136-
msg.SetLogMsgID(SequentialGuid.NewGuid().ToString(), isError, msg.Level);
137+
if (msg.Ex != null)
138+
{
139+
isError = 1;
137140
}
138141

139-
_LogQueue.QueueLogMessage(msg);
142+
//Used by Stackify profiler only
143+
msg.SetLogMsgID(msg.id, isError, msg.Level, msg.Msg, msg.data);
144+
145+
//We need to do everything up to this point for sasquatch. Even if we aren't uploading the log.
146+
if (this.CanQueue())
147+
{
148+
_LogQueue.QueueLogMessage(msg);
149+
}
140150

141151
}
142152

Src/StackifyLib/Logger.cs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public static void QueueLogObject(StackifyLib.Models.LogMsg msg)
172172
{
173173
try
174174
{
175-
if (_LogClient.CanQueue())
175+
if (_LogClient.CanQueue() || SasquatchEnabled())
176176
{
177177

178178
if (msg.Ex != null)
@@ -301,5 +301,45 @@ public static List<TraceFrame> GetCurrentStackTrace(string declaringClassName, i
301301
return frames;
302302
}
303303

304+
private static bool? _SasquatchEnabled = null;
305+
306+
public static bool SasquatchEnabled()
307+
{
308+
if (_SasquatchEnabled != null)
309+
return _SasquatchEnabled.Value;
310+
311+
var variable = Environment.GetEnvironmentVariable("StackSquatchUpdated");
312+
313+
314+
if (!string.IsNullOrEmpty(variable))
315+
{
316+
317+
DateTime updated;
318+
319+
if (DateTime.TryParse(variable, out updated))
320+
{
321+
if (updated > DateTime.UtcNow.AddHours(-1))
322+
{
323+
StackifyLib.Utils.StackifyAPILogger.Log("Sasquatch enabled", true);
324+
_SasquatchEnabled = true;
325+
}
326+
else
327+
{
328+
_SasquatchEnabled = false;
329+
}
330+
}
331+
else
332+
{
333+
_SasquatchEnabled = false;
334+
}
335+
336+
}
337+
else
338+
{
339+
_SasquatchEnabled = false;
340+
}
341+
342+
return _SasquatchEnabled.Value;
343+
}
304344
}
305345
}

Src/StackifyLib/Models/LogMsgGroup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public LogMsg()
101101

102102

103103
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.PreserveSig | MethodImplOptions.NoOptimization)]
104-
public void SetLogMsgID(string id, int isError, string logLevel)
104+
public void SetLogMsgID(string id, int isError, string logLevel, string logMsg, string logData)
105105
{
106106
this.id = id;
107107
}

0 commit comments

Comments
 (0)