Managing Global Options
How to set environment file
To set an environment, use the envFile
field. This allows you to load external environment variables from a specified file.
export default {
scripts: {
yourScript1: "someCommand",
},
envFile: './path/to/.env',
}
.env
:
SOME_ENV_VAR=VALUE1
The environment variables can be reached in various contexts:
- Function scripts:
process.env.SOME_ENV_VAR
- Traditional scripts:
$SOME_ENV_VAR
- Other processes: through mechanisms specific to each process (e.g., a Node.js process uses
process.env.SOME_ENV_VAR
)
How to set log level
To set the log level, use the logLevel
field. This allows you to define the verbosity of logging during execution.
logLevel
specifies the desired log level:
"info"
– Shows general information and normal operations. Default."warn"
– Displays warnings that don’t interrupt execution."error"
– Logs only errors that need attention.
Setting the level to 'info' means that informational, warning, and error messages are all logged. In contrast, choosing 'warn' will filter out informational messages and log only warnings and errors, while selecting 'error' limits the logs to error messages alone. This hierarchical logging setup helps you control verbosity and focus on the severity of events as needed.
For example:
- When using the
'error'
log level and an error arises:
export default {
scripts: {
yourScript: "exit 10",
}
// highlight-next-line,
logLevel: 'error'
}
$ jko yourScript
◤
jko end - yourScript: "exit 10" Failed.◣
- When using the
'warn'
log level and an error arises:
export default {
scripts: {
yourScript: "exit 10",
}
// highlight-next-line,
logLevel: 'warn'
}
$ jko yourScript
◤
jko end - yourScript: "exit 10" Failed.◣
- When using the
'info'
log level and an error arises:
export default {
scripts: {
yourScript: "exit 10",
}
// highlight-next-line,
logLevel: 'info'
}
$ jko yourScript
◤
jko end - yourScript: "exit 10" Failed.◣
- When using the
'error'
log level and a warning arises:
export default {
scripts: {
yourScript: "exit 10",
"$catch (yourScript)": "echo Ok!",
}
// highlight-next-line,
logLevel: 'error'
}
$ jko yourScript
Ok!
◤
jko warn - $catch (yourScript) executed.◣
◤
jko end - Successful execution of yourScript.◣
- When using the
'warn'
log level and a warning arises:
export default {
scripts: {
yourScript: "exit 10",
"$catch (yourScript)": "echo Ok!",
}
// highlight-next-line,
logLevel: 'warn'
}
$ jko yourScript
Ok!
◤
jko warn - $catch (yourScript) executed.◣
◤
jko end - Successful execution of yourScript.◣
- When using the
'info'
log level and a warning arises:
export default {
scripts: {
yourScript: "exit 10",
"$catch (yourScript)": "echo Ok!",
}
// highlight-next-line,
logLevel: 'info'
}
$ jko yourScript
Ok!
◤
jko end - Successful execution of yourScript.◣
- When any log level is applied and execution succeeds:
$ jko yourScript
...
◤
jko end - Successful execution of yourScript.◣