emaloney / CleanroomLogger

CleanroomLogger provides an extensible Swift-based logging API that is simple, lightweight and performant
MIT License
1.33k stars 154 forks source link

Not printing logs to logfile #73

Open gdimaggio opened 7 years ago

gdimaggio commented 7 years ago

Probably I'm missing something obvious but I can't get Cleanroom to log any of my messages to the logfile. I set up a RotatingLogFileConfiguration and call enable in my AppDelegate, as show by the code below:

var configurations: [BasicLogConfiguration] = [basicLogConfig]
if let directoryPath = self.logFileDirectoryPath() {
   let logConfiguration = RotatingLogFileConfiguration(minimumSeverity: .debug,
                                                        daysToKeep: 15,
                                                        directoryPath: directoryPath.path,
                                                        formatters: [formatter])
    do {
       logConfiguration.createLogDirectory()
       configurations.append(logConfiguration)
    } catch { }
}
Log.enable(configuration: configurations)

The file is correctly created in the directory passed by logFileDirectoryPath(), but the file is always empty no matter what...any thoughts?

emaloney commented 7 years ago

Hello,

There could be multiple possibilities. Would you mind trying the just-issued 5.0.3 release first? It addresses a separate issue with logs not being flushed frequently enough when not running in synchronous mode. This is one possible cause of the behavior you're seeing.

Another thing to try it setting a couple breakpoints to make sure they're being hit. Setting one at RotatingLogFileRecorder.swift:136 will let you know if the rotating log recorder is being called.

Setting one at FileLogRecorder.swift:84 will let you know if the underlying log recorder used by the rotating recorder is being called.

Lastly, what do your Log statements look like? It is possible you're not recording anything at the .debug severity or higher?

jogi commented 7 years ago

I had a similar issue and it turned out that I was calling Log.enable() twice. Once by calling Log.enable(minimumSeverity: .debug) and once by calling Log.enable(configuration: [LogConfiguration]). I didn't realize that when enabling using configurations, you need to pass the severity directly in the LogConfiguration object.

dustinrwh commented 7 years ago

@gdimaggio What directory path are writing to?

This probably isn't the issue since the file is actually being created in the directory, but the more information the better :)