forked from maziac/DeZogPlugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLog.cs
86 lines (76 loc) · 2.44 KB
/
Log.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace DeZogPlugin
{
/**
* This static class implements a simple logging functionality.
* Use e.g.
* ~~~
* if(Log.Enabled)
* Log.Write("bytesRead={0}, MsgLength={1}", bytesRead, state.MsgLength);
* ~~~
*
* Usage:
* - if(Log.Enabled) Log.Write(....
* For conditional logs. Logs will not appear if logging is not enabled.
* - Log.Write(....
* For Logs that will always appear. E.g. for errors or exceptions.
* - Log.ConsoleWrite(...
* For 'normal' user information. These logs will always be printed also on the console.
* This is for future, if I decide to log also into a file. Then the normal Log.Write
* would not be visible to the user.
*/
public class Log
{
/// <summary>
/// Use to enable logging.
/// </summary>
static public bool Enabled = false;
/// <summary>
/// Use this to print in front of each log.
/// Is done automatically normally.
/// </summary>
static public string Prefix = "Dezog Plugin: ";
/// <summary>
/// To decide when to print the Prefix.
/// </summary>
static private int PrefixColumn = 0;
/**
* Writes a formatted string.
* E.g. use Log.Write("bytesRead={0}, MsgLength={1}", bytesRead, state.MsgLength);
*/
static public void Write(string format, params object[] args)
{
if(PrefixColumn==0)
Console.Write(Prefix);
string text = string.Format(format, args);
Console.Write(text);
PrefixColumn += text.Length;
}
/**
* Writes a formatted string and adds a newline.
* E.g. use Log.Write("bytesRead={0}, MsgLength={1}", bytesRead, state.MsgLength);
*/
static public void WriteLine(string format, params object[] args)
{
if (PrefixColumn == 0)
Console.Write(Prefix);
string text = string.Format(format, args);
Console.WriteLine(text);
PrefixColumn = 0;
}
/**
* Writes an empty line.
*/
static public void WriteLine()
{
Console.WriteLine();
PrefixColumn = 0;
}
}
}