Skip to content

Commit

Permalink
✨ A lot more to unravel
Browse files Browse the repository at this point in the history
- Added customizable text/background colors
- All 8 severity levels form the Syslog Severity Logs spec
- Library is now called EasyLogPlus
- there's probably more but i forgot
  • Loading branch information
asoji committed Aug 26, 2022
1 parent 0237d4f commit e34803b
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 57 deletions.
13 changes: 13 additions & 0 deletions .idea/.idea.EasyLogPlus/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/.idea.EasyLogPlus/.idea/discord.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/.idea.EasyLogPlus/.idea/indexLayout.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/.idea.EasyLogPlus/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions EasyLog/Config.cs

This file was deleted.

2 changes: 1 addition & 1 deletion EasyLog.sln → EasyLogPlus.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VisualStudioVersion = 16.0.32106.194
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Example", "Example\Example.csproj", "{DE22B76E-763A-4019-A1D8-07EEF4592308}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyLog", "EasyLog\EasyLog.csproj", "{869CD7D8-113A-4D0B-B658-842DF1D5241F}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EasyLogPlus", "EasyLogPlus\EasyLogPlus.csproj", "{869CD7D8-113A-4D0B-B658-842DF1D5241F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
26 changes: 26 additions & 0 deletions EasyLogPlus/Config.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyLogPlus {
public class Config {
public bool ShowDate = true;
public bool Console = true;
public bool UseColon = true;

public string LogPath = Environment.CurrentDirectory + $@"\Application.log";

public ConsoleColor DebugForeground = ConsoleColor.Blue;
public ConsoleColor InfoForeground = ConsoleColor.Gray;
public ConsoleColor NoticeForeground = ConsoleColor.Green;
public ConsoleColor WarningForeground = ConsoleColor.DarkYellow;
public ConsoleColor ErrorForeground = ConsoleColor.Red;

public ConsoleColor CriticalBackground = ConsoleColor.DarkRed;
public ConsoleColor AlertBackground = ConsoleColor.DarkBlue;
public ConsoleColor EmergencyBackground = ConsoleColor.DarkMagenta;
}
}
10 changes: 5 additions & 5 deletions EasyLog/EasyLog.csproj → EasyLogPlus/EasyLogPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
<OutputType>Library</OutputType>
<TargetVersion>net6.0</TargetVersion>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<PackageId>EasyLog</PackageId>
<Version>1.0.6-pre1</Version>
<Authors>0x74</Authors>
<PackageDescription>Simple and easy to use logging system.</PackageDescription>
<RepositoryUrl>https://github.com/asoji/EasyLog</RepositoryUrl>
<PackageId>EasyLogPlus</PackageId>
<Version>1.0.6-pre2</Version>
<Authors>0x74, extended by asoji</Authors>
<PackageDescription>Simple and easy to use logging system. Extended by asoji.</PackageDescription>
<RepositoryUrl>https://github.com/asoji/EasyLogPlus</RepositoryUrl>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Data.DataSetExtensions" Version="4.5.0" />
Expand Down
78 changes: 64 additions & 14 deletions EasyLog/Logger.cs → EasyLogPlus/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;

namespace EasyLog {
namespace EasyLogPlus {
public class Logger {
public Config cfg;
public bool isInit = false;
Expand All @@ -13,12 +13,16 @@ public void InitLogger() {
isInit = true;
}

enum LogLevel {
Info = 0,
Debug,
Warning,
Error,
Critical
enum LogLevel { // trying to conform to the Syslog standard, found here
// https://en.wikipedia.org/wiki/Syslog#Severity_level
Debug = 7,
Info = 6,
Notice = 5,
Warning = 4,
Error = 3,
Critical = 2,
Alert = 1,
Emergency = 0
}

public string ProcessLogText(int level) {
Expand All @@ -29,13 +33,17 @@ public string ProcessLogText(int level) {
object text = string.Empty;

switch (level) {
case (int)LogLevel.Debug:
if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | ";
text += "DEBUG";
break;
case (int)LogLevel.Info:
if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | ";
text += "INFO";
break;
case (int)LogLevel.Debug:
case (int)LogLevel.Notice:
if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | ";
text += "DEBUG";
text += "NOTICE";
break;
case (int)LogLevel.Warning:
if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | ";
Expand All @@ -49,6 +57,14 @@ public string ProcessLogText(int level) {
if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | ";
text += "CRITICAL";
break;
case (int)LogLevel.Alert:
if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | ";
text += "ALERT";
break;
case (int)LogLevel.Emergency:
if (cfg.ShowDate) text += $"[{DateTime.Now.ToString()}] | ";
text += "EMERGENCY";
break;
}

switch (cfg.UseColon) {
Expand All @@ -66,7 +82,7 @@ public string ProcessLogText(int level) {
public void Debug(object Content) {
string LogText = ProcessLogText((int)LogLevel.Debug) + Content;
if (cfg.Console) {
Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.Blue);
Console.WriteLine(LogText, Console.ForegroundColor = cfg.DebugForeground);
Console.ForegroundColor = ConsoleColor.White;
}

Expand All @@ -76,7 +92,17 @@ public void Debug(object Content) {
public void Info(object Content) {
string LogText = ProcessLogText((int)LogLevel.Info) + Content;
if (cfg.Console) {
Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.White);
Console.WriteLine(LogText, Console.ForegroundColor = cfg.InfoForeground);
Console.ForegroundColor = ConsoleColor.White;
}

File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine);
}

public void Notice(object Content) {
string LogText = ProcessLogText((int)LogLevel.Notice) + Content;
if (cfg.Console) {
Console.WriteLine(LogText, Console.ForegroundColor = cfg.NoticeForeground);
Console.ForegroundColor = ConsoleColor.White;
}

Expand All @@ -86,7 +112,7 @@ public void Info(object Content) {
public void Warning(object Content) {
string LogText = ProcessLogText((int)LogLevel.Warning) + Content;
if (cfg.Console) {
Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.DarkYellow);
Console.WriteLine(LogText, Console.ForegroundColor = cfg.WarningForeground);
Console.ForegroundColor = ConsoleColor.White;
}

Expand All @@ -96,7 +122,7 @@ public void Warning(object Content) {
public void Error(object Content) {
string LogText = ProcessLogText((int)LogLevel.Error) + Content;
if (cfg.Console) {
Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.Red);
Console.WriteLine(LogText, Console.ForegroundColor = cfg.ErrorForeground);
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
}
Expand All @@ -108,7 +134,31 @@ public void Critical(object Content) {
string LogText = ProcessLogText((int)LogLevel.Critical) + Content;
if (cfg.Console) {
Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.White,
Console.BackgroundColor = ConsoleColor.DarkRed);
Console.BackgroundColor = cfg.CriticalBackground);
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
}

File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine);
}

public void Alert(object Content) {
string LogText = ProcessLogText((int)LogLevel.Alert) + Content;
if (cfg.Console) {
Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.White,
Console.BackgroundColor = cfg.AlertBackground);
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
}

File.AppendAllText(cfg.LogPath, LogText + Environment.NewLine);
}

public void Emergency(object Content) {
string LogText = ProcessLogText((int)LogLevel.Emergency) + Content;
if (cfg.Console) {
Console.WriteLine(LogText, Console.ForegroundColor = ConsoleColor.White,
Console.BackgroundColor = cfg.EmergencyBackground);
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("EasyLog")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyTitle("EasyLogPlus")]
[assembly: AssemblyDescription("Simple and easy to use logging system. Extended by asoji.")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EasyLog")]
[assembly: AssemblyProduct("EasyLogPlus")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand All @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.6.0")]
[assembly: AssemblyFileVersion("1.0.6.0")]
2 changes: 1 addition & 1 deletion Example/Example.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EasyLog\EasyLog.csproj" />
<ProjectReference Include="..\EasyLogPlus\EasyLogPlus.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.336902">
Expand Down
18 changes: 12 additions & 6 deletions Example/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.IO;
using EasyLog;
using EasyLogPlus;

namespace Example {
class Program {
Expand All @@ -9,21 +9,27 @@ class Program {

//If you want change logger settings create function like this and call it when application starts
static void SetConfig() {
cfg.LogPath = Environment.CurrentDirectory + @"\Application.log"; //Set path where you want log to be saved
cfg.ShowDate = true; //If this is set to true it will add date to the log
cfg.Console = true; //If this is set to true it will print the log to Console too
cfg.LogPath = Environment.CurrentDirectory + @"\Application.log"; // Set path where you want log to be saved
cfg.ShowDate = true; // If this is set to true it will add date to the log
cfg.Console = true; // If this is set to true it will print the log to Console too
}

static void Main(string[] args) {
SetConfig();
log.cfg = cfg;
log.InitLogger(); //Call this to init logger
log.Info("This is info text!");
log.InitLogger(); // Call this to init logger

log.Debug("This is debug text!");
log.Info("This is info text!");
log.Notice("This is notice text!");
log.Warning("This is warning text!");
log.Error("This is error text!");
log.Critical("This is critical text!");
log.Alert("This is alert text!");
log.Emergency("This is emergency text!");

log.Info("Press any key to stop this example!");

Console.ReadKey();
}
}
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
MIT License

Copyright (c) 2022 0x74
Copyright (c) 2022 Asoji

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit e34803b

Please sign in to comment.