Mob.AppConfig (mob v0.9.7)

Copy Markdown View Source

Puts the project's config/*.exs into the application environment on device.

A Mob app boots from a custom BEAM entry (<app>:start()), not a release, so nothing reads config/config.exs on the phone and Application.get_env/2 returns nil for everything that isn't compile_env. mob_dev closes that gap at build time: it evaluates config/config.exs (and config/runtime.exs, on the build host) for the build's Mix env and target, and ships the result as a generated :mob_app_config module next to the app's own BEAMs. Mob.App.start/0 calls load/0 before anything else reads the environment.

The values are put with persistent: true, so a later Application.load/1 of the same app (starting a plugin's OTP application loads it) does not replace them with the defaults in its .app file.

:logger

The :logger application is already running when the config arrives (the device entry starts it before Mob.App.start/0), so its settings that are read once at startup can't take effect. Applied:

  • :level, through Logger.configure/1, so the running Logger's primary level changes. An invalid level is logged and skipped.
  • :translator_inspect_opts, which Logger reads from the environment each time it's used.

Not applied, because Logger reads them only when it starts: :default_handler, :default_formatter, :handle_otp_reports, :handle_sasl_reports, :translators, :backends, and :truncate / :utc_log for the default handler's formatter. The :compile_time_* keys are compile-time only. Logger output on device goes through Mob.NativeLogger anyway.

Summary

Functions

Applies the generated config module, if there is one.

Functions

load(module \\ :mob_app_config)

@spec load(module()) :: :ok | :none | {:error, term()}

Applies the generated config module, if there is one.

Returns :ok once applied, :none when the module isn't present (an app built by an older mob_dev, or a host test), and {:error, reason} when it can't be applied. Never raises: a broken config must not stop the app from booting, so the failure is logged and the app runs with what it has.