Browse Source

VLCLibrary: add API to log debug info to a file

Felix Paul Kühne 6 years ago
parent
commit
fdc3e8094f
3 changed files with 53 additions and 6 deletions
  1. 12 1
      Headers/Public/VLCLibrary.h
  2. 4 3
      NEWS
  3. 37 2
      Sources/VLCLibrary.m

+ 12 - 1
Headers/Public/VLCLibrary.h

@@ -2,10 +2,11 @@
  * VLCLibrary.h: VLCKit.framework VLCLibrary header
  *****************************************************************************
  * Copyright (C) 2007 Pierre d'Herbemont
- * Copyright (C) 2007 VLC authors and VideoLAN
+ * Copyright (C) 2007-2019 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
+ *          Felix Paul Kühne <fkuehne # videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
@@ -57,11 +58,21 @@
 /**
  * Gets/sets the debug logging level
  * \note Logging level ranges from 0 (just error messages) to 4 (everything)
+ * \note values set here will be ignored when logging to a file
  * \warning If an invalid level is provided, level defaults to 0
  */
 @property (readwrite, nonatomic) int debugLoggingLevel;
 
 /**
+ * Activates debug logging to a file stream
+ * If the file already exists, the log will be appended by the end. If it does not exist, will be created.
+ * The file will continously updated with new messages from this library instance.
+ * \note It is the client app's obligation to ensure that the target file path is writable and all subfolders exist
+ * \warning when enabling this feature, logging to the console will be stopped automatically
+ */
+- (void)setDebugLoggingToFile:(NSString * _Nonnull)filePath;
+
+/**
  * Returns the library's version
  * \return The library version example "0.9.0-git Grishenko"
  */

+ 4 - 3
NEWS

@@ -3,6 +3,10 @@ Version 4.0.0:
 - Rename buildMobileVLCKit to compileAndBuildVLCKit
 - Use NSDateComponents API for VLCTime.verboseStringValue
 
+Version 3.2.1:
+--------------
+- Add API to VLCLibrary to log debug information to a file
+
 Version 3.2.0:
 --------------
 - Enabled libmux module
@@ -27,9 +31,6 @@ VLCTranscoderDelegate:
 VLCTranscoder:
 	- (BOOL)reencodeAndMuxSRTFile:(NSString *)srtPath toMP4File:(NSString *)mp4Path outputPath:(NSString *)outPath
 
-
-
-
 Version 3.1.5:
 --------------
 - Fixed a crash when updateProgressCallback was called

+ 37 - 2
Sources/VLCLibrary.m

@@ -2,10 +2,11 @@
  * VLCLibrary.m: VLCKit.framework VLCLibrary implementation
  *****************************************************************************
  * Copyright (C) 2007 Pierre d'Herbemont
- * Copyright (C) 2007 VLC authors and VideoLAN
+ * Copyright (C) 2007-2019 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Pierre d'Herbemont <pdherbemont # videolan.org>
+ *          Felix Paul Kühne <fkuehne # videolan.org>
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published by
@@ -42,6 +43,12 @@ static void HandleMessage(void *,
 
 static VLCLibrary * sharedLibrary = nil;
 
+@interface VLCLibrary()
+{
+    FILE *_logFileStream;
+}
+@end
+
 @implementation VLCLibrary
 
 + (VLCLibrary *)sharedLibrary
@@ -144,6 +151,9 @@ static VLCLibrary * sharedLibrary = nil;
         libvlc_log_set(_instance, HandleMessage, (__bridge void *)(self));
     } else {
         libvlc_log_unset(_instance);
+
+        if (_logFileStream)
+            fclose(_logFileStream);
     }
 }
 
@@ -159,6 +169,25 @@ static VLCLibrary * sharedLibrary = nil;
     }
 }
 
+- (void)setDebugLoggingToFile:(NSString * _Nonnull)filePath
+{
+    if (!filePath)
+        return;
+
+    if (!_instance)
+        return;
+
+    if (_debugLogging) {
+        libvlc_log_unset(_instance);
+    }
+
+    _logFileStream = fopen([filePath UTF8String], "a");
+
+    if (_logFileStream) {
+        libvlc_log_set_file(_instance, _logFileStream);
+    }
+}
+
 - (NSString *)version
 {
     return @(libvlc_get_version());
@@ -188,8 +217,14 @@ static VLCLibrary * sharedLibrary = nil;
 
 - (void)dealloc
 {
-    if (_instance)
+    if (_instance) {
+        libvlc_log_unset(_instance);
         libvlc_release(_instance);
+    }
+
+    if (_logFileStream) {
+        fclose(_logFileStream);
+    }
 }
 
 @end