ServiceLocator
Implements
- ServiceLocatorInterface
Index
Constructors
constructor
Creates a new ServiceLocator instance.
Parameters
optionalconfiguration: Configuration
Optional configuration instance to use
optionaleventManager: EventManager
Optional event manager instance to use
optionalstorageBackend: StorageBackend
Optional storage backend instance to use
optionallogger: CrawleeLogger
Optional logger instance to use
Returns ServiceLocator
Methods
getChildLog
Get a child logger with the given prefix. Equivalent to
getLogger().child({ prefix }).Parameters
prefix: string
Returns CrawleeLogger
getConfiguration
Get the configuration. Creates a default Configuration instance if none has been set.
Returns Configuration
getEventManager
Get the event manager. Creates a default LocalEventManager instance if none has been set.
Returns EventManager
getLogger
Get the logger. Returns the default
@apify/loglogger if none has been set.Returns CrawleeLogger
getStorageBackend
Get the storage backend. Creates a default storage backend if none has been set —
FileSystemStorageBackendwhenpersistStorageis enabled (the default),MemoryStorageBackendotherwise.Returns StorageBackend
getStorageInstanceManager
Get the storage instance manager (shared across all storage types).
Returns StorageInstanceManager
setConfiguration
Set the configuration.
Parameters
configuration: Configuration
The configuration to set
Returns void
Throws - If a different configuration has already been retrieved
setEventManager
Set the event manager.
Parameters
eventManager: EventManager
The event manager to set
Returns void
Throws - If a different event manager has already been retrieved
setLogger
Set the logger.
Parameters
logger: CrawleeLogger
The logger to set
Returns void
Throws - If a different logger has already been retrieved
setStorageBackend
Set the storage backend.
Parameters
storageBackend: StorageBackend
The storage backend to set
Returns void
Throws - If a different storage backend has already been retrieved
Service locator for managing the services used by Crawlee.
All services are initialized to their default value lazily.
There are two primary usage patterns:
1. Global service locator (for default services):
2. Per-crawler services (recommended for isolation):