Back to Baml

config (logging / environment variables)

fern/03-reference/baml_client/config.mdx

0.222.03.8 KB
Original Source

Various settings are configurable via environment variables.

SettingEnvironment VariableDescriptionDefault
Logging LevelBAML_LOGThe logging level to use (INFO, DEBUG, TRACE, WARN, ERROR, OFF)INFO
Text / JSON ModeBAML_LOG_JSONWhether to log in JSON format or human-readable format (1, 0)0
Max Log Chunk SizeBAML_LOG_MAX_MESSAGE_LENGTHHow large of a prompt / response will be logged (0 for no limit)64000
Log Color ModeBAML_LOG_COLOR_MODEWhether to color the log output (auto, always, never)auto

Setting can also be modified via functions in baml_client.config.

<Tabs> <Tab title="python" language="python"> ```python from baml_client.config import set_from_env, set_log_level, set_log_json_mode, set_log_max_message_length, get_log_level, reset_baml_env_vars ```

set_log_level

Environment variable: BAML_LOG

python
def set_log_level(level: "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF"):
  ...

set_log_json_mode

Environment variable: BAML_LOG_JSON

Switches the log output between JSON and human-readable format.

python
def set_log_json_mode(enable: bool):

set_log_max_message_length

0 for unlimited

Environment variable: BAML_LOG_MAX_MESSAGE_LENGTH

python
def set_log_max_message_length(length: int):

get_log_level

python
def get_log_level() -> "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF":

reset_baml_env_vars

<Warning> `reset_baml_env_vars` is deprecated and is safe to remove, since environment variables are now lazily loaded on each function call </Warning>

Resets the environment variables to the values in the provided dictionary. Will also reset any logging related environment variables to those passed in (if set explicitly).

python
def reset_baml_env_vars(env: Dict[str, str]):
</Tab> <Tab title="typescript" language="typescript"> ```typescript import { setLogLevel, setLogJsonMode, setLogMaxMessageLength, getLogLevel, resetBamlEnvVars } from '@/baml_client/config'; ```

setLogLevel

Environment variable: BAML_LOG

typescript
setLogLevel(level: "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF"): void;

setLogJsonMode

Environment variable: BAML_LOG_JSON

Switches the log output between JSON and human-readable format.

typescript
setLogJsonMode(enable: boolean): void;

setLogMaxMessageLength

Environment variable: BAML_LOG_MAX_MESSAGE_LENGTH

0 for unlimited

typescript
setLogMaxMessageLength(length: number): void;

getLogLevel

typescript
getLogLevel(): "INFO" | "DEBUG" | "TRACE" | "WARN" | "ERROR" | "OFF";

resetBamlEnvVars

Resets the environment variables to the values in the provided dictionary. Will also reset any logging related environment variables to those passed in (if set explicitly).

typescript
resetBamlEnvVars(env: Record<string, string | undefined>): void;
</Tab> <Tab title="rust" language="rust"> ```rust // Rust uses environment variables directly. // Set BAML_LOG, BAML_LOG_JSON, etc. before running your application, // or use .with_env_var() on function calls to override per-call. use myproject::baml_client::sync_client::B;

let result = B.ExtractResume .with_env_var("BAML_LOG", "DEBUG") .call("...") .unwrap();

  </Tab>
  <Tab title="ruby" language="ruby">
```ruby
# not implemented yet
# please use environment variables instead
</Tab> </Tabs> <hr /> <Markdown src="/snippets/setting-env-vars.mdx" />