Skip to main content
Version: 20.x

Logger

The logger section controls how the printed logs are going to look like in your terminal window.

Location

You can define the logger config section in two ways: globally and locally (per a configuration):

.detoxrc.js
/** @type {Detox.DetoxConfig} */
module.exports = {
logger: {
/* global section */
},
devices: { /* … */ },
apps: { /* … */ },
configurations: {
'ios.sim.debug': {
device: 'iphone',
app: 'ios.debug',
logger: {
/* local (per-configuration) section */
},
},
},
};

Properties

logger.level [enum]

Default: info.

Possible values in the descending severity order: fatal, error, warn, info, debug, trace.

  • Use info by default.
  • Use error or warn when you want to make the output as silent as possible.
  • Use debug to control what generally is happening under the hood.
  • Use trace when troubleshooting specific issues.

Please note that the log level has no effect on the generated log files and their content – it filters only the messages printed to your terminal.

info

The verbosity of the logs can be influenced by the session.debugSynchronization setting in your Detox configuration. Enabled by default, this setting helps track the reasons preventing your current actions from completing by identifying what the app is still busy with. It produces logs like this:

15:13:07.309 detox[17005] i The app is busy with the following tasks:
• There are 10 work items pending on the dispatch queue: "Main Queue (<OS_dispatch_queue_main: com.apple.main-thread>)".
...

If you want to disable or decrease how often session logs are saved, change the session.debugSynchronization value to 0 (to turn off logs) or increase it to 60000 (to lower the frequency of logs). For a deeper understanding of this setting's purpose, refer to the How Detox Works article.


logger.overrideConsole [boolean]

Default: true.

When enabled, hijacks all the console methods (console.log, console.warn, etc) so that the messages printed via them are formatted and saved as Detox logs.

logger.options [BunyanDebugStreamOptions]

Default: varies according to the logger.level.

Since Detox is using bunyan-debug-stream for printing logs, we decided just to expose all its options for sake of simplicity of customization:

export interface BunyanDebugStreamOptions {
colors?: { [key: number]: string | string[] } | false | null;
forceColor?: boolean;
basepath?: string;
basepathReplacement?: string;
showProcess?: boolean;
showDate?: boolean | ((time: Date, entry: any) => string);
showPrefixes?: boolean | ((prefixes: string[]) => string);
processName?: string;
maxExceptionLines?: number | 'auto';
stringifiers?: { [key: string]: Stringifier | null };
prefixers?: { [key: string]: Stringifier | null };
indent?: string;
showLoggerName?: boolean;
showPid?: boolean;
showLevel?: boolean;
showMetadata?: boolean;
}

There's one caveat inside logger.options, however – all the custom functions must not use closures! That's because they get eval()-ed every time the test runner spawns a new child worker process. In other words:

const dontDoThis = date => date.toISOString();

module.exports = {
logger: {
level: 'debug',
options: {
// showDate: (date) => dontDoThis(date),
showDate: (date) => date.toISOString(), /* do this instead */
},
},
// ...
};