Ejemplo n.º 1
0
    // Setup on first called GetLogger<T>.
    static GlobalLogger()
    {
        // Standard LoggerFactory does not work on IL2CPP,
        // But you can use ZLogger's UnityLoggerFactory instead, it works on IL2CPP, all platforms(includes mobile).
        loggerFactory = UnityLoggerFactory.Create(builder =>
        {
            // or more configuration, you can use builder.AddFilter
            builder.SetMinimumLevel(LogLevel.Trace);

            // AddZLoggerUnityDebug is only available for Unity, it send log to UnityEngine.Debug.Log.
            // LogLevels are translate to
            // * Trace/Debug/Information -> LogType.Log
            // * Warning/Critical -> LogType.Warning
            // * Error without Exception -> LogType.Error
            // * Error with Exception -> LogException
            builder.AddZLoggerUnityDebug();

            // and other configuration(AddFileLog, etc...)
        });

        globalLogger = loggerFactory.CreateLogger("Global");

        Application.quitting += () =>
        {
            // when quit, flush unfinished log entries.
            loggerFactory.Dispose();
        };
    }
Ejemplo n.º 2
0
        // todo: port: revisit
        //static InternalLoggerFactory()
        //{
        //    // Initiate some time-consuming background jobs here,
        //    // because this class is often initialized at the earliest time.
        //    try
        //    {
        //        Class.forName(ThreadLocalRandom.class.getName(), true, InternalLoggerFactory.class.getClassLoader());
        //    } catch (Exception ignored) {
        //        // Should not fail, but it does not harm to fail.
        //    }
        //}

        static ILoggerFactory NewDefaultFactory(string name)
        {
            var f = new UnityLoggerFactory();

            f.AddProvider(new EventSourceLoggerProvider());
            f.CreateLogger(name);
            return(f);
        }
Ejemplo n.º 3
0
 private static void Init()
 {
     _logger = UnityLoggerFactory.Create(builder =>
     {
         builder.SetMinimumLevel(LogLevel.Trace);
         builder.AddZLoggerUnityDebug();
     }).CreateLogger("Global");
 }
Ejemplo n.º 4
0
        static ILogger <NewTestScript> CreaterLogger()
        {
            var factory = UnityLoggerFactory.Create(builder =>
            {
                builder.AddZLoggerUnityDebug();
            });

            var mylogger = factory.CreateLogger <NewTestScript>();

            return(mylogger);
        }
Ejemplo n.º 5
0
    public void SetupLogger(string logName)
    {
        LogManager.LoggerFactory = UnityLoggerFactory.Create(builder =>
        {
            builder.SetMinimumLevel(LogLevel.Trace);
#if !UNITY_SERVER
            builder.AddConfiguration();
            builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <ILoggerProvider, LogGUIProvider>(x => new LogGUIProvider(this, x.GetService <IOptions <ZLoggerOptions> >())));
            LoggerProviderOptions.RegisterProviderOptions <ZLoggerOptions, LogGUIProvider>(builder.Services);
#endif
            builder.AddZLoggerFile($"{logFolder}/{logName}.{logExtension}", options =>
            {
                options.PrefixFormatter = LogManager.PrefixFormatterConfigure;
            });
        });
        loggingEnabled = true;
    }
Ejemplo n.º 6
0
        public void AddManyProviderTest()
        {
            var factory = UnityLoggerFactory.Create(builder =>
            {
                builder.SetMinimumLevel(LogLevel.Debug);

                builder.AddZLoggerUnityDebug(x =>
                {
                    x.PrefixFormatter = (buf, info) => ZString.Utf8Format(buf, "UNI [{0}][{1}]", info.LogLevel, info.Timestamp.LocalDateTime);
                });
                builder.AddZLoggerFile("test_il2cpp.log", x =>
                {
                    x.PrefixFormatter = (buf, info) => ZString.Utf8Format(buf, "FIL [{0}][{1}]", info.LogLevel, info.Timestamp.LocalDateTime);
                });
            });

            var newLogger = factory.CreateLogger <NewTestScript>();

            newLogger.ZLogInformation("NEW OK INFO");
            newLogger.ZLogDebug("NEW OK DEBUG");
        }
Ejemplo n.º 7
0
        public void AddFilterTest()
        {
            var factory = UnityLoggerFactory.Create(builder =>
            {
                builder.AddFilter <ZLoggerUnityLoggerProvider>("NewTestScript", LogLevel.Information);
                builder.AddFilter <ZLoggerUnityLoggerProvider>("OldTestScript", LogLevel.Debug);
                builder.AddZLoggerUnityDebug(x =>
                {
                    x.PrefixFormatter = (buf, info) => ZString.Utf8Format(buf, "[{0}][{1}]", info.LogLevel, info.Timestamp.LocalDateTime);
                });
            });

            var newLogger = factory.CreateLogger <NewTestScript>();
            var oldLogger = factory.CreateLogger("OldTestScript");

            newLogger.ZLogInformation("NEW OK INFO");
            newLogger.ZLogDebug("NEW OK DEBUG");

            oldLogger.ZLogInformation("OLD OK INFO");
            oldLogger.ZLogDebug("OLD OK DEBUG");
        }