DayZ
  • 🌶️FoxApo DayZ Mods
  • ⚙️Modding | Repacking
  • MODS
    • 👻CRDTN Creatures
      • Phantom
      • config.cpp
    • 💯CRDTN Core
      • File Logger
        • Logger Player Connected
      • Rest Api
        • Getting started
      • Event Handler
      • Notifications UI
      • Admin Utils
      • NPCs
    • 📺CRDTN Gui
    • 📦CRDTN Krabice
    • 🫂CRDTN Factions
    • ⁉️CRDTN Quests
      • ⁉️Getting started
      • 💻Client Side
      • 🖥️Server Side
        • ⚙️Installation
          • 🛠️Quests.json
            • ⚔️Goal
            • 🎁Reward
          • 🌎Quest Events
            • Teleport quest with quest event (server)
        • ⚙️Quest & Goal Types
          • 📜Turn-In goal
          • 📜Kill goal
          • 📜Trade goal
          • 📜Craft goal
          • 📜Action goal
          • 📜Explore goal
        • ⚙️Rewards
        • ⚙️Quest NPCs
    • 🔥CRDTN Fire Regen
      • Config
    • 🔊CRDTN Sounds
    • 🚪CRDTN Locked Doors
      • Config
      • How To
      • config.cpp
Powered by GitBook
On this page
  1. MODS
  2. CRDTN Core

File Logger

With the latest update I have added a custom file logger, which you can create in your code and save the logging results to your custom folder.

PreviousCRDTN CoreNextLogger Player Connected

Last updated 1 year ago

Let's create a logger with name TestLogger

This modded script should be created in Module #3 - 3_Game, so you can access that across the whole app. Otherwise you can choose a different place. I just think it's convenient to have it accessible from most of the codebase of DayZ Server.

// Create a modded class for DayZGame script
modded class DayZGame
{
    override void CRDTN_OnGameInit()
    {
        super.CRDTN_OnGameInit();
        CRDTN_FileLogger.CreateInstance("TestLogger");
        // instantiates the instance of FileLogger with key - TestLogger
        // 
    }
};

Congratulations, you have create your logger The file will be saved in $profile/CRDTN/Logs/TestLogger.log

If you want a different location for your logs, you must rewrite the constant

CFG_CRDTN_LogsFolder

Now you can access it from your code wherever you need by using the following code snippet.

CRDTN_FileLogger.GetInstance("TestLogger").Log("Some of your message");

You can also cache the reference for more convenient work like below.

class TestPlugin : CRDTN_PluginBase
{
    private ref CRDTN_FileLogger m_TestLogger;
    
    override void OnInit()
    {
        super.OnInit();
        m_TestLogger = CRDTN_FileLogger.GetInstance("TestLogger");
    }
    
    CRDTN_FileLogger GetTestLogger()
    {
        return m_TestLogger;
    }
};

TestPlugin GetTestPlugin()
{
    if (!GetGame().IsServer())
    {
        return NULL;
    }

    if (GetPluginManager() && GetPluginManager().GetPluginByType(TestPlugin))
    {
        return TestPlugin.Cast(GetPluginManager().GetPluginByType(TestPlugin));
    }

    return NULL;
}

CRDTN_TestLogger GetLogger()
{
    return GetTestPlugin().GetTestLogger();
}

If you have followed the code above, you now can just call in the code

GetLogger().Log("Some message");

Be aware, that the example showcases usage of PluginBase which is part of module #4 so you can use the GetLogger() method only within module #4 and #5.

💯
😂