Log File Watcher

  • Hi there

    I tried to make something like a log file watcher (like tail):

    ---
    - (void)awakeFromNib {
    logFile = [[NSFileHandle fileHandleForReadingAtPath:LOGFILE] init];
    if (!logFile)
            return;
    [logFile seekToEndOfFile];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                                selector:@selector(fileDataAvailable:)
                                                    name:NSFileHandleReadCompletionNotification
                                                 object:logFile];
    [logFile readInBackgroundAndNotify];
    }

    - (void)fileDataAvailable:(NSNotification*)note {
    NSLog(@"new entry %@", [[NSString alloc] initWithData:
          [[note userInfo] objectForKey:NSFileHandleNotificationDataItem]
                                                    encoding:NSUTF8StringEncoding]);
    [logFile readInBackgroundAndNotify];
    }
    ---

    The problem is, I now get e "new entry" all the time... The [note
    userInfo] is empty.

    ---
    2007-11-05 22:11:26.502 MyApp[4381:10b] new entry
    2007-11-05 22:11:26.504 MyApp[4381:10b] new entry
    2007-11-05 22:11:26.504 MyApp[4381:10b] new entry
    ---

    Any help is appreciated.

    Nils
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today