Skip to main content

FAQ

The compiler reports cannot find 'Logger' in scope​

The compiler reports cannot find 'Logger' in scope because Logger comes from Apple's os module and Logly does not bring that import along. Add import os (or import OSLog) next to import Logly.

The compiler reports expression is 'async' but is not marked with 'await'​

Inside an async function Swift picks the async variant of the Logly log method. Put await in front of it, for example:

await Logger.network.info("Request started")

See Logging in async code.

Why don't my messages appear in Console.app?​

Logly does not write to Apple's unified logging. Messages go to standard output, the log file and the sinks. They do not show up in Console.app or with log stream.

The Xcode console shows characters like [0;32m​

Characters like [0;32m are Logly ANSI color codes, which the Xcode console does not render. Turn the colors off in Logly like this:

LoggerConfiguration.shared.enableANSIColors = false

The log file stays empty or I see [Logger] Failed to write log to file​

If the Logly log file stays empty, usually the folder for the file is missing. Logly does not create folders. Create it before the first log call, for example:

let url = LoggerConfiguration.shared.logFilePath
try FileManager.default.createDirectory(at: url.deletingLastPathComponent(),
withIntermediateDirectories: true)

Also check that logToFile is true.

Where is the log file if I don't configure anything?​

Without your own setting, the Logly log file is at app_log.txt in FileManager.default.temporaryDirectory. LoggerConfiguration.shared.logFilePath returns the exact path.

The last messages are missing from the file​

With asynchronousLogging = true (the default) Logly messages wait briefly in a queue. If the process ends at that moment, for example in a command-line tool or during a crash, they are lost. Set asynchronousLogging = false if every message must reliably reach the file.

Why isn't the passed error in the log file?​

In Logly only the sinks receive the error: parameter. For console and file, include the error in the text like this:

Logger.database.error("Saving failed: \(error.localizedDescription)", error: error)

Debug messages appear in the release build​

In Logly the default value of currentLogLevel is .debug, regardless of the build. Set it yourself at startup, for example:

#if !DEBUG
LoggerConfiguration.shared.currentLogLevel = .info
#endif

Can I turn off console output?​

No, you cannot turn off the Logly console output. Every message that passes the level filter is printed to the console. You can only raise the minimum level (up to .fault) and turn off the file with logToFile = false.

Can I write a separate log file per category?​

A separate log file per category is not possible with the built-in features of Logly. There is one log file for the whole app. For additional files, write a custom sink that filters by event.category.

import LoglySentry does not work or bootstrap is unknown​

If import LoglySentry does not work, the Sentry package trait is not enabled. Without it the module is empty. See Adding the package.

Can I use Logly from several threads at the same time?​

Yes, you can use Logly from several threads at the same time. LogCategory is Sendable, and LoggerConfiguration protects its state with a lock. You can use loggers and the configuration from any thread, actor and task.

Should I use LoggerCrashHandler together with Sentry?​

No, you should not use LoggerCrashHandler together with Sentry. When Sentry is active through LoglySentry.bootstrap(), Sentry handles crash detection. See Crash handling.