Skip to content

Commit

Permalink
New release 4.2.0 (#230)
Browse files Browse the repository at this point in the history
Co-authored-by: Qortex <[email protected]>
  • Loading branch information
qortex and qortex committed Feb 22, 2021
1 parent b00f6c8 commit 1d99652
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 63 deletions.
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased] - Merged features waiting to be published in upcoming version

- None at the time.
- [in progress] Fix for sourcemap parsing in Firefox [#227](https://github.com/dbfannin/ngx-logger/pull/227)
- [in progress] Fix for logging complex structures (circular) without introducing a new dependency [#223](https://github.com/dbfannin/ngx-logger/pull/223)

## [4.2.0] - 2021-02-22

### Added

- A new option `proxiedSteps` {number} has been introduced. When set to a number, the given number of steps will be ignored in the stacktrace to compute the caller location. If you happen to always see the same location reported in the logs (for example a wrapper service of your own), tune this option to skip this step in the stack traces [#192](https://github.com/dbfannin/ngx-logger/pull/192). Thanks [@amilor](https://github.com/amilor) & [@bmtheo](https://github.com/bmtheo)
- New config option `disableFileDetails` (defaults to false). When set to `true`, filename details will not be shown in log messages ([#214](https://github.com/dbfannin/ngx-logger/pull/214)). Thanks [@Raphy](https://github.com/Raphy)
- Calling the `debug` endpoint now use `console.debug` api on the browser ([#213](https://github.com/dbfannin/ngx-logger/pull/213)). Thanks [@bmtheo](https://github.com/bmtheo)
- Gives direct accesss to current log levels through `level()` and `serverLogLevel()`. [#215](https://github.com/dbfannin/ngx-logger/pull/225). Thanks [@bmtheo](https://github.com/bmtheo)

### Fixed

- Fix missing `HttpClientModule` import ([#212](https://github.com/dbfannin/ngx-logger/pull/212)). Thanks [@markterrill](https://github.com/markterrill)
- Various dependencies bumps

## [4.1.8] - 2020-04-16

Expand All @@ -21,9 +36,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Now supports custom color schemes for logs (see README)


## [4.1.5] - 2020-04-16

### Fixed

- Now support custom format timestamps in addition to pre-defined ones in Angular [@qortex](https://github.com/qortex). Fixes #178.

## Breaking changes for NGX Logger 3.\* to 4.\*

- Importing mocks and the logger testing module should now be imported from the new testing entrypoint
- `import {LoggerTestingModule} from 'ngx-logger/testing';`
119 changes: 67 additions & 52 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
NGX Logger is a simple logging module for angular (currently supports angular 6+). It allows "pretty print" to the console, as well as allowing log messages to be POSTed to a URL for server-side logging.

## Join the NGX Logger discord server!

[Join our discord server!](https://discord.gg/zzkz9ny) Get updated on the latest changes and newest feature! Get help faster from the community! Share implementation strategies! Make friends :)

## We need your help!
As open source projects grow, they become more and more work to maintain. Feature requests and bug fixes take up more and more time. We need your help to make sure we can support our community well. If you're interested in supporting ngx-logger by answering question on github, or submitting PRs for bug fixes or feature requests, please reach out to us! We would love your help!


## Breaking changes for NGX Logger 3.* to 4.*
- Importing mocks and the logger testing module should now be imported from the new testing entrypoint
- `import {LoggerTestingModule} from 'ngx-logger/testing';`

As open source projects grow, they become more and more work to maintain. Feature requests and bug fixes take up more and more time. We need your help to make sure we can support our community well. If you're interested in supporting ngx-logger by answering question on github, or submitting PRs for bug fixes or feature requests, please reach out to us! We would love your help!

## Latest Updates to NGX Logger

- Support for Custom Color Schemes in the config
- uses the LoggerColorScheme type, it is an array of 7 colors, each color matches to a log level. see LogLevelEnum

```typescript
LoggerModule.forRoot({
...,
Expand All @@ -27,73 +25,88 @@ LoggerModule.forRoot({
```

- Support to set WithCredentials on your HTTP requests.

```typescript
this.logger.setWithCredentialsOptionValue(true);
```

- Support for custom parsing of source maps. In order to use it, you must set **enableSourceMaps: true** in your logger config

- Note: In order for the enableSourceMaps flag to work, your app must generate the source maps during the build process. If your using AngularCli you can generate Source Maps by setting **"sourceMap": {"scripts": true}** (or for older version of angularCli **"sourceMap": true**) in your angular.json

- Support of responseType for HTTP Requests. A new config option *httpResponseType* now allows you to set your server's response type.
- Support of responseType for HTTP Requests. A new config option _httpResponseType_ now allows you to set your server's response type.

- Custom HTTP Params
- If you need to pass in custom HTTP Params to your backend server, you can now use `setCustomParams()`.
- If you need to pass in custom HTTP Params to your backend server, you can now use `setCustomParams()`.

```typescript
this.logger.setCustomParams(new HttpParams());
this.logger.setCustomParams(new HttpParams());
```

- Using the NGXLoggerMonitor and want to disable console logs? Now you can!
- New config option disableConsoleLogging will disable console logs, but still alert to the log monitor.

- New config option disableConsoleLogging will disable console logs, but still alert to the log monitor.

- Custom HTTP Headers
- If you use an auth token, or need to pass in a custom header, now you can!
- If you use an auth token, or need to pass in a custom header, now you can!

```typescript
this.logger.setCustomHttpHeaders(new HttpHeaders({'X-Custom-Header': '123456'}));
this.logger.setCustomHttpHeaders(
new HttpHeaders({ "X-Custom-Header": "123456" })
);
```

- Custom Log Monitoring is now available.
- Only one monitor can be registered at a time; registering a new monitor overwrites the previous monitor.
- This should be registered as soon as possible so that it does not miss any logs.
- Custom Log Monitoring is available.
- Only one monitor can be registered at a time; registering a new monitor overwrites the previous monitor.
- This should be registered as soon as possible so that it does not miss any logs.

```typescript
import {NGXLoggerMonitor, NGXLogInterface} from 'ngx-logger';
import { NGXLoggerMonitor, NGXLogInterface } from "ngx-logger";

export class MyLoggerMonitor implements NGXLoggerMonitor {
onLog(log: NGXLogInterface) {
console.log('myCustomLoggerMonitor', log);
}
export class MyLoggerMonitor implements NGXLoggerMonitor {
onLog(log: NGXLogInterface) {
console.log("myCustomLoggerMonitor", log);
}
}
```

```typescript
import {NGXLogger} from 'ngx-logger';
import {MyLoggerMonitor} from './my-logger-monitor';
import { NGXLogger } from "ngx-logger";
import { MyLoggerMonitor } from "./my-logger-monitor";

export class MyService {
constructor(private logger: NGXLogger) {
this.logger.registerMonitor(new MyLoggerMonitor());
export class MyService {
constructor(private logger: NGXLogger) {
this.logger.registerMonitor(new MyLoggerMonitor());

this.logger.error('BLAHBLAHBLAH');
}
this.logger.error("BLAHBLAHBLAH");
}
}
```

- Updating your config after importing the module has never been easier...

```typescript
this.logger.updateConfig({ level: NgxLoggerLevel.DEBUG });
this.logger.updateConfig({ level: NgxLoggerLevel.DEBUG });
```

- You can now create a standalone logger with its own config!
- You can also create a standalone logger with its own config!

```typescript
export class MyService {
private logger: NGXLogger;
constructor(customLogger: CustomNGXLoggerService) {
this.logger = customLogger.create({ level: NgxLoggerLevel.ERROR });
export class MyService {
private logger: NGXLogger;
constructor(customLogger: CustomNGXLoggerService) {
this.logger = customLogger.create({ level: NgxLoggerLevel.ERROR });

this.logger.error('BLAHBLAHBLAH');
}
this.logger.error("BLAHBLAHBLAH");
}
}
```

- You can test the current log levels set:

```typescript
this.logger.level();
this.logger.serverLogLevel();
```

## Dependencies
Expand All @@ -110,7 +123,7 @@ npm install --save ngx-logger
Once installed you need to import our main module and it's dependency on HttpClientModule:

```typescript
import { LoggerModule, NgxLoggerLevel } from 'ngx-logger';
import { LoggerModule, NgxLoggerLevel } from "ngx-logger";
import { HttpClientModule } from "@angular/common/http";
```

Expand All @@ -131,36 +144,38 @@ export class AppModule {
To use the Logger, you will need import it locally, then call one of the logging functions

```typescript
import { Component } from '@angular/core';
import { NGXLogger } from 'ngx-logger';
import { Component } from "@angular/core";
import { NGXLogger } from "ngx-logger";

@Component({
selector: 'your-component',
templateUrl: './your.component.html',
styleUrls: ['your.component.scss']
selector: "your-component",
templateUrl: "./your.component.html",
styleUrls: ["your.component.scss"],
})
export class YourComponent {
constructor(private logger: NGXLogger) {
this.logger.debug('Your log message goes here');
this.logger.debug('Multiple', 'Argument', 'support');
this.logger.debug("Your log message goes here");
this.logger.debug("Multiple", "Argument", "support");
}
}
```

## Config Options

- level {NgxLoggerLevel}: only log messages of this level or higher (`OFF` disables the logger for the client).
- disableConsoleLogging {boolean}: disables console logging, while still alerting the log monitor.
- serverLogLevel {NgxLoggerLevel}: only send log messages of this level or higher to the server (`OFF` disables the logger for the server).
- serverLoggingUrl {string}: URL to POST logs.
- httpResponseType {'arraybuffer' | 'blob' | 'text' | 'json'}: the response type of the HTTP Logging request.
- enableSourceMaps {boolean}: enables manual parsing of Source Maps
- `level` {NgxLoggerLevel}: only log messages of this level or higher (`OFF` disables the logger for the client).
- `disableConsoleLogging` {boolean}: disables console logging, while still alerting the log monitor.
- `serverLogLevel` {NgxLoggerLevel}: only send log messages of this level or higher to the server (`OFF` disables the logger for the server).
- `serverLoggingUrl` {string}: URL to POST logs.
- `httpResponseType` {'arraybuffer' | 'blob' | 'text' | 'json'}: the response type of the HTTP Logging request.
- `enableSourceMaps` {boolean}: enables manual parsing of Source Maps
- Note: In order for the enableSourceMaps flag to work, your app must generate the source maps during the build process. If your using AngularCli you can generate Source Maps by setting **"sourceMap": {"scripts": true}** (or for older version of angularCli **"sourceMap": true**) in your angular.json
- timestampFormat {string}: format for the timestamp displayed with each log message. Can be any of the formatting options accepted by the classic Angular [DatePipe](https://angular.io/api/common/DatePipe#pre-defined-format-options).
- colorScheme {LoggerColorScheme}: a color scheme that defines which color should be used for each log level
- `timestampFormat` {string}: format for the timestamp displayed with each log message. Can be any of the formatting options accepted by the classic Angular [DatePipe](https://angular.io/api/common/DatePipe#pre-defined-format-options).
- `colorScheme` {LoggerColorScheme}: a color scheme that defines which color should be used for each log level
- Note: the index of the scheme relates to the log level value
- `disableFileDetails` {boolean} (defaults to false). When set to `true`, filename details will not be shown in log messages.
- `proxiedSteps` {number}. That many steps will be ignored in the stack trace to compute the caller location. If you happen to always see the same location reported in the logs (for example a wrapper service of your own), tune this option to skip this step in the stack traces.

NgxLoggerLevels: `TRACE|DEBUG|INFO|LOG|WARN|ERROR|FATAL|OFF`
`NgxLoggerLevels` are: `TRACE|DEBUG|INFO|LOG|WARN|ERROR|FATAL|OFF`

## Server-Side Logging

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ngx-logger",
"version": "4.1.9",
"version": "4.2.0",
"license": "MIT",
"scripts": {
"ng": "ng",
Expand Down Expand Up @@ -33,7 +33,9 @@
"th3n3wguy <[email protected]>",
"bniedermeyer",
"jbarrett732",
"qortex"
"qortex",
"bmtheo",
"amilor"
],
"keywords": [
"angular",
Expand Down
12 changes: 5 additions & 7 deletions src/lib/logger.config.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import {LoggerColorScheme} from './types/logger-color-scheme';
import {NgxLoggerLevel} from './types/logger-level.enum';
import { LoggerColorScheme } from "./types/logger-color-scheme";
import { NgxLoggerLevel } from "./types/logger-level.enum";

export class LoggerConfig {
level: NgxLoggerLevel;
serverLogLevel?: NgxLoggerLevel;
serverLoggingUrl?: string;
disableConsoleLogging?: boolean;
httpResponseType?: 'arraybuffer' | 'blob' | 'text' | 'json';
httpResponseType?: "arraybuffer" | "blob" | "text" | "json";
enableSourceMaps?: boolean;
/** Number of calls that will be ignored when trying to get line of stacktrace
* The base number is 5. The result number is 5 + proxiedSteps
*/
proxiedSteps?: number;
/** Number of calls that will be ignored when trying to get line of stacktrace */
proxiedSteps?: number;
/** Timestamp format: any format accepted by Angular DatePipe. Defaults to ISOString */
timestampFormat?: string;
colorScheme?: LoggerColorScheme;
Expand Down

0 comments on commit 1d99652

Please sign in to comment.