RFC - Agnostic Lumberjack - Draft 1 #166
Replies: 8 comments 26 replies
-
npm scope and package namesI would prefer it if we could have the packages in the same npm scope. The Maybe something like What do you all think? |
Beta Was this translation helpful? Give feedback.
-
Common log driversI think we should ship a console log driver with the core library. I also suggest that we ship a |
Beta Was this translation helpful? Give feedback.
-
Class and function namesI heavily dislike the
Come on, this is very bad.
Functions with a |
Beta Was this translation helpful? Give feedback.
-
ExamplesCould you add examples showing JSX-style framework usage of |
Beta Was this translation helpful? Give feedback.
-
Lumberjack Core Configuration APII think that the following are implementation details that shouldn't be part of a public API.
|
Beta Was this translation helpful? Give feedback.
-
Declarative Lumberjack Core logging API
|
Beta Was this translation helpful? Give feedback.
-
Save the log driversI don't feel good about entirely removing the concept and wording of log drivers. After all, log driving is an actual activity for lumberjacks. |
Beta Was this translation helpful? Give feedback.
-
Closing this discussion as we decided to move in a different direction, see #188 |
Beta Was this translation helpful? Give feedback.
-
RFC - Agnostic Lumberjack - Draft 1
TL;DR
This RFC proposes a new lumberjack package, agnostic to the underlying JavaScript framework. This package will power the
@ngworker/lumberjack
package and facilitate the creation of logging libraries for various frameworks beyond Angular, thereby providing a standard interface for logging.This document will define and discuss the API of the agnostic lumberjack package.
Simultaneously, we must address the naming conventions for current and future packages as we introduce new packages.
Need
The need for a logging library agnostic to the underlying JavaScript framework emerged when we began using other frameworks for our jobs and side projects.
Developers typically use a specific client for their log storage provider, such as Logz.io, DataDog, or Sentry. This arrangement works fine if you use only one provider. However, using multiple frameworks requires a different client, leading to consistency and data mismatch issues.
Our goal is to create an agnostic logging library that offers native clients for all the frameworks that the community desires. Users can select the client they wish to use through our plugin system.
Success Criteria
By developing an agnostic Lumberjack library, we should be able to convert
@ngworker/lumberjack
into a framework (Angular) shell that employs the underlying library while maintaining its current features. The only exception is that many types and features previously exported by@ngworker/lumberjack
will be moved to the new agnostic lumberjack package.We should be able to create a new client for any framework, offering similar features to the Angular client. These features include:
Approach
To accomplish this, we will develop a new package that encompasses all the core logic of the existing lumberjack library, independent of the underlying JavaScript framework.
We will employ factory functions instead of classes to provide a more functional approach to the library and circumvent this binding issues.
All non-Angular related logic currently in the @ngworker/lumberjack package will be transferred to this new package.
Technical Design
The proposed public API for the new library is as follows:
Let's dissect it to understand each component's purpose.
Configuration
The LumberjackConfig, LumberjackLogDriverConfig, LumberjackOptions, defaultDevelopmentLevels, and defaultProductionLevels are existing configuration files that will remain unchanged. They will be migrated to the agnostic library to make such configurations universally accessible to all framework client APIs.
The
createLumberjackConfig
is a new function that seamlessly integrates the default and custom user configurations.It follows the same patterns in the
@ngworker/lumberjack
package when configuring Lumberjack through their modules andprovideLumberjack
functions.Logs
LumberjackConfigLevels,
LumberjackLevel,
LumberjackLog,
LumberjackLogLevel
, andLumberjackLogPayload
are unchanged existing types and functions that will be extracted into the new package.Log drivers
The
LumberjackLogDriver
andLumberjackLogDriverLog
are unchanged existing interfaces that will be extracted into the new agnostic library.Formatting
The
lumberjackFormatLog
is the default Lumberjack function to format logs. It will be extracted into the new package. The clear benefit of exporting this function is to use it in tests to validate the output of logging a log. However, that benefit could be achieved by providing a customLumberjackFormatFunction
on the configuration.The type for all possible Lumberjack format functions is exposed as
LumberjackFormatFunction.
It is up to the discussion if the
utcTimestampFor
is going to remain as part of the public API of the agnostic library. Its only use outside of the agnostic core is in some Angular library tests.Logging
The
LumberjackLogBuilder
is the existing builder class and will be extracted into the new package to assist with log creation.The
createLumberjackLogFactory
is a new factory function that extracts the functionality previously found in theLumberjackLogFactory
class. TheLumberjackLogFactory
class still exists, but it was renamed toLumberjackLogFactoryService.
TheLumberjackLogFactoryService
is now a wrapper of this new factory function. The typeLumberjackLogFactory
was introduced in the agnostic library and represented the structure of the returned object by thecreateLumberjackLogFactory.
The
createLumberjack
is the new factory function that extracts the functionality previously found in theLumberjackService
class. This is the core of the agnostic library and what all the new clients will use to access the Lumberjack core system. TheLumberjackService
is now a wrapper for this new factory function. The typeLumberjack
was introduced in the agnostic library and represented the structure of the returned object by thecreateLumberjack.
Examples of use
Vanilla JavaScript
Since this library is agnostic of any framework, it can be used in any JavaScript project, including Node.js environments.
Examples of Lumberjack usage outside of Angular
Express with simple API
Express with log builder factory
JSX Frameworks
The following code shows how to use the agnostic library to create an JSX framework Lumberjack client like React.
Then we could provide it like this:
And to use it:
Breaking Changes
Relocation of files
The following lists the types, classes, and functions moved from the
@ngworker/lumberjack
package to the new agnostic library.LumberjackConfig
LumberjackLogDriverConfig
LumberjackOptions
defaultDevelopmentLevels
defaultProductionLevels
LumberjackConfigLevels
LumberjackLevel
LumberjackLog
LumberjackLogLevel
LumberjackLogPayload
LumberjackLogDriver
LumberjackLogDriverLog
lumberjackFormatLog
utcTimestampFor
LumberjackLogBuilder
Renaming of the LumberjackLogFactory
With the creation of the
createLumberjackLogFactory
on the new agnostic library, we also created a new type to represent the object that such a function returns. The type received the nameLumberjackLogFactory,
, which conflicts with the existing@ngworker/lumberjack
service.Following Angular naming conventions, we renamed the service to
LumberjackLogFactoryService
.Naming Considerations
We name ourselves and our organization the
ngworker,
clearly referencing Angular and theng
prefix. This is reflected in the lumberjack package name@ngworker/lumberjack.
However, with the introduction of an agnostic framework and the possibility of using it in other frameworks, we must consider what conventions to follow when naming the new package.
The following are some suggestions, but we are open to considering other options.
@webworker/lumberjack, @ngworker/lumberjack, @reactworker/lumberjack, etc
This variant specifies the framework's name using the prefix/organization scope.
Its main benefit is that it would keep the identity of the original package, and it would be easy to identify the framework being used.
The main drawback is that the ownership of the packages would need to be clarified. It would also be confusing to have the packages living under the @ngworker GitHub organization but not being related to Angular necessarily.
Renaming the organization-scope
This option would look like
@lumberjack/core,
@lumberjack/angular,
@lumberjack/react,
etc.The benefit of this approach is that all packages get grouped under the same organization, and it is clear that they are related.
The main drawback is that
@ngworker/lumberjack
would have to cease to exist, or it should be deprecated and point to the new organization.Out of Scope
This effort does not involve creating framework clients for Lumberjack. That will be addressed in the following work.
Implementation
Beta Was this translation helpful? Give feedback.
All reactions