Skip to content

Commit

Permalink
Initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
Digitalroot committed Jan 4, 2022
1 parent 368a9c0 commit 74a5119
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/discord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
secrets:
webhook_url: ${{ secrets.VALHEIM_DISCORD_TITANS_WEBHOOK_URL }}
with:
repo_name: Placeholder
repo_name: Digitalroot.Unity3d.Log
18 changes: 5 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@ jobs:
secrets:
aws-access-key-id: ${{ secrets.NUGET_S3_REPO_KEY_ID }}
aws-secret-access-key: ${{ secrets.NUGET_S3_REPO_KEY_SECRET }}
#nexus-api-key: ${{ secrets.NEXUS_API_KEY }}
#nexus-cookies-header: ${{ secrets.NEXUS_COOKIE_HEADER }}
#nuget-org-key: ${{ secrets.NUGET_ORG_PAT }}

with:
sln-file-name: Digitalroot.Valheim.Common.Placeholder
proj-file-name: Digitalroot.Valheim.Common.Placeholder
#src-path: src
#unit-test-path: UnitTests
#skip-unit-tests: true
sln-file-name: Digitalroot.Unity3d.Log
proj-file-name: Digitalroot.Unity3d.Log
skip-unit-tests: true
#force-assembly-version: true
#create-github-release: false
#aws-region: us-west-2
#is-nuget-package: false
#nuget-gh-upload: true
#nuget-s3-upload: true
nuget-gh-upload: true
nuget-s3-upload: true
#nuget-org-upload: true
#nexus-enable-upload: true
#nexus-mod-id: 000
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,19 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ico", "ico", "{C66A8E3B-31D
ico\ValheimRcon_color.png = ico\ValheimRcon_color.png
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Digitalroot.Unity3d.Log", "Digitalroot.Unity3d.Log\Digitalroot.Unity3d.Log.csproj", "{0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0FDC39E3-D8A6-434A-9DAD-5EF5A48162E5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
Expand Down
59 changes: 59 additions & 0 deletions src/Digitalroot.Unity3d.Log/Digitalroot.Unity3d.Log.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>Digitalroot.Unity3d.Log</AssemblyName>
<TargetFramework>net462</TargetFramework>
<LangVersion>9</LangVersion>
<PackageId>Digitalroot.Unity3d.Log</PackageId>
<RootNamespace>Digitalroot.Unity3d.Log</RootNamespace>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseExpression>AGPL-3.0-or-later</PackageLicenseExpression>
<Copyright>Copyright © Digitalroot Technologies 2022</Copyright>
<PackageProjectUrl>https://github.com/Digitalroot-Valheim/Digitalroot.Unity3d.Log</PackageProjectUrl>
<RepositoryUrl>https://github.com/Digitalroot-Valheim/Digitalroot.Unity3d.Log</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageIcon>ValheimRcon_black.png</PackageIcon>
<PackageIconUrl />
<PackageTags>unity, digitalroot, log, logging</PackageTags>
<Authors>Digitalroot</Authors>
<Company>Digitalroot Technologies</Company>
<Product>Digitalroot Unity3d Log</Product>
<Description>Logging Unity</Description>
<PackageReleaseNotes>Initial Release</PackageReleaseNotes>
<NeutralLanguage>en-US</NeutralLanguage>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<VersionPrefix>1.0.0</VersionPrefix>
<RestoreAdditionalProjectSources>
https://nuget.bepinex.dev/v3/index.json;
https://digitalroot-valheim-nuget.s3.us-west-2.amazonaws.com/index.json
</RestoreAdditionalProjectSources>
<IsPublishable>False</IsPublishable>
<DebugType>embedded</DebugType>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net462|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net462|AnyCPU'">
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>

<ItemGroup>
<None Include="..\ico\ValheimRcon_black.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

<ItemGroup>
<PackageReference Include="UnityEngine.Modules" Version="[2019.4.31]">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>compile</IncludeAssets>
</PackageReference>
</ItemGroup>

</Project>
65 changes: 65 additions & 0 deletions src/Digitalroot.Unity3d.Log/TraceLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System;
using System.IO;
using System.Text;
using System.Threading;
using UnityEngine;

namespace Digitalroot.Unity3d.Log
{
public class TraceLogger
{
private readonly FileInfo _traceFileInfo;
private readonly string _source;
public bool IsTraceEnabled { get; private set; }

public TraceLogger(string source, bool enableTrace)
{
try
{
_source = source;
IsTraceEnabled = enableTrace;
var logDirectoryInfo = new DirectoryInfo(Application.dataPath);
if (!logDirectoryInfo.Exists) throw new DirectoryNotFoundException($"{logDirectoryInfo.FullName} does not exist.");

var gamePath = logDirectoryInfo.Parent?.FullName ?? throw new DirectoryNotFoundException($"_logDirectoryInfo.Parent of {logDirectoryInfo.FullName} is null");
var bepInExDirectoryInfo = new DirectoryInfo(Path.Combine(gamePath, "BepInEx"));
if (!bepInExDirectoryInfo.Exists) throw new DirectoryNotFoundException($"{bepInExDirectoryInfo.FullName} does not exist.");
var bepInExLogsDirectoryInfo = new DirectoryInfo(Path.Combine(bepInExDirectoryInfo.FullName, "logs"));
if (!bepInExLogsDirectoryInfo.Exists) bepInExLogsDirectoryInfo.Create();

_traceFileInfo = new FileInfo(Path.Combine(bepInExLogsDirectoryInfo.FullName, $"{_source}.Trace.log"));
}
catch (Exception e)
{
Debug.LogException(e);
}
}

public void EnableTrace()
{
IsTraceEnabled = true;
}

public void DisableTrace()
{
IsTraceEnabled = false;
}

public void Trace(string message)
{
if (!IsTraceEnabled) return;

using var mutex = new Mutex(false, $"Digitalroot.Unity3d.TraceLogger.{_source}");
mutex.WaitOne();
try
{
var msg = $"[{"Trace",-7}:{_source,10}] {message}{Environment.NewLine}";
File.AppendAllText(_traceFileInfo.FullName, msg, Encoding.UTF8);
}
finally
{
mutex.ReleaseMutex();
}
}
}
}
13 changes: 13 additions & 0 deletions src/Digitalroot.Unity3d.Log/packages.lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": 1,
"dependencies": {
".NETFramework,Version=v4.6.2": {
"UnityEngine.Modules": {
"type": "Direct",
"requested": "[2019.4.31, 2019.4.31]",
"resolved": "2019.4.31",
"contentHash": "xZjdfGGzZw6nnrn4auRNis6WnAlsvqY1XXioEGJnSku+CylESgEt/sTLYlrbrQ0srnLfSCfx80vR8z4SsI1EuQ=="
}
}
}
}

0 comments on commit 74a5119

Please sign in to comment.