Skip to content

Commit

Permalink
add the possibility to write a JSON log
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed Jun 1, 2024
1 parent 31b32c3 commit b58becb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
10 changes: 8 additions & 2 deletions cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type SharedFlags struct {
TimeZone string // Override default TZ
SkipSSL bool // Skip SSL Verification
NoUI bool // Disable user interface
JSONLog bool // Enable JSON structured log

Immich immich.ImmichInterface // Immich client
Log *slog.Logger // Logger
Expand All @@ -53,6 +54,7 @@ func (app *SharedFlags) InitSharedFlags() {
app.SkipSSL = false
app.LogLevel = "INFO"
app.NoUI = false
app.JSONLog = false
}

// SetFlag add common flags to a flagset
Expand All @@ -65,6 +67,7 @@ func (app *SharedFlags) SetFlags(fs *flag.FlagSet) {
fs.BoolFunc("no-colors-log", "Disable colors on logs", myflag.BoolFlagFn(&app.NoLogColors, app.NoLogColors))
fs.StringVar(&app.LogLevel, "log-level", app.LogLevel, "Log level (DEBUG|INFO|WARN|ERROR), default INFO")
fs.StringVar(&app.LogFile, "log-file", app.LogFile, "Write log messages into the file")
fs.BoolFunc("log-json", "Output line-delimited JSON file, default FALSE", myflag.BoolFlagFn(&app.JSONLog, app.JSONLog))
fs.BoolFunc("api-trace", "enable api call traces", myflag.BoolFlagFn(&app.APITrace, app.APITrace))
fs.BoolFunc("debug", "enable debug messages", myflag.BoolFlagFn(&app.Debug, app.Debug))
fs.StringVar(&app.TimeZone, "time-zone", app.TimeZone, "Override the system time zone")
Expand Down Expand Up @@ -177,7 +180,10 @@ func (app *SharedFlags) Start(ctx context.Context) error {
}

func (app *SharedFlags) SetLogWriter(w io.Writer) {
app.Log = slog.New(humane.NewHandler(w, &humane.Options{Level: app.Level}))
// app.Log = slog.New(slog.NewJSONHandler(w, &slog.HandlerOptions{}))
if app.JSONLog {
app.Log = slog.New(slog.NewJSONHandler(w, &slog.HandlerOptions{}))
} else {
app.Log = slog.New(humane.NewHandler(w, &humane.Options{Level: app.Level}))
}
app.Jnl.SetLogger(app.Log)
}
27 changes: 14 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,20 @@ immich-go -server URL -key KEY -general_options COMMAND -command_options... {fil


| **Parameter** | **Description** | **Default value** |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
| `-use-configuration=path/to/config/file` | Specifies the configuration file to use. <br>Server URL and the API key are stored into the immich-go configuration file. They can be omitted for the next runs. | Linux `$HOME/.config/immich-go/immich-go.json`<br>Windows `%AppData%\immich-go\immich-go.json`<br>Apple `$HOME/Library/Application Support/immich-go/immich-go.json` |
| `-server=URL` | URL of the Immich service, example http://<your-ip>:2283 or https://your-domain | |
| `-api=URL` | URL of the Immich api endpoint (http://container_ip:3301) | |
| `-device-uuid=VALUE` | Force the device identification | `$HOSTNAME` |
| `-skip-verify-ssl` | Skip SSL verification for use with self-signed certificates | `false` |
| `-key=KEY` | A key generated by the user. Uploaded photos will belong to the key's owner. | |
| `-no-colors-log` | Remove color codes from logs. | `TRUE` on Windows, `FALSE` otherwise |
| `-log-level=LEVEL` | Adjust the log verbosity as follows: <br> - `ERROR`: Display only errors <br> - `WARNING`: Same as previous one plus non blocking error <br> - `INFO`: Information messages | `INFO` |
| `-log-file=/path/to/log/file` | Write all messages to a file | Linux `$HOME/.cache/immich-go/immich-go_YYYY-MM-DD_HH-MI-SS.log` <br>Windows `%LocalAppData%\immich-go\immich-go_YYYY-MM-DD_HH-MI-SS.log` <br>Apple `$HOME/Library/Caches/immich-go/immich-go_YYYY-MM-DD_HH-MI-SS.log`|
| `-time-zone=time_zone_name` | Set the time zone for dates without time zone information | the system's time zone |
| `-no-ui` | Disable the user interface | 'false' |
| **Parameter** | **Description** | **Default value** |
| ---------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-use-configuration=path/to/config/file` | Specifies the configuration file to use. <br>Server URL and the API key are stored into the immich-go configuration file. They can be omitted for the next runs. | Linux `$HOME/.config/immich-go/immich-go.json`<br>Windows `%AppData%\immich-go\immich-go.json`<br>Apple `$HOME/Library/Application Support/immich-go/immich-go.json` |
| `-server=URL` | URL of the Immich service, example http://<your-ip>:2283 or https://your-domain | |
| `-api=URL` | URL of the Immich api endpoint (http://container_ip:3301) | |
| `-device-uuid=VALUE` | Force the device identification | `$HOSTNAME` |
| `-skip-verify-ssl` | Skip SSL verification for use with self-signed certificates | `false` |
| `-key=KEY` | A key generated by the user. Uploaded photos will belong to the key's owner. | |
| `-no-colors-log` | Remove color codes from logs. | `TRUE` on Windows, `FALSE` otherwise |
| `-log-level=LEVEL` | Adjust the log verbosity as follows: <br> - `ERROR`: Display only errors <br> - `WARNING`: Same as previous one plus non blocking error <br> - `INFO`: Information messages | `INFO` |
| `-log-file=/path/to/log/file` | Write all messages to a file | Linux `$HOME/.cache/immich-go/immich-go_YYYY-MM-DD_HH-MI-SS.log` <br>Windows `%LocalAppData%\immich-go\immich-go_YYYY-MM-DD_HH-MI-SS.log` <br>Apple `$HOME/Library/Caches/immich-go/immich-go_YYYY-MM-DD_HH-MI-SS.log` |
| `-log-json` | Output the log as line-delimited JSON file | `false` |
| `-time-zone=time_zone_name` | Set the time zone for dates without time zone information | the system's time zone |
| `-no-ui` | Disable the user interface | 'false' |


## Command `upload`
Expand Down

0 comments on commit b58becb

Please sign in to comment.