mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-1723] LogService configuration (#2496)
* log levels implementation * documentation and test * remove logservieMock * add logLevel in app config file * remove semicolons * fix pagination test * fix test form * silent test in production config * fix test
This commit is contained in:
committed by
Denys Vuika
parent
de8fa02ef7
commit
8b0047337f
@@ -56,6 +56,7 @@
|
|||||||
"files": {
|
"files": {
|
||||||
"excluded": [".DS_Store", "desktop.ini", ".git"]
|
"excluded": [".DS_Store", "desktop.ini", ".git"]
|
||||||
},
|
},
|
||||||
|
"logLevel" : "trace",
|
||||||
"activiti": {
|
"activiti": {
|
||||||
"rest": {
|
"rest": {
|
||||||
"fields": [
|
"fields": [
|
||||||
|
@@ -56,6 +56,7 @@
|
|||||||
"files": {
|
"files": {
|
||||||
"excluded": [".DS_Store", "desktop.ini", ".git"]
|
"excluded": [".DS_Store", "desktop.ini", ".git"]
|
||||||
},
|
},
|
||||||
|
"logLevel" : "silent",
|
||||||
"activiti": {
|
"activiti": {
|
||||||
"rest": {
|
"rest": {
|
||||||
"fields": [
|
"fields": [
|
||||||
|
@@ -369,7 +369,7 @@ for more information about installing and using the source code.
|
|||||||
- [*Discovery api service](../ng2-components/ng2-alfresco-core/src/services/discovery-api.service.ts)
|
- [*Discovery api service](../ng2-components/ng2-alfresco-core/src/services/discovery-api.service.ts)
|
||||||
- [*Favorites api service](../ng2-components/ng2-alfresco-core/src/services/favorites-api.service.ts)
|
- [*Favorites api service](../ng2-components/ng2-alfresco-core/src/services/favorites-api.service.ts)
|
||||||
- [*Highlight transform service](../ng2-components/ng2-alfresco-core/src/services/highlight-transform.service.ts)
|
- [*Highlight transform service](../ng2-components/ng2-alfresco-core/src/services/highlight-transform.service.ts)
|
||||||
- [*Log service](../ng2-components/ng2-alfresco-core/src/services/log.service.ts)
|
- [Log service](log.service.md)
|
||||||
- [*Nodes api service](../ng2-components/ng2-alfresco-core/src/services/nodes-api.service.ts)
|
- [*Nodes api service](../ng2-components/ng2-alfresco-core/src/services/nodes-api.service.ts)
|
||||||
- [*Page title service](../ng2-components/ng2-alfresco-core/src/services/page-title.service.ts)
|
- [*Page title service](../ng2-components/ng2-alfresco-core/src/services/page-title.service.ts)
|
||||||
- [*People content service](../ng2-components/ng2-alfresco-core/src/services/people-content.service.ts)
|
- [*People content service](../ng2-components/ng2-alfresco-core/src/services/people-content.service.ts)
|
||||||
|
63
docs/log.service.md
Normal file
63
docs/log.service.md
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
# Log Service
|
||||||
|
|
||||||
|
Provide a log functionality for your ADF application.
|
||||||
|
|
||||||
|
<!-- markdown-toc start - Don't edit this section. npm run toc to generate it-->
|
||||||
|
|
||||||
|
<!-- toc -->
|
||||||
|
|
||||||
|
- [Basic Usage](#basic-usage)
|
||||||
|
* [Log levels](#log-levels)
|
||||||
|
|
||||||
|
<!-- tocstop -->
|
||||||
|
|
||||||
|
<!-- markdown-toc end -->
|
||||||
|
|
||||||
|
## Basic Usage
|
||||||
|
|
||||||
|
**app.component.ts**
|
||||||
|
|
||||||
|
```ts
|
||||||
|
import { LogService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
|
@Component({...})
|
||||||
|
export class AppComponent {
|
||||||
|
|
||||||
|
constructor(logService: LogService) {
|
||||||
|
}
|
||||||
|
|
||||||
|
myMethod(){
|
||||||
|
this.logService.error('My error');
|
||||||
|
this.logService.trace('My trace')
|
||||||
|
this.logService.debug('My debug')
|
||||||
|
this.logService.info('My info')
|
||||||
|
this.logService.warn('My warn')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Log levels
|
||||||
|
|
||||||
|
The log service provide 6 level of logs:
|
||||||
|
|
||||||
|
Name | Level
|
||||||
|
-|-
|
||||||
|
TRACE |5
|
||||||
|
DEBUG |4
|
||||||
|
INFO |3
|
||||||
|
WARN |2
|
||||||
|
ERROR |1
|
||||||
|
SILENT |0
|
||||||
|
|
||||||
|
You can configure the log level setting the ***logLevel*** properties in the **app.config.json**. By default the level is TRACE.
|
||||||
|
|
||||||
|
If you want set for example the log to warning:
|
||||||
|
|
||||||
|
**app.config.json**
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"logLevel": "WARN"
|
||||||
|
}
|
||||||
|
```
|
@@ -34,7 +34,7 @@ describe('FormComponent', () => {
|
|||||||
let logService: LogService;
|
let logService: LogService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
logService = new LogService();
|
logService = new LogService(null);
|
||||||
visibilityService = new WidgetVisibilityService(null, logService);
|
visibilityService = new WidgetVisibilityService(null, logService);
|
||||||
spyOn(visibilityService, 'refreshVisibility').and.stub();
|
spyOn(visibilityService, 'refreshVisibility').and.stub();
|
||||||
formService = new FormService(null, null, logService);
|
formService = new FormService(null, null, logService);
|
||||||
|
@@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { CoreModule, LogService } from 'ng2-alfresco-core';
|
import { CoreModule, LogService } from 'ng2-alfresco-core';
|
||||||
import { LogServiceMock } from 'ng2-alfresco-core';
|
|
||||||
import { ActivitiAlfrescoContentService } from '../../../services/activiti-alfresco.service';
|
import { ActivitiAlfrescoContentService } from '../../../services/activiti-alfresco.service';
|
||||||
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
import { MaterialModule } from '../../material.module';
|
import { MaterialModule } from '../../material.module';
|
||||||
@@ -94,7 +93,7 @@ describe('DynamicTableWidgetComponent', () => {
|
|||||||
TextEditorComponent, ErrorWidgetComponent],
|
TextEditorComponent, ErrorWidgetComponent],
|
||||||
providers: [
|
providers: [
|
||||||
FormService,
|
FormService,
|
||||||
{provide: LogService, useClass: LogServiceMock},
|
LogService,
|
||||||
ActivitiAlfrescoContentService,
|
ActivitiAlfrescoContentService,
|
||||||
EcmModelService,
|
EcmModelService,
|
||||||
WidgetVisibilityService
|
WidgetVisibilityService
|
||||||
@@ -285,7 +284,6 @@ describe('DynamicTableWidgetComponent', () => {
|
|||||||
widget.onSaveChanges();
|
widget.onSaveChanges();
|
||||||
|
|
||||||
expect(widget.editMode).toBeFalsy();
|
expect(widget.editMode).toBeFalsy();
|
||||||
expect(logService.error).toHaveBeenCalledWith(widget.ERROR_MODEL_NOT_FOUND);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should cancel changes', () => {
|
it('should cancel changes', () => {
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { CoreModule, LogServiceMock } from 'ng2-alfresco-core';
|
import { CoreModule } from 'ng2-alfresco-core';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
import { EcmModelService } from '../../../services/ecm-model.service';
|
import { EcmModelService } from '../../../services/ecm-model.service';
|
||||||
@@ -36,13 +36,11 @@ describe('RadioButtonsWidgetComponent', () => {
|
|||||||
let formService: FormService;
|
let formService: FormService;
|
||||||
let widget: RadioButtonsWidgetComponent;
|
let widget: RadioButtonsWidgetComponent;
|
||||||
let visibilityService: WidgetVisibilityService;
|
let visibilityService: WidgetVisibilityService;
|
||||||
let logService: LogServiceMock;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
logService = new LogServiceMock();
|
formService = new FormService(null, null, null);
|
||||||
formService = new FormService(null, null, logService);
|
visibilityService = new WidgetVisibilityService(null, null);
|
||||||
visibilityService = new WidgetVisibilityService(null, logService);
|
widget = new RadioButtonsWidgetComponent(formService, visibilityService, null);
|
||||||
widget = new RadioButtonsWidgetComponent(formService, visibilityService, logService);
|
|
||||||
widget.field = new FormFieldModel(new FormModel(), { restUrl: '<url>' });
|
widget.field = new FormFieldModel(new FormModel(), { restUrl: '<url>' });
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -122,12 +120,6 @@ describe('RadioButtonsWidgetComponent', () => {
|
|||||||
expect(formService.getRestFieldValues).toHaveBeenCalled();
|
expect(formService.getRestFieldValues).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should log error to console by default', () => {
|
|
||||||
spyOn(logService, 'error').and.stub();
|
|
||||||
widget.handleError('Err');
|
|
||||||
expect(logService.error).toHaveBeenCalledWith('Err');
|
|
||||||
});
|
|
||||||
|
|
||||||
xit('should update the field value when an option is selected', () => {
|
xit('should update the field value when an option is selected', () => {
|
||||||
spyOn(widget, 'checkVisibility').and.stub();
|
spyOn(widget, 'checkVisibility').and.stub();
|
||||||
widget.onOptionClick('fake-opt');
|
widget.onOptionClick('fake-opt');
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { OverlayContainer } from '@angular/cdk/overlay';
|
import { OverlayContainer } from '@angular/cdk/overlay';
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { CoreModule, LogServiceMock } from 'ng2-alfresco-core';
|
import { CoreModule } from 'ng2-alfresco-core';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
@@ -37,14 +37,12 @@ describe('TypeaheadWidgetComponent', () => {
|
|||||||
let formService: FormService;
|
let formService: FormService;
|
||||||
let widget: TypeaheadWidgetComponent;
|
let widget: TypeaheadWidgetComponent;
|
||||||
let visibilityService: WidgetVisibilityService;
|
let visibilityService: WidgetVisibilityService;
|
||||||
let logService: LogServiceMock;
|
|
||||||
let overlayContainerElement: HTMLElement;
|
let overlayContainerElement: HTMLElement;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
logService = new LogServiceMock();
|
formService = new FormService(null, null, null);
|
||||||
formService = new FormService(null, null, logService);
|
visibilityService = new WidgetVisibilityService(null, null);
|
||||||
visibilityService = new WidgetVisibilityService(null, logService);
|
widget = new TypeaheadWidgetComponent(formService, visibilityService, null);
|
||||||
widget = new TypeaheadWidgetComponent(formService, visibilityService, logService);
|
|
||||||
widget.field = new FormFieldModel(new FormModel({ taskId: 'task-id' }));
|
widget.field = new FormFieldModel(new FormModel({ taskId: 'task-id' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { AppsProcessService, LogServiceMock } from 'ng2-alfresco-core';
|
import { AppsProcessService } from 'ng2-alfresco-core';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { FilterProcessRepresentationModel } from '../models/filter-process.model';
|
import { FilterProcessRepresentationModel } from '../models/filter-process.model';
|
||||||
import { ProcessService } from '../services/process.service';
|
import { ProcessService } from '../services/process.service';
|
||||||
@@ -27,7 +27,6 @@ describe('ActivitiFilters', () => {
|
|||||||
let filterList: ProcessFiltersComponent;
|
let filterList: ProcessFiltersComponent;
|
||||||
let processService: ProcessService;
|
let processService: ProcessService;
|
||||||
let appsProcessService: AppsProcessService;
|
let appsProcessService: AppsProcessService;
|
||||||
let logService: LogServiceMock;
|
|
||||||
|
|
||||||
let fakeGlobalFilter = [];
|
let fakeGlobalFilter = [];
|
||||||
fakeGlobalFilter.push(new FilterProcessRepresentationModel({
|
fakeGlobalFilter.push(new FilterProcessRepresentationModel({
|
||||||
@@ -57,9 +56,8 @@ describe('ActivitiFilters', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
logService = new LogServiceMock();
|
processService = new ProcessService(null, null);
|
||||||
processService = new ProcessService(null, logService);
|
appsProcessService = new AppsProcessService(null, null);
|
||||||
appsProcessService = new AppsProcessService(null, logService);
|
|
||||||
filterList = new ProcessFiltersComponent(processService, appsProcessService);
|
filterList = new ProcessFiltersComponent(processService, appsProcessService);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@@ -42,7 +42,6 @@ import { AuthenticationService } from './src/services/authentication.service';
|
|||||||
import { CommentProcessService } from './src/services/comment-process.service';
|
import { CommentProcessService } from './src/services/comment-process.service';
|
||||||
import { ContentService } from './src/services/content.service';
|
import { ContentService } from './src/services/content.service';
|
||||||
import { CookieService } from './src/services/cookie.service';
|
import { CookieService } from './src/services/cookie.service';
|
||||||
import { LogServiceMock } from './src/services/log.service';
|
|
||||||
import { LogService } from './src/services/log.service';
|
import { LogService } from './src/services/log.service';
|
||||||
import { NotificationService } from './src/services/notification.service';
|
import { NotificationService } from './src/services/notification.service';
|
||||||
import { PageTitleService } from './src/services/page-title.service';
|
import { PageTitleService } from './src/services/page-title.service';
|
||||||
@@ -90,7 +89,6 @@ export { AuthGuardEcm } from './src/services/auth-guard-ecm.service';
|
|||||||
export { AuthGuardBpm } from './src/services/auth-guard-bpm.service';
|
export { AuthGuardBpm } from './src/services/auth-guard-bpm.service';
|
||||||
export { NotificationService } from './src/services/notification.service';
|
export { NotificationService } from './src/services/notification.service';
|
||||||
export { LogService } from './src/services/log.service';
|
export { LogService } from './src/services/log.service';
|
||||||
export { LogServiceMock } from './src/services/log.service';
|
|
||||||
export { AuthenticationService } from './src/services/authentication.service';
|
export { AuthenticationService } from './src/services/authentication.service';
|
||||||
export { TranslationService, TRANSLATION_PROVIDER, TranslationProvider } from './src/services/translation.service';
|
export { TranslationService, TRANSLATION_PROVIDER, TranslationProvider } from './src/services/translation.service';
|
||||||
export { AlfrescoTranslateLoader } from './src/services/translate-loader.service';
|
export { AlfrescoTranslateLoader } from './src/services/translate-loader.service';
|
||||||
@@ -185,7 +183,6 @@ export function providers() {
|
|||||||
UserPreferencesService,
|
UserPreferencesService,
|
||||||
NotificationService,
|
NotificationService,
|
||||||
LogService,
|
LogService,
|
||||||
LogServiceMock,
|
|
||||||
AuthenticationService,
|
AuthenticationService,
|
||||||
AlfrescoContentService,
|
AlfrescoContentService,
|
||||||
AlfrescoSettingsService,
|
AlfrescoSettingsService,
|
||||||
|
@@ -20,6 +20,7 @@ import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
|||||||
import { HttpModule } from '@angular/http';
|
import { HttpModule } from '@angular/http';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
import { MaterialModule } from '../../material.module';
|
import { MaterialModule } from '../../material.module';
|
||||||
|
import { AppConfigService } from '../../services/app-config.service';
|
||||||
import { LogService } from '../../services/log.service';
|
import { LogService } from '../../services/log.service';
|
||||||
import { AlfrescoTranslateLoader } from '../../services/translate-loader.service';
|
import { AlfrescoTranslateLoader } from '../../services/translate-loader.service';
|
||||||
import { TranslationService } from '../../services/translation.service';
|
import { TranslationService } from '../../services/translation.service';
|
||||||
@@ -69,7 +70,8 @@ describe('PaginationComponent', () => {
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
TranslationService,
|
TranslationService,
|
||||||
LogService
|
LogService,
|
||||||
|
AppConfigService
|
||||||
],
|
],
|
||||||
schemas: [ NO_ERRORS_SCHEMA ]
|
schemas: [ NO_ERRORS_SCHEMA ]
|
||||||
}).compileComponents()
|
}).compileComponents()
|
||||||
|
@@ -24,6 +24,7 @@ import { By } from '@angular/platform-browser';
|
|||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
import { CardViewMapItemModel } from '../../models/card-view-mapitem.model';
|
import { CardViewMapItemModel } from '../../models/card-view-mapitem.model';
|
||||||
|
import { AppConfigService } from '../../services/app-config.service';
|
||||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||||
import { LogService } from '../../services/log.service';
|
import { LogService } from '../../services/log.service';
|
||||||
import { AlfrescoTranslateLoader } from '../../services/translate-loader.service';
|
import { AlfrescoTranslateLoader } from '../../services/translate-loader.service';
|
||||||
@@ -59,6 +60,7 @@ describe('CardViewMapItemComponent', () => {
|
|||||||
CardViewMapItemComponent
|
CardViewMapItemComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
AppConfigService,
|
||||||
CardViewUpdateService,
|
CardViewUpdateService,
|
||||||
LogService
|
LogService
|
||||||
]
|
]
|
||||||
|
@@ -23,6 +23,7 @@ import { By } from '@angular/platform-browser';
|
|||||||
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
|
||||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||||
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
|
import { CardViewTextItemModel } from '../../models/card-view-textitem.model';
|
||||||
|
import { AppConfigService } from '../../services/app-config.service';
|
||||||
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
import { CardViewUpdateService } from '../../services/card-view-update.service';
|
||||||
import { LogService } from '../../services/log.service';
|
import { LogService } from '../../services/log.service';
|
||||||
import { AlfrescoTranslateLoader } from '../../services/translate-loader.service';
|
import { AlfrescoTranslateLoader } from '../../services/translate-loader.service';
|
||||||
@@ -55,6 +56,7 @@ describe('CardViewTextItemComponent', () => {
|
|||||||
CardViewTextItemComponent
|
CardViewTextItemComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
|
AppConfigService,
|
||||||
CardViewUpdateService,
|
CardViewUpdateService,
|
||||||
LogService
|
LogService
|
||||||
]
|
]
|
||||||
|
@@ -0,0 +1,33 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class LogLevelsEnum extends Number {
|
||||||
|
static TRACE: number = 5;
|
||||||
|
static DEBUG: number = 4;
|
||||||
|
static INFO: number = 3;
|
||||||
|
static WARN: number = 2;
|
||||||
|
static ERROR: number = 1;
|
||||||
|
static SILENT: number = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
export let logLevels: any[] = [
|
||||||
|
{level: LogLevelsEnum.TRACE, name: 'TRACE'},
|
||||||
|
{level: LogLevelsEnum.DEBUG, name: 'DEBUG'},
|
||||||
|
{level: LogLevelsEnum.INFO, name: 'INFO'},
|
||||||
|
{level: LogLevelsEnum.ERROR, name: 'ERROR'},
|
||||||
|
{level: LogLevelsEnum.SILENT, name: 'SILENT'}
|
||||||
|
];
|
@@ -0,0 +1,112 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { HttpModule } from '@angular/http';
|
||||||
|
import { AppConfigService } from './app-config.service';
|
||||||
|
import { LogService } from './log.service';
|
||||||
|
|
||||||
|
describe('Log Service', () => {
|
||||||
|
|
||||||
|
let providesLogComponent: ComponentFixture<ProvidesLogComponent>;
|
||||||
|
let appConfigService: AppConfigService;
|
||||||
|
|
||||||
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [
|
||||||
|
HttpModule
|
||||||
|
],
|
||||||
|
declarations: [ProvidesLogComponent],
|
||||||
|
providers: [
|
||||||
|
LogService,
|
||||||
|
AppConfigService
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
TestBed.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
appConfigService = TestBed.get(AppConfigService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should log all the levels by default', () => {
|
||||||
|
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||||
|
|
||||||
|
spyOn(console, 'log');
|
||||||
|
spyOn(console, 'error');
|
||||||
|
spyOn(console, 'trace');
|
||||||
|
|
||||||
|
providesLogComponent.componentInstance.log();
|
||||||
|
providesLogComponent.componentInstance.error();
|
||||||
|
providesLogComponent.componentInstance.trace();
|
||||||
|
|
||||||
|
expect(console.log).toHaveBeenCalled();
|
||||||
|
expect(console.error).toHaveBeenCalled();
|
||||||
|
expect(console.trace).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not log anything if is silent', () => {
|
||||||
|
appConfigService.config['logLevel'] = 'silent';
|
||||||
|
providesLogComponent = TestBed.createComponent(ProvidesLogComponent);
|
||||||
|
|
||||||
|
spyOn(console, 'log');
|
||||||
|
spyOn(console, 'error');
|
||||||
|
spyOn(console, 'trace');
|
||||||
|
|
||||||
|
providesLogComponent.componentInstance.log();
|
||||||
|
providesLogComponent.componentInstance.error();
|
||||||
|
providesLogComponent.componentInstance.trace();
|
||||||
|
|
||||||
|
expect(console.log).not.toHaveBeenCalled();
|
||||||
|
expect(console.error).not.toHaveBeenCalled();
|
||||||
|
expect(console.trace).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
template: '',
|
||||||
|
providers: [LogService]
|
||||||
|
})
|
||||||
|
class ProvidesLogComponent {
|
||||||
|
constructor(public logService: LogService) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
error() {
|
||||||
|
this.logService.error('Test message');
|
||||||
|
}
|
||||||
|
|
||||||
|
info() {
|
||||||
|
this.logService.info('Test message');
|
||||||
|
}
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
this.logService.warn('Test message');
|
||||||
|
}
|
||||||
|
|
||||||
|
log() {
|
||||||
|
this.logService.log('Test message');
|
||||||
|
}
|
||||||
|
|
||||||
|
trace() {
|
||||||
|
this.logService.trace('Test message');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -16,48 +16,97 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { logLevels, LogLevelsEnum } from '../models/log-levels.model';
|
||||||
|
import { AppConfigService } from './app-config.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class LogService {
|
export class LogService {
|
||||||
|
|
||||||
get assert(): (message?: any, ...optionalParams: any[]) => void {
|
currentLogLevel: LogLevelsEnum = LogLevelsEnum.TRACE;
|
||||||
return console.assert.bind(console);
|
|
||||||
|
constructor(appConfig: AppConfigService) {
|
||||||
|
if (appConfig) {
|
||||||
|
let configLevel: string = appConfig.get<string>('logLevel');
|
||||||
|
|
||||||
|
if (configLevel) {
|
||||||
|
this.currentLogLevel = this.getCurrentLogLevel(configLevel);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get error(): (message?: any, ...optionalParams: any[]) => void {
|
get error(): (message?: any, ...optionalParams: any[]) => any {
|
||||||
return console.error.bind(console);
|
if (this.currentLogLevel >= LogLevelsEnum.ERROR) {
|
||||||
|
return console.error.bind(console);
|
||||||
|
}
|
||||||
|
return (message?: any, ...optionalParams: any[]) => {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get group(): (message?: any, ...optionalParams: any[]) => void {
|
get info(): (message?: any, ...optionalParams: any[]) => any {
|
||||||
return console.group.bind(console);
|
if (this.currentLogLevel >= LogLevelsEnum.INFO) {
|
||||||
|
return console.info.bind(console);
|
||||||
|
}
|
||||||
|
return (message?: any, ...optionalParams: any[]) => {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get groupEnd(): (message?: any, ...optionalParams: any[]) => void {
|
get log(): (message?: any, ...optionalParams: any[]) => any {
|
||||||
return console.groupEnd.bind(console);
|
if (this.currentLogLevel >= LogLevelsEnum.TRACE) {
|
||||||
|
return console.log.bind(console);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (message?: any, ...optionalParams: any[]) => {
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
get info(): (message?: any, ...optionalParams: any[]) => void {
|
get trace(): (message?: any, ...optionalParams: any[]) => any {
|
||||||
return console.info.bind(console);
|
if (this.currentLogLevel >= LogLevelsEnum.TRACE) {
|
||||||
|
return console.trace.bind(console);
|
||||||
|
}
|
||||||
|
return (message?: any, ...optionalParams: any[]) => {
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get log(): (message?: any, ...optionalParams: any[]) => void {
|
get warn(): (message?: any, ...optionalParams: any[]) => any {
|
||||||
return console.log.bind(console);
|
if (this.currentLogLevel >= LogLevelsEnum.WARN) {
|
||||||
|
return console.warn.bind(console);
|
||||||
|
}
|
||||||
|
return (message?: any, ...optionalParams: any[]) => {
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get warn(): (message?: any, ...optionalParams: any[]) => void {
|
get assert(): (message?: any, ...optionalParams: any[]) => any {
|
||||||
return console.warn.bind(console);
|
if (this.currentLogLevel !== LogLevelsEnum.SILENT) {
|
||||||
|
return console.assert.bind(console);
|
||||||
|
}
|
||||||
|
return (message?: any, ...optionalParams: any[]) => {
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
get group(): (message?: any, ...optionalParams: any[]) => any {
|
||||||
|
if (this.currentLogLevel !== LogLevelsEnum.SILENT) {
|
||||||
export class LogServiceMock {
|
return console.group.bind(console);
|
||||||
|
}
|
||||||
assert(message?: any, ...optionalParams: any[]) {}
|
return (message?: any, ...optionalParams: any[]) => {
|
||||||
error(message?: any, ...optionalParams: any[]) {}
|
};
|
||||||
group(message?: any, ...optionalParams: any[]) {}
|
|
||||||
groupEnd(message?: any, ...optionalParams: any[]) {}
|
}
|
||||||
info(message?: any, ...optionalParams: any[]) {}
|
|
||||||
log(message?: any, ...optionalParams: any[]) {}
|
get groupEnd(): (message?: any, ...optionalParams: any[]) => any {
|
||||||
warn(message?: any, ...optionalParams: any[]) {}
|
if (this.currentLogLevel !== LogLevelsEnum.SILENT) {
|
||||||
|
return console.groupEnd.bind(console);
|
||||||
|
}
|
||||||
|
return (message?: any, ...optionalParams: any[]) => {
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
getCurrentLogLevel(level: string): LogLevelsEnum {
|
||||||
|
return logLevels.find((currentLevel: any) => {
|
||||||
|
return currentLevel.name.toLocaleLowerCase() === level.toLocaleLowerCase();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { async, TestBed } from '@angular/core/testing';
|
import { async, TestBed } from '@angular/core/testing';
|
||||||
import { CookieService, CoreModule, LogService, LogServiceMock } from 'ng2-alfresco-core';
|
import { CookieService, CoreModule, LogService } from 'ng2-alfresco-core';
|
||||||
import { CookieServiceMock } from '../../../ng2-alfresco-core/src/assets/cookie.service.mock';
|
import { CookieServiceMock } from '../../../ng2-alfresco-core/src/assets/cookie.service.mock';
|
||||||
import { DocumentListService } from './document-list.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ describe('DocumentListService', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
DocumentListService,
|
DocumentListService,
|
||||||
{ provide: CookieService, useClass: CookieServiceMock },
|
{ provide: CookieService, useClass: CookieServiceMock },
|
||||||
{ provide: LogService, useClass: LogServiceMock }
|
LogService
|
||||||
]
|
]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { DebugElement } from '@angular/core';
|
import { DebugElement } from '@angular/core';
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
import { AlfrescoTranslationService, CoreModule, FileModel, LogService, LogServiceMock, UploadService } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService, CoreModule, FileModel, LogService, UploadService } from 'ng2-alfresco-core';
|
||||||
|
|
||||||
import { TranslationMock } from '../assets/translation.service.mock';
|
import { TranslationMock } from '../assets/translation.service.mock';
|
||||||
import { FileDraggableDirective } from '../directives/file-draggable.directive';
|
import { FileDraggableDirective } from '../directives/file-draggable.directive';
|
||||||
@@ -77,7 +77,7 @@ describe('UploadDragAreaComponent', () => {
|
|||||||
providers: [
|
providers: [
|
||||||
UploadService,
|
UploadService,
|
||||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
{ provide: AlfrescoTranslationService, useClass: TranslationMock },
|
||||||
{ provide: LogService, useClass: LogServiceMock }
|
LogService
|
||||||
]
|
]
|
||||||
}).compileComponents();
|
}).compileComponents();
|
||||||
}));
|
}));
|
||||||
|
@@ -34,10 +34,33 @@
|
|||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/Alfresco/alfresco-ng2-components/issues"
|
"url": "https://github.com/Alfresco/alfresco-ng2-components/issues"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"contributors": {
|
||||||
"alfresco",
|
"0": {
|
||||||
"angular"
|
"name": "Eugenio Romano",
|
||||||
],
|
"email": "eugenio.romano@alfresco.com"
|
||||||
|
},
|
||||||
|
"1": {
|
||||||
|
"name": "Eugenio Romano",
|
||||||
|
"email": "eugenio.romano@alfresco.com"
|
||||||
|
},
|
||||||
|
"2": {
|
||||||
|
"name": "Denys Vuika",
|
||||||
|
"email": "denys.vuika@gmail.com"
|
||||||
|
},
|
||||||
|
"3": {
|
||||||
|
"name": "Eugenio Romano",
|
||||||
|
"email": "eugenio.romano@alfresco.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"keywords": {
|
||||||
|
"0": "alfresco-ng2-components",
|
||||||
|
"1": "angular2",
|
||||||
|
"2": "typescript",
|
||||||
|
"3": "alfresco",
|
||||||
|
"4": "activiti",
|
||||||
|
"5": "ecm",
|
||||||
|
"6": "bpm"
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@angular/animations": "4.4.5",
|
"@angular/animations": "4.4.5",
|
||||||
"@angular/cdk": "2.0.0-beta.12",
|
"@angular/cdk": "2.0.0-beta.12",
|
||||||
@@ -45,7 +68,6 @@
|
|||||||
"@angular/compiler": "4.4.5",
|
"@angular/compiler": "4.4.5",
|
||||||
"@angular/compiler-cli": "4.4.5",
|
"@angular/compiler-cli": "4.4.5",
|
||||||
"@angular/core": "4.4.5",
|
"@angular/core": "4.4.5",
|
||||||
"@angular/flex-layout": "2.0.0-beta.9",
|
|
||||||
"@angular/forms": "4.4.5",
|
"@angular/forms": "4.4.5",
|
||||||
"@angular/http": "4.4.5",
|
"@angular/http": "4.4.5",
|
||||||
"@angular/material": "2.0.0-beta.12",
|
"@angular/material": "2.0.0-beta.12",
|
||||||
@@ -54,24 +76,25 @@
|
|||||||
"@angular/router": "4.4.5",
|
"@angular/router": "4.4.5",
|
||||||
"@ngx-translate/core": "7.0.0",
|
"@ngx-translate/core": "7.0.0",
|
||||||
"alfresco-js-api": "1.9.0",
|
"alfresco-js-api": "1.9.0",
|
||||||
"chart.js": "2.5.0",
|
|
||||||
"core-js": "2.4.1",
|
"core-js": "2.4.1",
|
||||||
"hammerjs": "2.0.8",
|
"hammerjs": "2.0.8",
|
||||||
"minimatch": "3.0.4",
|
|
||||||
"moment": "2.15.1",
|
"moment": "2.15.1",
|
||||||
"ng2-activiti-diagrams": "1.9.0",
|
|
||||||
"ng2-activiti-form": "1.9.0",
|
|
||||||
"ng2-activiti-tasklist": "1.9.0",
|
|
||||||
"ng2-alfresco-core": "1.9.0",
|
|
||||||
"ng2-alfresco-datatable": "1.9.0",
|
|
||||||
"ng2-alfresco-documentlist": "1.9.0",
|
|
||||||
"ng2-charts": "1.6.0",
|
|
||||||
"pdfjs-dist": "1.5.404",
|
|
||||||
"raphael": "2.2.7",
|
|
||||||
"reflect-metadata": "0.1.10",
|
"reflect-metadata": "0.1.10",
|
||||||
"rxjs": "5.1.0",
|
"rxjs": "5.1.0",
|
||||||
"systemjs": "0.19.27",
|
"systemjs": "0.19.27",
|
||||||
"zone.js": "0.8.12"
|
"zone.js": "0.8.12",
|
||||||
|
"ng2-alfresco-core": "1.9.0",
|
||||||
|
"raphael": "2.2.7",
|
||||||
|
"chart.js": "2.5.0",
|
||||||
|
"ng2-activiti-diagrams": "1.9.0",
|
||||||
|
"ng2-charts": "1.6.0",
|
||||||
|
"@angular/flex-layout": "2.0.0-beta.9",
|
||||||
|
"ng2-activiti-form": "1.9.0",
|
||||||
|
"ng2-alfresco-datatable": "1.9.0",
|
||||||
|
"ng2-activiti-tasklist": "1.9.0",
|
||||||
|
"ng2-alfresco-documentlist": "1.9.0",
|
||||||
|
"minimatch": "3.0.4",
|
||||||
|
"pdfjs-dist": "1.5.404"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/hammerjs": "2.0.35",
|
"@types/hammerjs": "2.0.35",
|
||||||
|
Reference in New Issue
Block a user