To implement a custom logger, you'll need to implement a type that extends the Sitecore.JavaScriptServices.ViewEngine.NodeServices.ILogger
interface from the Sitecore.JavaScriptServices.ViewEngine.NodeServices
assembly.
(For reference, use your favorite disassembler to inspect the default JSS/Sitecore implementation that logs Node.js output to Sitecore logs in the Sitecore.JavaScriptServices.ViewEngine.Node.Logger
class in the Sitecore.JavaScriptServices.ViewEngine.Node
assembly.)
You'll then need to register your ILogger
implementation with the Sitecore DI container with something like this (where MyCustomLogger
is your custom implementation of ILogger
:
using Microsoft.Extensions.DependencyInjection;
using Sitecore.DependencyInjection;
using Sitecore.JavaScriptServices.ViewEngine.NodeServices;
namespace MyNamespace
{
public class RegisterDependenciesPatch : IServicesConfigurator
{
public void Configure(IServiceCollection serviceCollection)
{
var toRemove = serviceCollection.FirstOrDefault(d => d.ServiceType == typeof(ILogger));
serviceCollection.Remove(toRemove);
serviceCollection.AddTransiet<ILogger, MyCustomLogger>();
}
}
}
Lastly, you'll need to patch the App_Config/Sitecore/JavaScriptServices/Sitecore.JavaScriptServices.ViewEngine.Node.config
file to add your dependency registration code after the default JSS Node services dependency registrations. Example:
<configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
<sitecore>
<configurator
type="MyNamespace.RegisterDependenciesPatch, MyLibrary"
patch:after="*[@type='Sitecore.JavaScriptServices.ViewEngine.Node.RegisterDependencies, Sitecore.JavaScriptServices.ViewEngine.Node']"
/>
</sitecore>
</configuration>