@@ -60,8 +60,8 @@ func main() {
6060 // Add global flags
6161 rootCmd .PersistentFlags ().StringVarP (& configFile , "config" , "c" , "" , "Configuration file path" )
6262 rootCmd .PersistentFlags ().StringVarP (& dataDir , "data-dir" , "d" , "" , "Data directory path (default: ~/.mcpproxy)" )
63- rootCmd .PersistentFlags ().StringVar (& logLevel , "log-level" , "info " , "Log level (debug, info, warn, error)" )
64- rootCmd .PersistentFlags ().BoolVar (& logToFile , "log-to-file" , true , "Enable logging to file in standard OS location" )
63+ rootCmd .PersistentFlags ().StringVar (& logLevel , "log-level" , "" , "Log level (debug, info, warn, error) - defaults: server=info, other commands=warn " )
64+ rootCmd .PersistentFlags ().BoolVar (& logToFile , "log-to-file" , false , "Enable logging to file in standard OS location (default: console only) " )
6565 rootCmd .PersistentFlags ().StringVar (& logDir , "log-dir" , "" , "Custom log directory path (overrides standard OS location)" )
6666
6767 // Add server command
@@ -121,9 +121,22 @@ Examples:
121121
122122 # Search for servers tagged as "finance" in the Pulse registry
123123 mcpproxy search-servers --registry pulse --tag finance` ,
124- RunE : func (_ * cobra.Command , _ []string ) error {
124+ RunE : func (cmd * cobra.Command , _ []string ) error {
125+ // Setup logger for search command (non-server command = WARN level by default)
126+ cmdLogLevel , _ := cmd .Flags ().GetString ("log-level" )
127+ cmdLogToFile , _ := cmd .Flags ().GetBool ("log-to-file" )
128+ cmdLogDir , _ := cmd .Flags ().GetString ("log-dir" )
129+
130+ logger , err := logs .SetupCommandLogger (false , cmdLogLevel , cmdLogToFile , cmdLogDir )
131+ if err != nil {
132+ return fmt .Errorf ("failed to setup logger: %w" , err )
133+ }
134+ defer func () {
135+ _ = logger .Sync ()
136+ }()
137+
125138 if listRegistries {
126- return listAllRegistries ()
139+ return listAllRegistries (logger )
127140 }
128141
129142 if registryFlag == "" {
@@ -145,16 +158,24 @@ Examples:
145158 // Create experiments guesser if repository checking is enabled
146159 var guesser * experiments.Guesser
147160 if cfg .CheckServerRepo {
148- // For CLI, we don't have cache manager, so pass nil
149- logger := zap .NewNop () // Use no-op logger for CLI
161+ // Use the proper logger instead of no-op
150162 guesser = experiments .NewGuesser (nil , logger )
151163 }
152164
165+ logger .Info ("Searching servers" ,
166+ zap .String ("registry" , registryFlag ),
167+ zap .String ("search" , searchFlag ),
168+ zap .String ("tag" , tagFlag ),
169+ zap .Int ("limit" , limitFlag ))
170+
153171 servers , err := registries .SearchServers (ctx , registryFlag , tagFlag , searchFlag , limitFlag , guesser )
154172 if err != nil {
173+ logger .Error ("Search failed" , zap .Error (err ))
155174 return fmt .Errorf ("search failed: %w" , err )
156175 }
157176
177+ logger .Info ("Search completed" , zap .Int ("results_count" , len (servers )))
178+
158179 // Print results as JSON
159180 output , err := json .MarshalIndent (servers , "" , " " )
160181 if err != nil {
@@ -175,19 +196,23 @@ Examples:
175196 return cmd
176197}
177198
178- func listAllRegistries () error {
199+ func listAllRegistries (logger * zap. Logger ) error {
179200 // Load config and initialize registries
180201 cfg , err := config .LoadFromFile ("" )
181202 if err != nil {
182203 // Use default config if loading fails
183204 cfg = config .DefaultConfig ()
184205 }
185206
207+ logger .Info ("Loading registries configuration" )
208+
186209 // Initialize registries from config
187210 registries .SetRegistriesFromConfig (cfg )
188211
189212 registryList := registries .ListRegistries ()
190213
214+ logger .Info ("Found registries" , zap .Int ("count" , len (registryList )))
215+
191216 // Format as a simple table for CLI display
192217 fmt .Printf ("%-20s %-30s %s\n " , "ID" , "NAME" , "DESCRIPTION" )
193218 fmt .Printf ("%-20s %-30s %s\n " , "==" , "====" , "===========" )
@@ -223,8 +248,14 @@ func runServer(cmd *cobra.Command, _ []string) error {
223248
224249 // Override logging settings from command line
225250 if cfg .Logging == nil {
251+ // Use command-specific default level (INFO for server command)
252+ defaultLevel := cmdLogLevel
253+ if defaultLevel == "" {
254+ defaultLevel = "info" // Server command defaults to INFO
255+ }
256+
226257 cfg .Logging = & config.LogConfig {
227- Level : cmdLogLevel ,
258+ Level : defaultLevel ,
228259 EnableFile : cmdLogToFile ,
229260 EnableConsole : true ,
230261 Filename : "main.log" ,
@@ -236,7 +267,11 @@ func runServer(cmd *cobra.Command, _ []string) error {
236267 }
237268 } else {
238269 // Override specific fields from command line
239- cfg .Logging .Level = cmdLogLevel
270+ if cmdLogLevel != "" {
271+ cfg .Logging .Level = cmdLogLevel
272+ } else if cfg .Logging .Level == "" {
273+ cfg .Logging .Level = "info" // Server command defaults to INFO
274+ }
240275 cfg .Logging .EnableFile = cmdLogToFile
241276 if cfg .Logging .Filename == "" || cfg .Logging .Filename == "mcpproxy.log" {
242277 cfg .Logging .Filename = "main.log"
0 commit comments