From ae0a38ddf8fe2b0db0dae3c072c322eaaff57dcd Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 18 Mar 2012 16:06:57 +0100 Subject: macosx_finder_args: use a custom logfile instead of system.log Change the macosx_finder_args function so that when mplayer2 is invoked from the Finder in a Mac application bundle, it redirects the output to ~/Library/Logs/mplayer2.log instead of cluttering the global system.log. This doesn't affect terminal use which keeps writing to stdout and stderr. --- osdep/macosx_finder_args.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'osdep') diff --git a/osdep/macosx_finder_args.m b/osdep/macosx_finder_args.m index cce5acbcc6..b006f11a79 100644 --- a/osdep/macosx_finder_args.m +++ b/osdep/macosx_finder_args.m @@ -24,6 +24,7 @@ static play_tree_t *files = NULL; void macosx_wait_fileopen_events(void); +void macosx_redirect_output_to_logfile(const char *filename); bool psn_matches_current_process(char *psn_arg_to_check); @interface FileOpenDelegate : NSObject @@ -59,6 +60,16 @@ void macosx_wait_fileopen_events() [pool release]; } +void macosx_redirect_output_to_logfile(const char *filename) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *log_path = [NSHomeDirectory() stringByAppendingPathComponent: + [@"Library/Logs/" stringByAppendingFormat:@"%s.log", filename]]; + freopen([log_path fileSystemRepresentation], "a", stdout); + freopen([log_path fileSystemRepresentation], "a", stderr); + [pool release]; +} + bool psn_matches_current_process(char *psn_arg_to_check) { ProcessSerialNumber psn; @@ -75,6 +86,7 @@ bool psn_matches_current_process(char *psn_arg_to_check) play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv) { if (argc==2 && psn_matches_current_process(argv[1])) { + macosx_redirect_output_to_logfile("mplayer2"); m_config_set_option0(config, "quiet", NULL, false); macosx_wait_fileopen_events(); } -- cgit v1.2.3