discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSLog suddenly mirroring to /var/log/user.log, /var/log/warnings, a


From: Ivan Vučica
Subject: Re: NSLog suddenly mirroring to /var/log/user.log, /var/log/warnings, and /var/log/syslog
Date: Thu, 4 Aug 2016 15:25:34 +0100

Is GSLogSyslog defaults flag flipped to YES for you?

If so, I would look outside GNUstep, into the world of syslog() and its configuration.

http://svn.gna.org/svn/gnustep/libs/base/trunk/Source/NSLog.m
static void
_NSLog_standard_printf_handler(NSString* message)
{
...
  if (GSPrivateDefaultsFlag(GSLogSyslog) == YES
    || write(_NSLogDescriptor, buf, len) != (int)len)
    {
      null_terminated_buf = malloc(sizeof (char) * (len + 1));
      strncpy (null_terminated_buf, buf, len);
      null_terminated_buf[len] = '\0';

      syslog(SYSLOGMASK, "%s",  null_terminated_buf);

      free(null_terminated_buf);
    }
...
}

On Thu, Aug 4, 2016 at 3:16 PM, Lobron, David <dlobron@akamai.com> wrote:
Hi All,

I have an application that sends NSLog output to a custom location.  A few days ago, the log lines suddenly started mirroring to /var/log/user.log, /var/log/warnings, and /var/log/syslog.  I did not make any changes to my program or the GNUStep runtime.  From a read of the NSLog docs, it seems like this should not be able to happen.  Has anyone seen this before?

My code sets up logging in a function called p_logRotate.  This function is called when the application starts up, and also when its regular log file needs to be rotated: the latter is triggered by a SIGHUP from a monitoring process.  This code has been in use at my company for years, across many programs, so I'd be surprised if a bug like this suddenly was triggered.  The only thing that distinguishes my application from others is that it's doing very heavy logging at the moment.  Also, /var is currently full, but that's a result of these logs being mirrored to /var/log/* - I don't think it's the cause.

Many thanks in advance for any help here.

--David

My code:

- (void)p_logRotate:(BOOL)firstTime
{
    if (!firstTime)
        NSLog(@"Rotating log file");
    if (_logfileNameCString != 0) {
        int fd;
        fd = open(_logfileNameCString, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
        if (fd >= 0) {
            if (firstTime)
                NSLog(@"Logging to %@", _logfileName);
            dup2(fd, STDOUT_FILENO);
            dup2(fd, STDERR_FILENO);
            close(fd);
            [[NSNotificationCenter defaultCenter] postNotificationName:AkamaiDaemonLogFileWasOpenedNotification object:self];
        } else {
            [NSException raise:@"log rotate failed" format:@"log rotation failed: %s", strerror(errno)];
        }
    }
    if (!firstTime) {
        NSLog(@"Log file rotated");
        [[NSNotificationCenter defaultCenter] postNotificationName:AkamaiDaemonLogFileWasRotatedNotification object:self];
    }
}
_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep


reply via email to

[Prev in Thread] Current Thread [Next in Thread]