diff --git a/ingest/ledgerbackend/captive_core_backend.go b/ingest/ledgerbackend/captive_core_backend.go index 10f7c29db5..07cf53ea62 100644 --- a/ingest/ledgerbackend/captive_core_backend.go +++ b/ingest/ledgerbackend/captive_core_backend.go @@ -124,6 +124,9 @@ type CaptiveCoreConfig struct { // Log is an (optional) custom logger which will capture any output from the Stellar Core process. // If Log is omitted then all output will be printed to stdout. Log *log.Entry + // LogPath is the (optional) path in which to store Core logs, passed along + // to Stellar Core's LOG_FILE_PATH + LogPath string // Context is the (optional) context which controls the lifetime of a CaptiveStellarCore instance. Once the context is done // the CaptiveStellarCore instance will not be able to stream ledgers from Stellar Core or spawn new // instances of Stellar Core. If Context is omitted CaptiveStellarCore will default to using context.Background. @@ -134,11 +137,14 @@ type CaptiveCoreConfig struct { func NewCaptive(config CaptiveCoreConfig) (*CaptiveStellarCore, error) { // Here we set defaults in the config. Because config is not a pointer this code should // not mutate the original CaptiveCoreConfig instance which was passed into NewCaptive() + + // Log Captive Core straight to stdout by default if config.Log == nil { config.Log = log.New() config.Log.Logger.SetOutput(os.Stdout) config.Log.SetLevel(logrus.InfoLevel) } + parentCtx := config.Context if parentCtx == nil { parentCtx = context.Background() diff --git a/ingest/ledgerbackend/stellar_core_runner.go b/ingest/ledgerbackend/stellar_core_runner.go index 72a7f7064d..9889322fb2 100644 --- a/ingest/ledgerbackend/stellar_core_runner.go +++ b/ingest/ledgerbackend/stellar_core_runner.go @@ -48,6 +48,7 @@ type pipe struct { } type stellarCoreRunner struct { + logPath string executablePath string configAppendPath string networkPassphrase string @@ -82,6 +83,7 @@ func newStellarCoreRunner(config CaptiveCoreConfig, mode stellarCoreRunnerMode) ctx, cancel := context.WithCancel(config.Context) runner := &stellarCoreRunner{ + logPath: config.LogPath, executablePath: config.BinaryPath, configAppendPath: config.ConfigAppendPath, networkPassphrase: config.NetworkPassphrase, @@ -116,7 +118,7 @@ func (r *stellarCoreRunner) generateConfig() (string, error) { fmt.Sprintf(`NETWORK_PASSPHRASE="%s"`, r.networkPassphrase), fmt.Sprintf(`BUCKET_DIR_PATH="%s"`, filepath.Join(r.tempDir, "buckets")), fmt.Sprintf(`HTTP_PORT=%d`, r.httpPort), - `LOG_FILE_PATH=""`, + fmt.Sprintf(`LOG_FILE_PATH="%s"`, r.logPath), } if r.mode == stellarCoreRunnerModeOffline { diff --git a/services/horizon/internal/config.go b/services/horizon/internal/config.go index 9c55a85cac..331f2bc444 100644 --- a/services/horizon/internal/config.go +++ b/services/horizon/internal/config.go @@ -21,6 +21,7 @@ type Config struct { CaptiveCoreConfigAppendPath string RemoteCaptiveCoreURL string CaptiveCoreHTTPPort uint + CaptiveCoreLogPath string StellarCoreDatabaseURL string StellarCoreURL string diff --git a/services/horizon/internal/flags.go b/services/horizon/internal/flags.go index 6e9c23960b..964f5eaea4 100644 --- a/services/horizon/internal/flags.go +++ b/services/horizon/internal/flags.go @@ -255,6 +255,12 @@ func Flags() (*Config, support.ConfigOptions) { OptType: types.String, Usage: "name of the file where logs will be saved (leave empty to send logs to stdout)", }, + &support.ConfigOption{ + Name: "captive-core-log-path", + ConfigKey: &config.CaptiveCoreLogPath, + OptType: types.String, + Usage: "name of the path for Core logs (leave empty to log w/ Horizon only)", + }, &support.ConfigOption{ Name: "max-path-length", ConfigKey: &config.MaxPathLength, diff --git a/services/horizon/internal/ingest/main.go b/services/horizon/internal/ingest/main.go index 762295e905..14690ffc24 100644 --- a/services/horizon/internal/ingest/main.go +++ b/services/horizon/internal/ingest/main.go @@ -71,6 +71,7 @@ type Config struct { CaptiveCoreBinaryPath string CaptiveCoreConfigAppendPath string CaptiveCoreHTTPPort uint + CaptiveCoreLogPath string RemoteCaptiveCoreURL string NetworkPassphrase string @@ -189,8 +190,10 @@ func NewSystem(config Config) (System, error) { return nil, errors.Wrap(err, "error creating captive core backend") } } else { + logger := log.WithField("subservice", "stellar-core") ledgerBackend, err = ledgerbackend.NewCaptive( ledgerbackend.CaptiveCoreConfig{ + LogPath: config.CaptiveCoreLogPath, BinaryPath: config.CaptiveCoreBinaryPath, ConfigAppendPath: config.CaptiveCoreConfigAppendPath, HTTPPort: config.CaptiveCoreHTTPPort, @@ -198,7 +201,7 @@ func NewSystem(config Config) (System, error) { HistoryArchiveURLs: []string{config.HistoryArchiveURL}, CheckpointFrequency: config.CheckpointFrequency, LedgerHashStore: ledgerbackend.NewHorizonDBLedgerHashStore(config.HistorySession), - Log: log.WithField("subservice", "stellar-core"), + Log: logger, Context: ctx, }, ) diff --git a/services/horizon/internal/init.go b/services/horizon/internal/init.go index 0108e28ef4..90677d16a5 100644 --- a/services/horizon/internal/init.go +++ b/services/horizon/internal/init.go @@ -72,6 +72,7 @@ func initIngester(app *App) { CaptiveCoreBinaryPath: app.config.CaptiveCoreBinaryPath, CaptiveCoreConfigAppendPath: app.config.CaptiveCoreConfigAppendPath, CaptiveCoreHTTPPort: app.config.CaptiveCoreHTTPPort, + CaptiveCoreLogPath: app.config.CaptiveCoreLogPath, RemoteCaptiveCoreURL: app.config.RemoteCaptiveCoreURL, EnableCaptiveCore: app.config.EnableCaptiveCoreIngestion, DisableStateVerification: app.config.IngestDisableStateVerification,