Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Make logging part configurable #44

Open
jcyuan opened this issue Mar 3, 2023 · 11 comments
Open

[feature request] Make logging part configurable #44

jcyuan opened this issue Mar 3, 2023 · 11 comments

Comments

@jcyuan
Copy link

jcyuan commented Mar 3, 2023

something like

public interface ILogSink
{
    bool IsEnabled(LogEventLevel level, string type);
    void Log(LogEventLevel level, string type, object? source, string messageTemplate);
    void Log(
      LogEventLevel level,
      string type,
      object? source,
      string messageTemplate,
      params object?[] propertyValues);
  }

and in SeeShark have a default console sink and then in the end user logic just implement a sink adapter and replace the default one to record logs.

@Speykious
Copy link
Owner

So it's about bringing customizability here?

internal static unsafe void SetupFFmpegLogging(FFmpegLogLevel logLevel, ConsoleColor logColor)
{
ffmpeg.av_log_set_level((int)logLevel);
// Do not convert to local function!
logCallback = (p0, level, format, vl) =>
{
if (level > ffmpeg.av_log_get_level())
return;
var lineSize = 1024;
var lineBuffer = stackalloc byte[lineSize];
var printPrefix = 1;
ffmpeg.av_log_format_line(p0, level, format, vl, lineBuffer, lineSize, &printPrefix);
var line = Marshal.PtrToStringAnsi((IntPtr)lineBuffer);
// TODO: maybe make it possible to log this in any stream?
Console.ForegroundColor = logColor;
Console.Write(line);
Console.ResetColor();
};
ffmpeg.av_log_set_callback(logCallback);
}

@jcyuan
Copy link
Author

jcyuan commented Mar 3, 2023

So it's about bringing customizability here?

internal static unsafe void SetupFFmpegLogging(FFmpegLogLevel logLevel, ConsoleColor logColor)
{
ffmpeg.av_log_set_level((int)logLevel);
// Do not convert to local function!
logCallback = (p0, level, format, vl) =>
{
if (level > ffmpeg.av_log_get_level())
return;
var lineSize = 1024;
var lineBuffer = stackalloc byte[lineSize];
var printPrefix = 1;
ffmpeg.av_log_format_line(p0, level, format, vl, lineBuffer, lineSize, &printPrefix);
var line = Marshal.PtrToStringAnsi((IntPtr)lineBuffer);
// TODO: maybe make it possible to log this in any stream?
Console.ForegroundColor = logColor;
Console.Write(line);
Console.ResetColor();
};
ffmpeg.av_log_set_callback(logCallback);
}

yes please, because i need to record informations into log files.
not sure why public interface ILogSink this line was missed in my code above. just fixed.
so that in my logic i can do something like:

class SerilogLoggerAdapter : ILogSink {
      public SerilogLoggerAdapter(ILogger logger)
    {
        _log = logger;
    }
    public bool IsEnabled(LogEventLevel level, string area) { ... return true; }
    public void Log(LogEventLevel level, string area, object? source, string messageTemplate)
    {
       switch(level) case LogEventLevel.Debug: _log.Debug(.....); .....
    }
    .....
}

// then maybe:
YourLibModule.SetLoggerSink(new SerilogLoggerAdapter(new Serilog.LoggerConfig().WriteToFile().CreateLogger()));

@Speykious
Copy link
Owner

Ok, I'll see what I can do. Ideally you'll just need to setup a delegate, no need to create an interface.

@jcyuan
Copy link
Author

jcyuan commented Mar 3, 2023

Ok, I'll see what I can do. Ideally you'll just need to setup a delegate, no need to create an interface.

ok~ it works too, but not sure which way will be more efficient, but i think it's ignorable.
and thanks so much~ 👍

@jcyuan
Copy link
Author

jcyuan commented Mar 3, 2023

ah, right, another is, could you please make the paths configurable too?

protected VideoDeviceManager(DeviceInputFormat inputFormat)
{
SetupFFmpeg();

@Speykious
Copy link
Owner

Not sure what you mean, path to what?
If it's for the logging file, then you're gonna specify it yourself anyway, no problem :p

@jcyuan
Copy link
Author

jcyuan commented Mar 3, 2023

i'm sorry, it's a public static method. my bad.😅

@jcyuan
Copy link
Author

jcyuan commented Mar 3, 2023

Not sure what you mean, path to what? If it's for the logging file, then you're gonna specify it yourself anyway, no problem :p

no no, i meant, i thought FFmpegManager.SetupFFmpeg is internal use only, i found it in VideoManager class, and i wanna pass my path into it.
but i just found FFmpegManager.SetupFFmpeg is a static public method, so i can just call it when my app booting up.
no worry, this is not related to the logging problem.
sorry just ignore it.

@jcyuan
Copy link
Author

jcyuan commented Mar 3, 2023

are these native libs any special? or just download from ffmpeg official site it will just work fine?
which version your lib is currently rely on?

@Speykious
Copy link
Owner

SeeShark 4 relies on the FFmpeg 5.0 LibAV* native libraries. In any case, if the versions aren't correct, it's going to tell you.
So yeah you can just download them from the official website. But you need the libav dynamic libraries, not the ffmpeg executable.

@jcyuan
Copy link
Author

jcyuan commented Mar 4, 2023

SeeShark 4 relies on the FFmpeg 5.0 LibAV* native libraries. In any case, if the versions aren't correct, it's going to tell you. So yeah you can just download them from the official website. But you need the libav dynamic libraries, not the ffmpeg executable.

nice one, thanks so much ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants