├── .circleci └── config.yml ├── .editorconfig ├── .eslintrc.json ├── .gitignore ├── .npmignore ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE.md ├── LICENSE ├── README.md ├── bower.json ├── build ├── args.js ├── babel-options.js ├── paths.js ├── tasks │ ├── build.js │ ├── clean.js │ ├── dev.js │ ├── doc.js │ ├── lint.js │ ├── prepare-release.js │ └── test.js └── typescript-options.js ├── config.js ├── dist ├── amd │ ├── aurelia-logging.js │ └── index.js ├── aurelia-logging.d.ts ├── aurelia-logging.js ├── commonjs │ ├── aurelia-logging.js │ └── index.js ├── es2015 │ ├── aurelia-logging.js │ └── index.js ├── index.d.ts ├── native-modules │ ├── aurelia-logging.js │ └── index.js └── system │ ├── aurelia-logging.js │ └── index.js ├── doc ├── CHANGELOG.md └── api.json ├── gulpfile.js ├── karma.conf.js ├── package-lock.json ├── package.json ├── src └── index.js ├── test ├── custom-levels.spec.js └── logging.spec.js ├── tsconfig.json └── typings.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | map-1: &filter_only_develop 4 | filters: 5 | branches: 6 | only: develop 7 | 8 | map-2: &filter_only_tag 9 | filters: 10 | branches: 11 | ignore: /.*/ 12 | tags: 13 | only: /^v?[0-9]+(\.[0-9]+)*$/ 14 | 15 | orbs: 16 | v1: aurelia/v1@volatile 17 | 18 | workflows: 19 | main: 20 | jobs: 21 | - v1/build_test 22 | - v1/build_merge: 23 | <<: *filter_only_develop 24 | requires: 25 | - v1/build_test 26 | - v1/npm_publish: 27 | <<: *filter_only_tag 28 | name: npm_publish_dry 29 | args: "--dry-run" 30 | - request_publish_latest: 31 | <<: *filter_only_tag 32 | type: approval 33 | requires: 34 | - npm_publish_dry 35 | - v1/npm_publish: 36 | <<: *filter_only_tag 37 | name: npm_publish 38 | context: Aurelia 39 | requires: 40 | - request_publish_latest 41 | - v1/merge_back: 42 | <<: *filter_only_tag 43 | requires: 44 | - npm_publish 45 | 46 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # 2 space indentation 12 | [**.*] 13 | indent_style = space 14 | indent_size = 2 -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/aurelia-tools/.eslintrc.json" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | jspm_packages 3 | bower_components 4 | .idea 5 | .DS_STORE 6 | build/reports 7 | dist 8 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | jspm_packages 2 | bower_components 3 | .idea 4 | build/reports 5 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | We'd love for you to contribute and to make this project even better than it is today! If this interests you, please begin by reading [our contributing guidelines](https://github.com/DurandalProject/about/blob/master/CONTRIBUTING.md). The contributing document will provide you with all the information you need to get started. Once you have read that, you will need to also [sign our CLA](http://goo.gl/forms/dI8QDDSyKR) before we can accept a Pull Request from you. More information on the process is included in the [contributor's guide](https://github.com/DurandalProject/about/blob/master/CONTRIBUTING.md). 4 | -------------------------------------------------------------------------------- /ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 19 | **I'm submitting a bug report** 20 | **I'm submitting a feature request** 21 | 22 | * **Library Version:** 23 | major.minor.patch-pre 24 | 25 | 26 | **Please tell us about your environment:** 27 | * **Operating System:** 28 | OSX 10.x|Linux (distro)|Windows [7|8|8.1|10] 29 | 30 | * **Node Version:** 31 | 6.2.0 32 | 36 | 37 | * **NPM Version:** 38 | 3.8.9 39 | 43 | 44 | * **JSPM OR Webpack AND Version** 45 | JSPM 0.16.32 | webpack 2.1.0-beta.17 46 | 52 | 53 | * **Browser:** 54 | all | Chrome XX | Firefox XX | Edge XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView 55 | 56 | * **Language:** 57 | all | TypeScript X.X | ESNext 58 | 59 | 60 | **Current behavior:** 61 | 62 | 63 | **Expected/desired behavior:** 64 | 71 | 72 | 73 | * **What is the expected behavior?** 74 | 75 | 76 | * **What is the motivation / use case for changing the behavior?** 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2010 - 2018 Blue Spire Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # aurelia-logging 2 | 3 | [![npm Version](https://img.shields.io/npm/v/aurelia-logging.svg)](https://www.npmjs.com/package/aurelia-logging) 4 | [![ZenHub](https://raw.githubusercontent.com/ZenHubIO/support/master/zenhub-badge.png)](https://zenhub.io) 5 | [![Join the chat at https://gitter.im/aurelia/discuss](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/aurelia/discuss?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 6 | [![CircleCI](https://circleci.com/gh/aurelia/logging.svg?style=shield)](https://circleci.com/gh/aurelia/logging) 7 | 8 | This library is part of the [Aurelia](http://www.aurelia.io/) platform and contains a minimal but effective logging mechanism with support for log levels and pluggable log appenders. 9 | 10 | > To keep up to date on [Aurelia](http://www.aurelia.io/), please visit and subscribe to [the official blog](http://blog.aurelia.io/) and [our email list](http://eepurl.com/ces50j). We also invite you to [follow us on twitter](https://twitter.com/aureliaeffect). If you have questions, please [join our community on Gitter](https://gitter.im/aurelia/discuss) or use [stack overflow](http://stackoverflow.com/search?q=aurelia). Documentation can be found [in our developer hub](http://aurelia.io/hub.html). If you would like to have deeper insight into our development process, please install the [ZenHub](https://zenhub.io) Chrome or Firefox Extension and visit any of our repository's boards. 11 | 12 | ## Platform Support 13 | 14 | This library can be used in the **browser** as well as on the **server**. 15 | 16 | ## Building The Code 17 | 18 | To build the code, follow these steps. 19 | 20 | 1. Ensure that [NodeJS](http://nodejs.org/) is installed. This provides the platform on which the build tooling runs. 21 | 2. From the project folder, execute the following command: 22 | 23 | ```shell 24 | npm install 25 | ``` 26 | 3. Ensure that [Gulp](http://gulpjs.com/) is installed. If you need to install it, use the following command: 27 | 28 | ```shell 29 | npm install -g gulp 30 | ``` 31 | 4. To build the code, you can now run: 32 | 33 | ```shell 34 | gulp build 35 | ``` 36 | 5. You will find the compiled code in the `dist` folder, available in three module formats: AMD, CommonJS and ES6. 37 | 38 | 6. See `gulpfile.js` for other tasks related to generating the docs and linting. 39 | 40 | ## Running The Tests 41 | 42 | To run the unit tests, first ensure that you have followed the steps above in order to install all dependencies and successfully build the library. Once you have done that, proceed with these additional steps: 43 | 44 | 1. Ensure that the [Karma](http://karma-runner.github.io/) CLI is installed. If you need to install it, use the following command: 45 | 46 | ```shell 47 | npm install -g karma-cli 48 | ``` 49 | 2. Ensure that [jspm](http://jspm.io/) is installed. If you need to install it, use the following commnand: 50 | 51 | ```shell 52 | npm install -g jspm 53 | ``` 54 | 3. Download the [SystemJS](https://github.com/systemjs/systemjs) module loader: 55 | 56 | ```shell 57 | jspm dl-loader 58 | ``` 59 | 60 | 4. You can now run the tests with this command: 61 | 62 | ```shell 63 | karma start 64 | ``` 65 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aurelia-logging", 3 | "version": "1.5.3", 4 | "description": "A minimal but effective logging mechanism with support for log levels and pluggable log appenders.", 5 | "keywords": [ 6 | "aurelia", 7 | "logging" 8 | ], 9 | "homepage": "http://aurelia.io", 10 | "main": "dist/commonjs/aurelia-logging.js", 11 | "moduleType": "node", 12 | "license": "MIT", 13 | "authors": [ 14 | "Rob Eisenberg (http://robeisenberg.com/)" 15 | ], 16 | "repository": { 17 | "type": "git", 18 | "url": "http://github.com/aurelia/logging" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /build/args.js: -------------------------------------------------------------------------------- 1 | var yargs = require('yargs'); 2 | 3 | var argv = yargs.argv, 4 | validBumpTypes = "major|minor|patch|prerelease".split("|"), 5 | bump = (argv.bump || 'patch').toLowerCase(); 6 | 7 | if(validBumpTypes.indexOf(bump) === -1) { 8 | throw new Error('Unrecognized bump "' + bump + '".'); 9 | } 10 | 11 | module.exports = { 12 | bump: bump 13 | }; 14 | -------------------------------------------------------------------------------- /build/babel-options.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var paths = require('./paths'); 3 | 4 | exports.base = function() { 5 | var config = { 6 | filename: '', 7 | filenameRelative: '', 8 | sourceMap: true, 9 | sourceRoot: '', 10 | moduleRoot: path.resolve('src').replace(/\\/g, '/'), 11 | moduleIds: false, 12 | comments: false, 13 | compact: false, 14 | code: true, 15 | presets: [ 'es2015-loose', 'stage-1' ], 16 | plugins: [ 17 | 'syntax-flow', 18 | 'transform-decorators-legacy', 19 | ] 20 | }; 21 | if (!paths.useTypeScriptForDTS) { 22 | config.plugins.push( 23 | ['babel-dts-generator', { 24 | packageName: paths.packageName, 25 | typings: '', 26 | suppressModulePath: true, 27 | suppressComments: false, 28 | memberOutputFilter: /^_.*/, 29 | suppressAmbientDeclaration: true 30 | }] 31 | ); 32 | }; 33 | config.plugins.push('transform-flow-strip-types'); 34 | return config; 35 | } 36 | 37 | exports.commonjs = function() { 38 | var options = exports.base(); 39 | options.plugins.push('transform-es2015-modules-commonjs'); 40 | return options; 41 | }; 42 | 43 | exports.amd = function() { 44 | var options = exports.base(); 45 | options.plugins.push('transform-es2015-modules-amd'); 46 | return options; 47 | }; 48 | 49 | exports.system = function() { 50 | var options = exports.base(); 51 | options.plugins.push('transform-es2015-modules-systemjs'); 52 | return options; 53 | }; 54 | 55 | exports.es2015 = function() { 56 | var options = exports.base(); 57 | options.presets = ['stage-1'] 58 | return options; 59 | }; 60 | 61 | exports['native-modules'] = function() { 62 | var options = exports.base(); 63 | options.presets[0] = 'es2015-loose-native-modules'; 64 | return options; 65 | } 66 | -------------------------------------------------------------------------------- /build/paths.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var fs = require('fs'); 3 | 4 | // hide warning // 5 | var emitter = require('events'); 6 | emitter.defaultMaxListeners = 20; 7 | 8 | var appRoot = 'src/'; 9 | var pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')); 10 | 11 | var paths = { 12 | root: appRoot, 13 | source: appRoot + '**/*.js', 14 | html: appRoot + '**/*.html', 15 | style: 'styles/**/*.css', 16 | output: 'dist/', 17 | doc:'./doc', 18 | e2eSpecsSrc: 'test/e2e/src/*.js', 19 | e2eSpecsDist: 'test/e2e/dist/', 20 | packageName: pkg.name, 21 | ignore: [], 22 | useTypeScriptForDTS: false, 23 | importsToAdd: [], 24 | sort: false 25 | }; 26 | 27 | paths.files = [ 28 | 'index.js' 29 | ].map(function(file){ 30 | return paths.root + file; 31 | }); 32 | 33 | module.exports = paths; 34 | -------------------------------------------------------------------------------- /build/tasks/build.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var runSequence = require('run-sequence'); 3 | var to5 = require('gulp-babel'); 4 | var paths = require('../paths'); 5 | var compilerOptions = require('../babel-options'); 6 | var compilerTsOptions = require('../typescript-options'); 7 | var assign = Object.assign || require('object.assign'); 8 | var through2 = require('through2'); 9 | var concat = require('gulp-concat'); 10 | var insert = require('gulp-insert'); 11 | var rename = require('gulp-rename'); 12 | var tools = require('aurelia-tools'); 13 | var ts = require('gulp-typescript'); 14 | var gutil = require('gulp-util'); 15 | var gulpIgnore = require('gulp-ignore'); 16 | var merge = require('merge2'); 17 | var jsName = paths.packageName + '.js'; 18 | var compileToModules = ['es2015', 'commonjs', 'amd', 'system', 'native-modules']; 19 | 20 | function cleanGeneratedCode() { 21 | return through2.obj(function(file, enc, callback) { 22 | file.contents = new Buffer(tools.cleanGeneratedCode(file.contents.toString('utf8'))); 23 | this.push(file); 24 | return callback(); 25 | }); 26 | } 27 | 28 | gulp.task('build-index', function() { 29 | var importsToAdd = paths.importsToAdd.slice(); 30 | 31 | var src = gulp.src(paths.files); 32 | 33 | if (paths.sort) { 34 | src = src.pipe(tools.sortFiles()); 35 | } 36 | 37 | if (paths.ignore) { 38 | paths.ignore.forEach(function(filename){ 39 | src = src.pipe(gulpIgnore.exclude(filename)); 40 | }); 41 | } 42 | 43 | return src.pipe(through2.obj(function(file, enc, callback) { 44 | file.contents = new Buffer(tools.extractImports(file.contents.toString('utf8'), importsToAdd)); 45 | this.push(file); 46 | return callback(); 47 | })) 48 | .pipe(concat(jsName)) 49 | .pipe(insert.transform(function(contents) { 50 | return tools.createImportBlock(importsToAdd) + contents; 51 | })) 52 | .pipe(gulp.dest(paths.output)); 53 | }); 54 | 55 | function gulpFileFromString(filename, string) { 56 | var src = require('stream').Readable({ objectMode: true }); 57 | src._read = function() { 58 | this.push(new gutil.File({ cwd: paths.appRoot, base: paths.output, path: filename, contents: new Buffer(string) })) 59 | this.push(null) 60 | } 61 | return src; 62 | } 63 | 64 | function srcForBabel() { 65 | return merge( 66 | gulp.src(paths.output + jsName), 67 | gulpFileFromString(paths.output + 'index.js', "export * from './" + paths.packageName + "';") 68 | ); 69 | } 70 | 71 | function srcForTypeScript() { 72 | return gulp 73 | .src(paths.output + paths.packageName + '.js') 74 | .pipe(rename(function (path) { 75 | if (path.extname == '.js') { 76 | path.extname = '.ts'; 77 | } 78 | })); 79 | } 80 | 81 | compileToModules.forEach(function(moduleType){ 82 | gulp.task('build-babel-' + moduleType, function () { 83 | return srcForBabel() 84 | .pipe(to5(assign({}, compilerOptions[moduleType]()))) 85 | .pipe(cleanGeneratedCode()) 86 | .pipe(gulp.dest(paths.output + moduleType)); 87 | }); 88 | 89 | if (moduleType === 'native-modules') return; // typescript doesn't support the combination of: es5 + native modules 90 | 91 | gulp.task('build-ts-' + moduleType, function () { 92 | var tsProject = ts.createProject( 93 | compilerTsOptions({ module: moduleType, target: moduleType == 'es2015' ? 'es2015' : 'es5' }), ts.reporter.defaultReporter()); 94 | var tsResult = srcForTypeScript().pipe(ts(tsProject)); 95 | return tsResult.js 96 | .pipe(gulp.dest(paths.output + moduleType)); 97 | }); 98 | }); 99 | 100 | gulp.task('build-dts', function() { 101 | var tsProject = ts.createProject( 102 | compilerTsOptions({ removeComments: false, target: "es2015", module: "es2015" }), ts.reporter.defaultReporter()); 103 | var tsResult = srcForTypeScript().pipe(ts(tsProject)); 104 | return tsResult.dts 105 | .pipe(gulp.dest(paths.output)); 106 | }); 107 | 108 | gulp.task('build', function(callback) { 109 | return runSequence( 110 | 'clean', 111 | 'build-index', 112 | compileToModules 113 | .map(function(moduleType) { return 'build-babel-' + moduleType }) 114 | .concat(paths.useTypeScriptForDTS ? ['build-dts'] : []), 115 | callback 116 | ); 117 | }); 118 | 119 | gulp.task('build-ts', function(callback) { 120 | return runSequence( 121 | 'clean', 122 | 'build-index', 123 | 'build-babel-native-modules', 124 | compileToModules 125 | .filter(function(moduleType) { return moduleType !== 'native-modules' }) 126 | .map(function(moduleType) { return 'build-ts-' + moduleType }) 127 | .concat(paths.useTypeScriptForDTS ? ['build-dts'] : []), 128 | callback 129 | ); 130 | }); 131 | -------------------------------------------------------------------------------- /build/tasks/clean.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var paths = require('../paths'); 3 | var del = require('del'); 4 | var vinylPaths = require('vinyl-paths'); 5 | 6 | gulp.task('clean', function() { 7 | return gulp.src([paths.output]) 8 | .pipe(vinylPaths(del)); 9 | }); 10 | -------------------------------------------------------------------------------- /build/tasks/dev.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var tools = require('aurelia-tools'); 3 | 4 | gulp.task('update-own-deps', function(){ 5 | tools.updateOwnDependenciesFromLocalRepositories(); 6 | }); 7 | 8 | gulp.task('build-dev-env', function () { 9 | tools.buildDevEnv(); 10 | }); 11 | -------------------------------------------------------------------------------- /build/tasks/doc.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var paths = require('../paths'); 3 | var typedoc = require('gulp-typedoc'); 4 | var runSequence = require('run-sequence'); 5 | var through2 = require('through2'); 6 | 7 | gulp.task('doc-generate', function(){ 8 | return gulp.src([paths.output + paths.packageName + '.d.ts']) 9 | .pipe(typedoc({ 10 | target: 'es6', 11 | includeDeclarations: true, 12 | moduleResolution: 'node', 13 | json: paths.doc + '/api.json', 14 | name: paths.packageName + '-docs',  15 | mode: 'modules', 16 | excludeExternals: true, 17 | ignoreCompilerErrors: false, 18 | version: true 19 | })); 20 | }); 21 | 22 | gulp.task('doc-shape', function(){ 23 | return gulp.src([paths.doc + '/api.json']) 24 | .pipe(through2.obj(function(file, enc, callback) { 25 | var json = JSON.parse(file.contents.toString('utf8')).children[0]; 26 | 27 | json = { 28 | name: paths.packageName, 29 | children: json.children, 30 | groups: json.groups 31 | }; 32 | 33 | file.contents = new Buffer(JSON.stringify(json)); 34 | this.push(file); 35 | return callback(); 36 | })) 37 | .pipe(gulp.dest(paths.doc)); 38 | }); 39 | 40 | gulp.task('doc', function(callback){ 41 | return runSequence( 42 | 'doc-generate', 43 | 'doc-shape', 44 | callback 45 | ); 46 | }); 47 | -------------------------------------------------------------------------------- /build/tasks/lint.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var paths = require('../paths'); 3 | var eslint = require('gulp-eslint'); 4 | 5 | gulp.task('lint', function() { 6 | return gulp.src(paths.source) 7 | .pipe(eslint()) 8 | .pipe(eslint.format()) 9 | .pipe(eslint.failOnError()); 10 | }); 11 | -------------------------------------------------------------------------------- /build/tasks/prepare-release.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var runSequence = require('run-sequence'); 3 | var paths = require('../paths'); 4 | var fs = require('fs'); 5 | var bump = require('gulp-bump'); 6 | var args = require('../args'); 7 | var conventionalChangelog = require('gulp-conventional-changelog'); 8 | 9 | gulp.task('changelog', function () { 10 | return gulp.src(paths.doc + '/CHANGELOG.md', { 11 | buffer: false 12 | }).pipe(conventionalChangelog({ 13 | preset: 'angular' 14 | })) 15 | .pipe(gulp.dest(paths.doc)); 16 | }); 17 | 18 | gulp.task('bump-version', function(){ 19 | return gulp.src(['./package.json', './bower.json']) 20 | .pipe(bump({type:args.bump })) //major|minor|patch|prerelease 21 | .pipe(gulp.dest('./')); 22 | }); 23 | 24 | gulp.task('prepare-release', function(callback){ 25 | return runSequence( 26 | 'build', 27 | 'lint', 28 | 'bump-version', 29 | 'doc', 30 | 'changelog', 31 | callback 32 | ); 33 | }); 34 | -------------------------------------------------------------------------------- /build/tasks/test.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var Karma = require('karma').Server; 3 | 4 | /** 5 | * Run test once and exit 6 | */ 7 | gulp.task('test', function (done) { 8 | new Karma({ 9 | configFile: __dirname + '/../../karma.conf.js', 10 | singleRun: true 11 | }, done).start(); 12 | }); 13 | 14 | /** 15 | * Watch for file changes and re-run tests on each change 16 | */ 17 | gulp.task('tdd', function (done) { 18 | new Karma({ 19 | configFile: __dirname + '/../../karma.conf.js' 20 | }, done).start(); 21 | }); 22 | 23 | /** 24 | * Run test once with code coverage and exit 25 | */ 26 | gulp.task('cover', function (done) { 27 | new Karma({ 28 | configFile: __dirname + '/../../karma.conf.js', 29 | singleRun: true, 30 | reporters: ['coverage'], 31 | preprocessors: { 32 | 'test/**/*.js': ['babel'], 33 | 'src/**/*.js': ['babel', 'coverage'] 34 | }, 35 | coverageReporter: { 36 | type: 'html', 37 | dir: 'build/reports/coverage' 38 | } 39 | }, done).start(); 40 | }); 41 | -------------------------------------------------------------------------------- /build/typescript-options.js: -------------------------------------------------------------------------------- 1 | var tsconfig = require('../tsconfig.json'); 2 | var assign = Object.assign || require('object.assign'); 3 | 4 | module.exports = function(override) { 5 | return assign(tsconfig.compilerOptions, { 6 | "target": override && override.target || "es5", 7 | "typescript": require('typescript') 8 | }, override || {}); 9 | } 10 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | System.config({ 2 | defaultJSExtensions: true, 3 | transpiler: "babel", 4 | babelOptions: { 5 | "optional": [ 6 | "runtime", 7 | "optimisation.modules.system" 8 | ] 9 | }, 10 | paths: { 11 | "aurelia-logging/*": "dist/*.js", 12 | "github:*": "jspm_packages/github/*", 13 | "npm:*": "jspm_packages/npm/*" 14 | }, 15 | 16 | map: { 17 | "babel": "npm:babel-core@5.8.38", 18 | "babel-runtime": "npm:babel-runtime@5.8.38", 19 | "core-js": "npm:core-js@2.4.0", 20 | "github:jspm/nodelibs-assert@0.1.0": { 21 | "assert": "npm:assert@1.4.1" 22 | }, 23 | "github:jspm/nodelibs-buffer@0.1.0": { 24 | "buffer": "npm:buffer@3.6.0" 25 | }, 26 | "github:jspm/nodelibs-path@0.1.0": { 27 | "path-browserify": "npm:path-browserify@0.0.0" 28 | }, 29 | "github:jspm/nodelibs-process@0.1.2": { 30 | "process": "npm:process@0.11.5" 31 | }, 32 | "github:jspm/nodelibs-util@0.1.0": { 33 | "util": "npm:util@0.10.3" 34 | }, 35 | "github:jspm/nodelibs-vm@0.1.0": { 36 | "vm-browserify": "npm:vm-browserify@0.0.4" 37 | }, 38 | "npm:assert@1.4.1": { 39 | "assert": "github:jspm/nodelibs-assert@0.1.0", 40 | "buffer": "github:jspm/nodelibs-buffer@0.1.0", 41 | "process": "github:jspm/nodelibs-process@0.1.2", 42 | "util": "npm:util@0.10.3" 43 | }, 44 | "npm:babel-runtime@5.8.38": { 45 | "process": "github:jspm/nodelibs-process@0.1.2" 46 | }, 47 | "npm:buffer@3.6.0": { 48 | "base64-js": "npm:base64-js@0.0.8", 49 | "child_process": "github:jspm/nodelibs-child_process@0.1.0", 50 | "fs": "github:jspm/nodelibs-fs@0.1.2", 51 | "ieee754": "npm:ieee754@1.1.6", 52 | "isarray": "npm:isarray@1.0.0", 53 | "process": "github:jspm/nodelibs-process@0.1.2" 54 | }, 55 | "npm:core-js@2.4.0": { 56 | "fs": "github:jspm/nodelibs-fs@0.1.2", 57 | "path": "github:jspm/nodelibs-path@0.1.0", 58 | "process": "github:jspm/nodelibs-process@0.1.2", 59 | "systemjs-json": "github:systemjs/plugin-json@0.1.2" 60 | }, 61 | "npm:inherits@2.0.1": { 62 | "util": "github:jspm/nodelibs-util@0.1.0" 63 | }, 64 | "npm:path-browserify@0.0.0": { 65 | "process": "github:jspm/nodelibs-process@0.1.2" 66 | }, 67 | "npm:process@0.11.5": { 68 | "assert": "github:jspm/nodelibs-assert@0.1.0", 69 | "fs": "github:jspm/nodelibs-fs@0.1.2", 70 | "vm": "github:jspm/nodelibs-vm@0.1.0" 71 | }, 72 | "npm:util@0.10.3": { 73 | "inherits": "npm:inherits@2.0.1", 74 | "process": "github:jspm/nodelibs-process@0.1.2" 75 | }, 76 | "npm:vm-browserify@0.0.4": { 77 | "indexof": "npm:indexof@0.0.1" 78 | } 79 | } 80 | }); 81 | -------------------------------------------------------------------------------- /dist/amd/aurelia-logging.js: -------------------------------------------------------------------------------- 1 | define(['exports'], function (exports) { 2 | 'use strict'; 3 | 4 | Object.defineProperty(exports, "__esModule", { 5 | value: true 6 | }); 7 | exports.getLogger = getLogger; 8 | exports.addAppender = addAppender; 9 | exports.removeAppender = removeAppender; 10 | exports.getAppenders = getAppenders; 11 | exports.clearAppenders = clearAppenders; 12 | exports.addCustomLevel = addCustomLevel; 13 | exports.removeCustomLevel = removeCustomLevel; 14 | exports.setLevel = setLevel; 15 | exports.getLevel = getLevel; 16 | 17 | 18 | 19 | var logLevel = exports.logLevel = { 20 | none: 0, 21 | error: 10, 22 | warn: 20, 23 | info: 30, 24 | debug: 40 25 | }; 26 | 27 | var loggers = {}; 28 | var appenders = []; 29 | var globalDefaultLevel = logLevel.none; 30 | 31 | var standardLevels = ['none', 'error', 'warn', 'info', 'debug']; 32 | function isStandardLevel(level) { 33 | return standardLevels.filter(function (l) { 34 | return l === level; 35 | }).length > 0; 36 | } 37 | 38 | function appendArgs() { 39 | return [this].concat(Array.prototype.slice.call(arguments)); 40 | } 41 | 42 | function logFactory(level) { 43 | var threshold = logLevel[level]; 44 | return function () { 45 | if (this.level < threshold) { 46 | return; 47 | } 48 | 49 | var args = appendArgs.apply(this, arguments); 50 | var i = appenders.length; 51 | while (i--) { 52 | var _appenders$i; 53 | 54 | (_appenders$i = appenders[i])[level].apply(_appenders$i, args); 55 | } 56 | }; 57 | } 58 | 59 | function logFactoryCustom(level) { 60 | var threshold = logLevel[level]; 61 | return function () { 62 | if (this.level < threshold) { 63 | return; 64 | } 65 | 66 | var args = appendArgs.apply(this, arguments); 67 | var i = appenders.length; 68 | while (i--) { 69 | var appender = appenders[i]; 70 | if (appender[level] !== undefined) { 71 | appender[level].apply(appender, args); 72 | } 73 | } 74 | }; 75 | } 76 | 77 | function connectLoggers() { 78 | var proto = Logger.prototype; 79 | for (var _level in logLevel) { 80 | if (isStandardLevel(_level)) { 81 | if (_level !== 'none') { 82 | proto[_level] = logFactory(_level); 83 | } 84 | } else { 85 | proto[_level] = logFactoryCustom(_level); 86 | } 87 | } 88 | } 89 | 90 | function disconnectLoggers() { 91 | var proto = Logger.prototype; 92 | for (var _level2 in logLevel) { 93 | if (_level2 !== 'none') { 94 | proto[_level2] = function () {}; 95 | } 96 | } 97 | } 98 | 99 | function getLogger(id) { 100 | return loggers[id] || new Logger(id); 101 | } 102 | 103 | function addAppender(appender) { 104 | if (appenders.push(appender) === 1) { 105 | connectLoggers(); 106 | } 107 | } 108 | 109 | function removeAppender(appender) { 110 | appenders = appenders.filter(function (a) { 111 | return a !== appender; 112 | }); 113 | } 114 | 115 | function getAppenders() { 116 | return [].concat(appenders); 117 | } 118 | 119 | function clearAppenders() { 120 | appenders = []; 121 | disconnectLoggers(); 122 | } 123 | 124 | function addCustomLevel(name, value) { 125 | if (logLevel[name] !== undefined) { 126 | throw Error('Log level "' + name + '" already exists.'); 127 | } 128 | 129 | if (isNaN(value)) { 130 | throw Error('Value must be a number.'); 131 | } 132 | 133 | logLevel[name] = value; 134 | 135 | if (appenders.length > 0) { 136 | connectLoggers(); 137 | } else { 138 | Logger.prototype[name] = function () {}; 139 | } 140 | } 141 | 142 | function removeCustomLevel(name) { 143 | if (logLevel[name] === undefined) { 144 | return; 145 | } 146 | 147 | if (isStandardLevel(name)) { 148 | throw Error('Built-in log level "' + name + '" cannot be removed.'); 149 | } 150 | 151 | delete logLevel[name]; 152 | delete Logger.prototype[name]; 153 | } 154 | 155 | function setLevel(level) { 156 | globalDefaultLevel = level; 157 | for (var key in loggers) { 158 | loggers[key].setLevel(level); 159 | } 160 | } 161 | 162 | function getLevel() { 163 | return globalDefaultLevel; 164 | } 165 | 166 | var Logger = exports.Logger = function () { 167 | function Logger(id) { 168 | 169 | 170 | var cached = loggers[id]; 171 | if (cached) { 172 | return cached; 173 | } 174 | 175 | loggers[id] = this; 176 | this.id = id; 177 | this.level = globalDefaultLevel; 178 | } 179 | 180 | Logger.prototype.debug = function debug(message) {}; 181 | 182 | Logger.prototype.info = function info(message) {}; 183 | 184 | Logger.prototype.warn = function warn(message) {}; 185 | 186 | Logger.prototype.error = function error(message) {}; 187 | 188 | Logger.prototype.setLevel = function setLevel(level) { 189 | this.level = level; 190 | }; 191 | 192 | Logger.prototype.isDebugEnabled = function isDebugEnabled() { 193 | return this.level === logLevel.debug; 194 | }; 195 | 196 | return Logger; 197 | }(); 198 | }); -------------------------------------------------------------------------------- /dist/amd/index.js: -------------------------------------------------------------------------------- 1 | define(['exports', './aurelia-logging'], function (exports, _aureliaLogging) { 2 | 'use strict'; 3 | 4 | Object.defineProperty(exports, "__esModule", { 5 | value: true 6 | }); 7 | Object.keys(_aureliaLogging).forEach(function (key) { 8 | if (key === "default" || key === "__esModule") return; 9 | Object.defineProperty(exports, key, { 10 | enumerable: true, 11 | get: function () { 12 | return _aureliaLogging[key]; 13 | } 14 | }); 15 | }); 16 | }); -------------------------------------------------------------------------------- /dist/aurelia-logging.d.ts: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Specifies the available logging levels. 4 | */ 5 | export declare interface LogLevel { 6 | 7 | /** 8 | * No logging. 9 | */ 10 | none: number; 11 | 12 | /** 13 | * Log only error messages. 14 | */ 15 | error: number; 16 | 17 | /** 18 | * Log warnings messages or above. 19 | */ 20 | warn: number; 21 | 22 | /** 23 | * Log informational messages or above. 24 | */ 25 | info: number; 26 | 27 | /** 28 | * Log all messages. 29 | */ 30 | debug: number; 31 | 32 | /** 33 | * Additional log levels defined at runtime. 34 | */ 35 | [level: string]: number; 36 | } 37 | 38 | /** 39 | * Implemented by classes which wish to append log data to a target data store. 40 | */ 41 | export declare interface Appender { 42 | 43 | /** 44 | * Appends a debug log. 45 | * 46 | * @param logger The source logger. 47 | * @param rest The data to log. 48 | */ 49 | debug(logger: Logger, ...rest: any[]): void; 50 | 51 | /** 52 | * Appends an info log. 53 | * 54 | * @param logger The source logger. 55 | * @param rest The data to log. 56 | */ 57 | info(logger: Logger, ...rest: any[]): void; 58 | 59 | /** 60 | * Appends a warning log. 61 | * 62 | * @param logger The source logger. 63 | * @param rest The data to log. 64 | */ 65 | warn(logger: Logger, ...rest: any[]): void; 66 | 67 | /** 68 | * Appends an error log. 69 | * 70 | * @param logger The source logger. 71 | * @param rest The data to log. 72 | */ 73 | error(logger: Logger, ...rest: any[]): void; 74 | } 75 | 76 | /** 77 | * Specifies the available logging levels. 78 | */ 79 | /** 80 | * Specifies the available logging levels. 81 | */ 82 | export declare const logLevel: LogLevel; 83 | 84 | /** 85 | * Gets the instance of a logger associated with a particular id (or creates one if it doesn't already exist). 86 | * 87 | * @param id The id of the logger you wish to get an instance of. 88 | * @return The instance of the logger, or creates a new logger if none exists for that id. 89 | */ 90 | export declare function getLogger(id: string): Logger; 91 | 92 | /** 93 | * Adds an appender capable of processing logs and channeling them to an output. 94 | * 95 | * @param appender An appender instance to begin processing logs with. 96 | */ 97 | /** 98 | * Adds an appender capable of processing logs and channeling them to an output. 99 | * 100 | * @param appender An appender instance to begin processing logs with. 101 | */ 102 | export declare function addAppender(appender: Appender): void; 103 | 104 | /** 105 | * Removes an appender. 106 | * @param appender An appender that has been added previously. 107 | */ 108 | export declare function removeAppender(appender: Appender): void; 109 | 110 | /** 111 | * Gets an array of all appenders. 112 | */ 113 | export declare function getAppenders(): any; 114 | 115 | /** 116 | * Removes all appenders. 117 | */ 118 | export declare function clearAppenders(): void; 119 | 120 | /** 121 | * Adds a custom log level that will be added as an additional method to Logger. 122 | * Logger will call the corresponding method on any appenders that support it. 123 | * 124 | * @param name The name for the new log level. 125 | * @param value The numeric severity value for the level (higher is more severe). 126 | */ 127 | export declare function addCustomLevel(name: string, value: number): void; 128 | 129 | /** 130 | * Removes a custom log level. 131 | * @param name The name of a custom log level that has been added previously. 132 | */ 133 | export declare function removeCustomLevel(name: string): void; 134 | 135 | /** 136 | * Sets the level of logging for ALL the application loggers. 137 | * 138 | * @param level Matches a value of logLevel specifying the level of logging. 139 | */ 140 | export declare function setLevel(level: number): void; 141 | 142 | /** 143 | * Gets the level of logging of ALL the application loggers. 144 | * 145 | * @return The logLevel value used in all loggers. 146 | */ 147 | export declare function getLevel(): number; 148 | 149 | /** 150 | * A logger logs messages to a set of appenders, depending on the log level that is set. 151 | */ 152 | export declare class Logger { 153 | 154 | /** 155 | * The id that the logger was created with. 156 | */ 157 | id: string; 158 | 159 | /** 160 | * The logging severity level for this logger 161 | */ 162 | level: number; 163 | 164 | /** 165 | * You cannot instantiate the logger directly - you must use the getLogger method instead. 166 | */ 167 | constructor(id: string); 168 | 169 | /** 170 | * Logs a debug message. 171 | * 172 | * @param message The message to log. 173 | * @param rest The data to log. 174 | */ 175 | debug(message: string, ...rest: any[]): void; 176 | 177 | /** 178 | * Logs info. 179 | * 180 | * @param message The message to log. 181 | * @param rest The data to log. 182 | */ 183 | info(message: string, ...rest: any[]): void; 184 | 185 | /** 186 | * Logs a warning. 187 | * 188 | * @param message The message to log. 189 | * @param rest The data to log. 190 | */ 191 | warn(message: string, ...rest: any[]): void; 192 | 193 | /** 194 | * Logs an error. 195 | * 196 | * @param message The message to log. 197 | * @param rest The data to log. 198 | */ 199 | error(message: string, ...rest: any[]): void; 200 | 201 | /** 202 | * Sets the level of logging for this logger instance 203 | * 204 | * @param level Matches a value of logLevel specifying the level of logging. 205 | */ 206 | setLevel(level: number): void; 207 | 208 | /** 209 | * Returns if the logger is in debug mode or not. 210 | */ 211 | isDebugEnabled(): boolean; 212 | } -------------------------------------------------------------------------------- /dist/aurelia-logging.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * Specifies the available logging levels. 4 | */ 5 | interface LogLevel { 6 | /** 7 | * No logging. 8 | */ 9 | none: number, 10 | /** 11 | * Log only error messages. 12 | */ 13 | error: number, 14 | /** 15 | * Log warnings messages or above. 16 | */ 17 | warn: number, 18 | /** 19 | * Log informational messages or above. 20 | */ 21 | info: number, 22 | /** 23 | * Log all messages. 24 | */ 25 | debug: number, 26 | 27 | /** 28 | * Additional log levels defined at runtime. 29 | */ 30 | [level: string]: number 31 | } 32 | 33 | /** 34 | * Specifies the available logging levels. 35 | */ 36 | export const logLevel: LogLevel = { 37 | none: 0, 38 | error: 10, 39 | warn: 20, 40 | info: 30, 41 | debug: 40 42 | }; 43 | 44 | let loggers = {}; 45 | let appenders = []; 46 | let globalDefaultLevel = logLevel.none; 47 | 48 | const standardLevels = ['none', 'error', 'warn', 'info', 'debug']; 49 | function isStandardLevel(level: string) { 50 | return standardLevels.filter(l => l === level).length > 0; 51 | } 52 | 53 | function appendArgs() { 54 | return [this, ...arguments]; 55 | } 56 | 57 | function logFactory(level) { 58 | const threshold = logLevel[level]; 59 | return function() { 60 | // In this function, this === logger 61 | if (this.level < threshold) { 62 | return; 63 | } 64 | // We don't want to disable optimizations (such as inlining) in this function 65 | // so we do the arguments manipulation in another function. 66 | // Note that Function#apply is very special for V8. 67 | const args = appendArgs.apply(this, arguments); 68 | let i = appenders.length; 69 | while (i--) { 70 | appenders[i][level](...args); 71 | } 72 | }; 73 | } 74 | 75 | function logFactoryCustom(level) { 76 | //This function is the same as logFactory() except that it checks that the method 77 | //is defined on the appender. 78 | const threshold = logLevel[level]; 79 | return function() { 80 | // In this function, this === logger 81 | if (this.level < threshold) { 82 | return; 83 | } 84 | // We don't want to disable optimizations (such as inlining) in this function 85 | // so we do the arguments manipulation in another function. 86 | // Note that Function#apply is very special for V8. 87 | const args = appendArgs.apply(this, arguments); 88 | let i = appenders.length; 89 | while (i--) { 90 | const appender = appenders[i]; 91 | if (appender[level] !== undefined) { 92 | appender[level](...args); 93 | } 94 | } 95 | }; 96 | } 97 | 98 | function connectLoggers() { 99 | let proto = Logger.prototype; 100 | for (let level in logLevel) { 101 | if (isStandardLevel(level)) { 102 | if (level !== 'none') { 103 | proto[level] = logFactory(level); 104 | } 105 | } else { 106 | proto[level] = logFactoryCustom(level); 107 | } 108 | } 109 | } 110 | 111 | function disconnectLoggers() { 112 | let proto = Logger.prototype; 113 | for (let level in logLevel) { 114 | if (level !== 'none') { 115 | proto[level] = function() { }; 116 | } 117 | } 118 | } 119 | 120 | /** 121 | * Gets the instance of a logger associated with a particular id (or creates one if it doesn't already exist). 122 | * 123 | * @param id The id of the logger you wish to get an instance of. 124 | * @return The instance of the logger, or creates a new logger if none exists for that id. 125 | */ 126 | export function getLogger(id: string): Logger { 127 | return loggers[id] || new Logger(id); 128 | } 129 | 130 | /** 131 | * Implemented by classes which wish to append log data to a target data store. 132 | */ 133 | interface Appender { 134 | 135 | /** 136 | * Appends a debug log. 137 | * 138 | * @param logger The source logger. 139 | * @param rest The data to log. 140 | */ 141 | debug(logger: Logger, ...rest: any[]): void; 142 | 143 | /** 144 | * Appends an info log. 145 | * 146 | * @param logger The source logger. 147 | * @param rest The data to log. 148 | */ 149 | info(logger: Logger, ...rest: any[]): void; 150 | 151 | /** 152 | * Appends a warning log. 153 | * 154 | * @param logger The source logger. 155 | * @param rest The data to log. 156 | */ 157 | warn(logger: Logger, ...rest: any[]): void; 158 | 159 | /** 160 | * Appends an error log. 161 | * 162 | * @param logger The source logger. 163 | * @param rest The data to log. 164 | */ 165 | error(logger: Logger, ...rest: any[]): void; 166 | } 167 | 168 | /** 169 | * Adds an appender capable of processing logs and channeling them to an output. 170 | * 171 | * @param appender An appender instance to begin processing logs with. 172 | */ 173 | export function addAppender(appender: Appender): void { 174 | if (appenders.push(appender) === 1) { 175 | connectLoggers(); 176 | } 177 | } 178 | 179 | /** 180 | * Removes an appender. 181 | * @param appender An appender that has been added previously. 182 | */ 183 | export function removeAppender(appender: Appender): void { 184 | appenders = appenders.filter(a => a !== appender); 185 | } 186 | 187 | /** 188 | * Gets an array of all appenders. 189 | */ 190 | export function getAppenders() { 191 | return [...appenders]; 192 | } 193 | 194 | /** 195 | * Removes all appenders. 196 | */ 197 | export function clearAppenders(): void { 198 | appenders = []; 199 | disconnectLoggers(); 200 | } 201 | 202 | /** 203 | * Adds a custom log level that will be added as an additional method to Logger. 204 | * Logger will call the corresponding method on any appenders that support it. 205 | * 206 | * @param name The name for the new log level. 207 | * @param value The numeric severity value for the level (higher is more severe). 208 | */ 209 | export function addCustomLevel(name: string, value: number): void { 210 | if (logLevel[name] !== undefined) { 211 | throw Error(`Log level "${name}" already exists.`); 212 | } 213 | 214 | if (isNaN(value)) { 215 | throw Error('Value must be a number.'); 216 | } 217 | 218 | logLevel[name] = value; 219 | 220 | if (appenders.length > 0) { 221 | //Reinitialize the Logger prototype with the new method. 222 | connectLoggers(); 223 | } else { 224 | //Add the custom level as a noop by default. 225 | Logger.prototype[name] = function() { }; 226 | } 227 | } 228 | 229 | /** 230 | * Removes a custom log level. 231 | * @param name The name of a custom log level that has been added previously. 232 | */ 233 | export function removeCustomLevel(name: string): void { 234 | if (logLevel[name] === undefined) { 235 | return; 236 | } 237 | 238 | if (isStandardLevel(name)) { 239 | throw Error(`Built-in log level "${name}" cannot be removed.`); 240 | } 241 | 242 | delete logLevel[name]; 243 | delete Logger.prototype[name]; 244 | } 245 | 246 | /** 247 | * Sets the level of logging for ALL the application loggers. 248 | * 249 | * @param level Matches a value of logLevel specifying the level of logging. 250 | */ 251 | export function setLevel(level: number): void { 252 | globalDefaultLevel = level; 253 | for (let key in loggers) { 254 | loggers[key].setLevel(level); 255 | } 256 | } 257 | 258 | /** 259 | * Gets the level of logging of ALL the application loggers. 260 | * 261 | * @return The logLevel value used in all loggers. 262 | */ 263 | export function getLevel(): number { 264 | return globalDefaultLevel; 265 | } 266 | 267 | /** 268 | * A logger logs messages to a set of appenders, depending on the log level that is set. 269 | */ 270 | export class Logger { 271 | /** 272 | * The id that the logger was created with. 273 | */ 274 | id: string; 275 | 276 | /** 277 | * The logging severity level for this logger 278 | */ 279 | level: number; 280 | 281 | /** 282 | * You cannot instantiate the logger directly - you must use the getLogger method instead. 283 | */ 284 | constructor(id: string) { 285 | let cached = loggers[id]; 286 | if (cached) { 287 | return cached; 288 | } 289 | 290 | loggers[id] = this; 291 | this.id = id; 292 | this.level = globalDefaultLevel; 293 | } 294 | 295 | /** 296 | * Logs a debug message. 297 | * 298 | * @param message The message to log. 299 | * @param rest The data to log. 300 | */ 301 | debug(message: string, ...rest: any[]): void {} 302 | 303 | /** 304 | * Logs info. 305 | * 306 | * @param message The message to log. 307 | * @param rest The data to log. 308 | */ 309 | info(message: string, ...rest: any[]): void {} 310 | 311 | /** 312 | * Logs a warning. 313 | * 314 | * @param message The message to log. 315 | * @param rest The data to log. 316 | */ 317 | warn(message: string, ...rest: any[]): void {} 318 | 319 | /** 320 | * Logs an error. 321 | * 322 | * @param message The message to log. 323 | * @param rest The data to log. 324 | */ 325 | error(message: string, ...rest: any[]): void {} 326 | 327 | /** 328 | * Sets the level of logging for this logger instance 329 | * 330 | * @param level Matches a value of logLevel specifying the level of logging. 331 | */ 332 | setLevel(level: number): void { 333 | this.level = level; 334 | } 335 | 336 | /** 337 | * Returns if the logger is in debug mode or not. 338 | */ 339 | isDebugEnabled(): boolean { 340 | return this.level === logLevel.debug; 341 | } 342 | } 343 | -------------------------------------------------------------------------------- /dist/commonjs/aurelia-logging.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | exports.getLogger = getLogger; 7 | exports.addAppender = addAppender; 8 | exports.removeAppender = removeAppender; 9 | exports.getAppenders = getAppenders; 10 | exports.clearAppenders = clearAppenders; 11 | exports.addCustomLevel = addCustomLevel; 12 | exports.removeCustomLevel = removeCustomLevel; 13 | exports.setLevel = setLevel; 14 | exports.getLevel = getLevel; 15 | 16 | 17 | 18 | var logLevel = exports.logLevel = { 19 | none: 0, 20 | error: 10, 21 | warn: 20, 22 | info: 30, 23 | debug: 40 24 | }; 25 | 26 | var loggers = {}; 27 | var appenders = []; 28 | var globalDefaultLevel = logLevel.none; 29 | 30 | var standardLevels = ['none', 'error', 'warn', 'info', 'debug']; 31 | function isStandardLevel(level) { 32 | return standardLevels.filter(function (l) { 33 | return l === level; 34 | }).length > 0; 35 | } 36 | 37 | function appendArgs() { 38 | return [this].concat(Array.prototype.slice.call(arguments)); 39 | } 40 | 41 | function logFactory(level) { 42 | var threshold = logLevel[level]; 43 | return function () { 44 | if (this.level < threshold) { 45 | return; 46 | } 47 | 48 | var args = appendArgs.apply(this, arguments); 49 | var i = appenders.length; 50 | while (i--) { 51 | var _appenders$i; 52 | 53 | (_appenders$i = appenders[i])[level].apply(_appenders$i, args); 54 | } 55 | }; 56 | } 57 | 58 | function logFactoryCustom(level) { 59 | var threshold = logLevel[level]; 60 | return function () { 61 | if (this.level < threshold) { 62 | return; 63 | } 64 | 65 | var args = appendArgs.apply(this, arguments); 66 | var i = appenders.length; 67 | while (i--) { 68 | var appender = appenders[i]; 69 | if (appender[level] !== undefined) { 70 | appender[level].apply(appender, args); 71 | } 72 | } 73 | }; 74 | } 75 | 76 | function connectLoggers() { 77 | var proto = Logger.prototype; 78 | for (var _level in logLevel) { 79 | if (isStandardLevel(_level)) { 80 | if (_level !== 'none') { 81 | proto[_level] = logFactory(_level); 82 | } 83 | } else { 84 | proto[_level] = logFactoryCustom(_level); 85 | } 86 | } 87 | } 88 | 89 | function disconnectLoggers() { 90 | var proto = Logger.prototype; 91 | for (var _level2 in logLevel) { 92 | if (_level2 !== 'none') { 93 | proto[_level2] = function () {}; 94 | } 95 | } 96 | } 97 | 98 | function getLogger(id) { 99 | return loggers[id] || new Logger(id); 100 | } 101 | 102 | function addAppender(appender) { 103 | if (appenders.push(appender) === 1) { 104 | connectLoggers(); 105 | } 106 | } 107 | 108 | function removeAppender(appender) { 109 | appenders = appenders.filter(function (a) { 110 | return a !== appender; 111 | }); 112 | } 113 | 114 | function getAppenders() { 115 | return [].concat(appenders); 116 | } 117 | 118 | function clearAppenders() { 119 | appenders = []; 120 | disconnectLoggers(); 121 | } 122 | 123 | function addCustomLevel(name, value) { 124 | if (logLevel[name] !== undefined) { 125 | throw Error('Log level "' + name + '" already exists.'); 126 | } 127 | 128 | if (isNaN(value)) { 129 | throw Error('Value must be a number.'); 130 | } 131 | 132 | logLevel[name] = value; 133 | 134 | if (appenders.length > 0) { 135 | connectLoggers(); 136 | } else { 137 | Logger.prototype[name] = function () {}; 138 | } 139 | } 140 | 141 | function removeCustomLevel(name) { 142 | if (logLevel[name] === undefined) { 143 | return; 144 | } 145 | 146 | if (isStandardLevel(name)) { 147 | throw Error('Built-in log level "' + name + '" cannot be removed.'); 148 | } 149 | 150 | delete logLevel[name]; 151 | delete Logger.prototype[name]; 152 | } 153 | 154 | function setLevel(level) { 155 | globalDefaultLevel = level; 156 | for (var key in loggers) { 157 | loggers[key].setLevel(level); 158 | } 159 | } 160 | 161 | function getLevel() { 162 | return globalDefaultLevel; 163 | } 164 | 165 | var Logger = exports.Logger = function () { 166 | function Logger(id) { 167 | 168 | 169 | var cached = loggers[id]; 170 | if (cached) { 171 | return cached; 172 | } 173 | 174 | loggers[id] = this; 175 | this.id = id; 176 | this.level = globalDefaultLevel; 177 | } 178 | 179 | Logger.prototype.debug = function debug(message) {}; 180 | 181 | Logger.prototype.info = function info(message) {}; 182 | 183 | Logger.prototype.warn = function warn(message) {}; 184 | 185 | Logger.prototype.error = function error(message) {}; 186 | 187 | Logger.prototype.setLevel = function setLevel(level) { 188 | this.level = level; 189 | }; 190 | 191 | Logger.prototype.isDebugEnabled = function isDebugEnabled() { 192 | return this.level === logLevel.debug; 193 | }; 194 | 195 | return Logger; 196 | }(); -------------------------------------------------------------------------------- /dist/commonjs/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | 7 | var _aureliaLogging = require('./aurelia-logging'); 8 | 9 | Object.keys(_aureliaLogging).forEach(function (key) { 10 | if (key === "default" || key === "__esModule") return; 11 | Object.defineProperty(exports, key, { 12 | enumerable: true, 13 | get: function get() { 14 | return _aureliaLogging[key]; 15 | } 16 | }); 17 | }); -------------------------------------------------------------------------------- /dist/es2015/aurelia-logging.js: -------------------------------------------------------------------------------- 1 | 2 | export const logLevel = { 3 | none: 0, 4 | error: 10, 5 | warn: 20, 6 | info: 30, 7 | debug: 40 8 | }; 9 | 10 | let loggers = {}; 11 | let appenders = []; 12 | let globalDefaultLevel = logLevel.none; 13 | 14 | const standardLevels = ['none', 'error', 'warn', 'info', 'debug']; 15 | function isStandardLevel(level) { 16 | return standardLevels.filter(l => l === level).length > 0; 17 | } 18 | 19 | function appendArgs() { 20 | return [this, ...arguments]; 21 | } 22 | 23 | function logFactory(level) { 24 | const threshold = logLevel[level]; 25 | return function () { 26 | if (this.level < threshold) { 27 | return; 28 | } 29 | 30 | const args = appendArgs.apply(this, arguments); 31 | let i = appenders.length; 32 | while (i--) { 33 | appenders[i][level](...args); 34 | } 35 | }; 36 | } 37 | 38 | function logFactoryCustom(level) { 39 | const threshold = logLevel[level]; 40 | return function () { 41 | if (this.level < threshold) { 42 | return; 43 | } 44 | 45 | const args = appendArgs.apply(this, arguments); 46 | let i = appenders.length; 47 | while (i--) { 48 | const appender = appenders[i]; 49 | if (appender[level] !== undefined) { 50 | appender[level](...args); 51 | } 52 | } 53 | }; 54 | } 55 | 56 | function connectLoggers() { 57 | let proto = Logger.prototype; 58 | for (let level in logLevel) { 59 | if (isStandardLevel(level)) { 60 | if (level !== 'none') { 61 | proto[level] = logFactory(level); 62 | } 63 | } else { 64 | proto[level] = logFactoryCustom(level); 65 | } 66 | } 67 | } 68 | 69 | function disconnectLoggers() { 70 | let proto = Logger.prototype; 71 | for (let level in logLevel) { 72 | if (level !== 'none') { 73 | proto[level] = function () {}; 74 | } 75 | } 76 | } 77 | 78 | export function getLogger(id) { 79 | return loggers[id] || new Logger(id); 80 | } 81 | 82 | export function addAppender(appender) { 83 | if (appenders.push(appender) === 1) { 84 | connectLoggers(); 85 | } 86 | } 87 | 88 | export function removeAppender(appender) { 89 | appenders = appenders.filter(a => a !== appender); 90 | } 91 | 92 | export function getAppenders() { 93 | return [...appenders]; 94 | } 95 | 96 | export function clearAppenders() { 97 | appenders = []; 98 | disconnectLoggers(); 99 | } 100 | 101 | export function addCustomLevel(name, value) { 102 | if (logLevel[name] !== undefined) { 103 | throw Error(`Log level "${name}" already exists.`); 104 | } 105 | 106 | if (isNaN(value)) { 107 | throw Error('Value must be a number.'); 108 | } 109 | 110 | logLevel[name] = value; 111 | 112 | if (appenders.length > 0) { 113 | connectLoggers(); 114 | } else { 115 | Logger.prototype[name] = function () {}; 116 | } 117 | } 118 | 119 | export function removeCustomLevel(name) { 120 | if (logLevel[name] === undefined) { 121 | return; 122 | } 123 | 124 | if (isStandardLevel(name)) { 125 | throw Error(`Built-in log level "${name}" cannot be removed.`); 126 | } 127 | 128 | delete logLevel[name]; 129 | delete Logger.prototype[name]; 130 | } 131 | 132 | export function setLevel(level) { 133 | globalDefaultLevel = level; 134 | for (let key in loggers) { 135 | loggers[key].setLevel(level); 136 | } 137 | } 138 | 139 | export function getLevel() { 140 | return globalDefaultLevel; 141 | } 142 | 143 | export let Logger = class Logger { 144 | constructor(id) { 145 | let cached = loggers[id]; 146 | if (cached) { 147 | return cached; 148 | } 149 | 150 | loggers[id] = this; 151 | this.id = id; 152 | this.level = globalDefaultLevel; 153 | } 154 | 155 | debug(message, ...rest) {} 156 | 157 | info(message, ...rest) {} 158 | 159 | warn(message, ...rest) {} 160 | 161 | error(message, ...rest) {} 162 | 163 | setLevel(level) { 164 | this.level = level; 165 | } 166 | 167 | isDebugEnabled() { 168 | return this.level === logLevel.debug; 169 | } 170 | }; -------------------------------------------------------------------------------- /dist/es2015/index.js: -------------------------------------------------------------------------------- 1 | export * from './aurelia-logging'; -------------------------------------------------------------------------------- /dist/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from 'aurelia-logging/aurelia-logging'; -------------------------------------------------------------------------------- /dist/native-modules/aurelia-logging.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | export var logLevel = { 4 | none: 0, 5 | error: 10, 6 | warn: 20, 7 | info: 30, 8 | debug: 40 9 | }; 10 | 11 | var loggers = {}; 12 | var appenders = []; 13 | var globalDefaultLevel = logLevel.none; 14 | 15 | var standardLevels = ['none', 'error', 'warn', 'info', 'debug']; 16 | function isStandardLevel(level) { 17 | return standardLevels.filter(function (l) { 18 | return l === level; 19 | }).length > 0; 20 | } 21 | 22 | function appendArgs() { 23 | return [this].concat(Array.prototype.slice.call(arguments)); 24 | } 25 | 26 | function logFactory(level) { 27 | var threshold = logLevel[level]; 28 | return function () { 29 | if (this.level < threshold) { 30 | return; 31 | } 32 | 33 | var args = appendArgs.apply(this, arguments); 34 | var i = appenders.length; 35 | while (i--) { 36 | var _appenders$i; 37 | 38 | (_appenders$i = appenders[i])[level].apply(_appenders$i, args); 39 | } 40 | }; 41 | } 42 | 43 | function logFactoryCustom(level) { 44 | var threshold = logLevel[level]; 45 | return function () { 46 | if (this.level < threshold) { 47 | return; 48 | } 49 | 50 | var args = appendArgs.apply(this, arguments); 51 | var i = appenders.length; 52 | while (i--) { 53 | var appender = appenders[i]; 54 | if (appender[level] !== undefined) { 55 | appender[level].apply(appender, args); 56 | } 57 | } 58 | }; 59 | } 60 | 61 | function connectLoggers() { 62 | var proto = Logger.prototype; 63 | for (var _level in logLevel) { 64 | if (isStandardLevel(_level)) { 65 | if (_level !== 'none') { 66 | proto[_level] = logFactory(_level); 67 | } 68 | } else { 69 | proto[_level] = logFactoryCustom(_level); 70 | } 71 | } 72 | } 73 | 74 | function disconnectLoggers() { 75 | var proto = Logger.prototype; 76 | for (var _level2 in logLevel) { 77 | if (_level2 !== 'none') { 78 | proto[_level2] = function () {}; 79 | } 80 | } 81 | } 82 | 83 | export function getLogger(id) { 84 | return loggers[id] || new Logger(id); 85 | } 86 | 87 | export function addAppender(appender) { 88 | if (appenders.push(appender) === 1) { 89 | connectLoggers(); 90 | } 91 | } 92 | 93 | export function removeAppender(appender) { 94 | appenders = appenders.filter(function (a) { 95 | return a !== appender; 96 | }); 97 | } 98 | 99 | export function getAppenders() { 100 | return [].concat(appenders); 101 | } 102 | 103 | export function clearAppenders() { 104 | appenders = []; 105 | disconnectLoggers(); 106 | } 107 | 108 | export function addCustomLevel(name, value) { 109 | if (logLevel[name] !== undefined) { 110 | throw Error('Log level "' + name + '" already exists.'); 111 | } 112 | 113 | if (isNaN(value)) { 114 | throw Error('Value must be a number.'); 115 | } 116 | 117 | logLevel[name] = value; 118 | 119 | if (appenders.length > 0) { 120 | connectLoggers(); 121 | } else { 122 | Logger.prototype[name] = function () {}; 123 | } 124 | } 125 | 126 | export function removeCustomLevel(name) { 127 | if (logLevel[name] === undefined) { 128 | return; 129 | } 130 | 131 | if (isStandardLevel(name)) { 132 | throw Error('Built-in log level "' + name + '" cannot be removed.'); 133 | } 134 | 135 | delete logLevel[name]; 136 | delete Logger.prototype[name]; 137 | } 138 | 139 | export function setLevel(level) { 140 | globalDefaultLevel = level; 141 | for (var key in loggers) { 142 | loggers[key].setLevel(level); 143 | } 144 | } 145 | 146 | export function getLevel() { 147 | return globalDefaultLevel; 148 | } 149 | 150 | export var Logger = function () { 151 | function Logger(id) { 152 | 153 | 154 | var cached = loggers[id]; 155 | if (cached) { 156 | return cached; 157 | } 158 | 159 | loggers[id] = this; 160 | this.id = id; 161 | this.level = globalDefaultLevel; 162 | } 163 | 164 | Logger.prototype.debug = function debug(message) {}; 165 | 166 | Logger.prototype.info = function info(message) {}; 167 | 168 | Logger.prototype.warn = function warn(message) {}; 169 | 170 | Logger.prototype.error = function error(message) {}; 171 | 172 | Logger.prototype.setLevel = function setLevel(level) { 173 | this.level = level; 174 | }; 175 | 176 | Logger.prototype.isDebugEnabled = function isDebugEnabled() { 177 | return this.level === logLevel.debug; 178 | }; 179 | 180 | return Logger; 181 | }(); -------------------------------------------------------------------------------- /dist/native-modules/index.js: -------------------------------------------------------------------------------- 1 | export * from './aurelia-logging'; -------------------------------------------------------------------------------- /dist/system/aurelia-logging.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | System.register([], function (_export, _context) { 4 | "use strict"; 5 | 6 | var logLevel, loggers, appenders, globalDefaultLevel, standardLevels, Logger; 7 | 8 | 9 | 10 | function isStandardLevel(level) { 11 | return standardLevels.filter(function (l) { 12 | return l === level; 13 | }).length > 0; 14 | } 15 | 16 | function appendArgs() { 17 | return [this].concat(Array.prototype.slice.call(arguments)); 18 | } 19 | 20 | function logFactory(level) { 21 | var threshold = logLevel[level]; 22 | return function () { 23 | if (this.level < threshold) { 24 | return; 25 | } 26 | 27 | var args = appendArgs.apply(this, arguments); 28 | var i = appenders.length; 29 | while (i--) { 30 | var _appenders$i; 31 | 32 | (_appenders$i = appenders[i])[level].apply(_appenders$i, args); 33 | } 34 | }; 35 | } 36 | 37 | function logFactoryCustom(level) { 38 | var threshold = logLevel[level]; 39 | return function () { 40 | if (this.level < threshold) { 41 | return; 42 | } 43 | 44 | var args = appendArgs.apply(this, arguments); 45 | var i = appenders.length; 46 | while (i--) { 47 | var appender = appenders[i]; 48 | if (appender[level] !== undefined) { 49 | appender[level].apply(appender, args); 50 | } 51 | } 52 | }; 53 | } 54 | 55 | function connectLoggers() { 56 | var proto = Logger.prototype; 57 | for (var _level in logLevel) { 58 | if (isStandardLevel(_level)) { 59 | if (_level !== 'none') { 60 | proto[_level] = logFactory(_level); 61 | } 62 | } else { 63 | proto[_level] = logFactoryCustom(_level); 64 | } 65 | } 66 | } 67 | 68 | function disconnectLoggers() { 69 | var proto = Logger.prototype; 70 | for (var _level2 in logLevel) { 71 | if (_level2 !== 'none') { 72 | proto[_level2] = function () {}; 73 | } 74 | } 75 | } 76 | 77 | function getLogger(id) { 78 | return loggers[id] || new Logger(id); 79 | } 80 | 81 | _export('getLogger', getLogger); 82 | 83 | function addAppender(appender) { 84 | if (appenders.push(appender) === 1) { 85 | connectLoggers(); 86 | } 87 | } 88 | 89 | _export('addAppender', addAppender); 90 | 91 | function removeAppender(appender) { 92 | appenders = appenders.filter(function (a) { 93 | return a !== appender; 94 | }); 95 | } 96 | 97 | _export('removeAppender', removeAppender); 98 | 99 | function getAppenders() { 100 | return [].concat(appenders); 101 | } 102 | 103 | _export('getAppenders', getAppenders); 104 | 105 | function clearAppenders() { 106 | appenders = []; 107 | disconnectLoggers(); 108 | } 109 | 110 | _export('clearAppenders', clearAppenders); 111 | 112 | function addCustomLevel(name, value) { 113 | if (logLevel[name] !== undefined) { 114 | throw Error('Log level "' + name + '" already exists.'); 115 | } 116 | 117 | if (isNaN(value)) { 118 | throw Error('Value must be a number.'); 119 | } 120 | 121 | logLevel[name] = value; 122 | 123 | if (appenders.length > 0) { 124 | connectLoggers(); 125 | } else { 126 | Logger.prototype[name] = function () {}; 127 | } 128 | } 129 | 130 | _export('addCustomLevel', addCustomLevel); 131 | 132 | function removeCustomLevel(name) { 133 | if (logLevel[name] === undefined) { 134 | return; 135 | } 136 | 137 | if (isStandardLevel(name)) { 138 | throw Error('Built-in log level "' + name + '" cannot be removed.'); 139 | } 140 | 141 | delete logLevel[name]; 142 | delete Logger.prototype[name]; 143 | } 144 | 145 | _export('removeCustomLevel', removeCustomLevel); 146 | 147 | function setLevel(level) { 148 | globalDefaultLevel = level; 149 | for (var key in loggers) { 150 | loggers[key].setLevel(level); 151 | } 152 | } 153 | 154 | _export('setLevel', setLevel); 155 | 156 | function getLevel() { 157 | return globalDefaultLevel; 158 | } 159 | 160 | _export('getLevel', getLevel); 161 | 162 | return { 163 | setters: [], 164 | execute: function () { 165 | _export('logLevel', logLevel = { 166 | none: 0, 167 | error: 10, 168 | warn: 20, 169 | info: 30, 170 | debug: 40 171 | }); 172 | 173 | _export('logLevel', logLevel); 174 | 175 | loggers = {}; 176 | appenders = []; 177 | globalDefaultLevel = logLevel.none; 178 | standardLevels = ['none', 'error', 'warn', 'info', 'debug']; 179 | 180 | _export('Logger', Logger = function () { 181 | function Logger(id) { 182 | 183 | 184 | var cached = loggers[id]; 185 | if (cached) { 186 | return cached; 187 | } 188 | 189 | loggers[id] = this; 190 | this.id = id; 191 | this.level = globalDefaultLevel; 192 | } 193 | 194 | Logger.prototype.debug = function debug(message) {}; 195 | 196 | Logger.prototype.info = function info(message) {}; 197 | 198 | Logger.prototype.warn = function warn(message) {}; 199 | 200 | Logger.prototype.error = function error(message) {}; 201 | 202 | Logger.prototype.setLevel = function setLevel(level) { 203 | this.level = level; 204 | }; 205 | 206 | Logger.prototype.isDebugEnabled = function isDebugEnabled() { 207 | return this.level === logLevel.debug; 208 | }; 209 | 210 | return Logger; 211 | }()); 212 | 213 | _export('Logger', Logger); 214 | } 215 | }; 216 | }); -------------------------------------------------------------------------------- /dist/system/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | System.register(['./aurelia-logging'], function (_export, _context) { 4 | "use strict"; 5 | 6 | return { 7 | setters: [function (_aureliaLogging) { 8 | var _exportObj = {}; 9 | 10 | for (var _key in _aureliaLogging) { 11 | if (_key !== "default" && _key !== "__esModule") _exportObj[_key] = _aureliaLogging[_key]; 12 | } 13 | 14 | _export(_exportObj); 15 | }], 16 | execute: function () {} 17 | }; 18 | }); -------------------------------------------------------------------------------- /doc/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | ## [1.5.3](https://github.com/aurelia/logging/compare/1.5.1...1.5.3) (2019-03-26) 3 | 4 | 5 | ### Bug Fixes 6 | 7 | * **all:** change es2015 back to native-modules ([a84649d](https://github.com/aurelia/logging/commit/a84649d)) 8 | 9 | 10 | 11 | 12 | ## [1.5.2](https://github.com/aurelia/logging/compare/1.5.1...1.5.2) (2019-02-04) 13 | 14 | 15 | ### Bug Fixes 16 | 17 | * **all:** change es2015 back to native-modules ([a84649d](https://github.com/aurelia/logging/commit/a84649d)) 18 | 19 | 20 | 21 | 22 | ## [1.5.1](https://github.com/aurelia/logging/compare/1.5.0...1.5.1) (2019-01-17) 23 | 24 | * Add module field to package.json 25 | 26 | 27 | # [1.5.0](https://github.com/aurelia/logging/compare/1.4.0...1.5.0) (2018-06-12) 28 | 29 | 30 | ### Features 31 | 32 | * **logging:** Allow isDebugEnabled to be returned ([9e7d571](https://github.com/aurelia/logging/commit/9e7d571)), closes [#41](https://github.com/aurelia/logging/issues/41) 33 | 34 | 35 | 36 | 37 | # [1.4.0](https://github.com/aurelia/logging/compare/1.3.1...v1.4.0) (2017-12-20) 38 | 39 | 40 | ### Features 41 | 42 | * **log-manager:** add custom log levels ([9b5b245](https://github.com/aurelia/logging/commit/9b5b245)), closes [#33](https://github.com/aurelia/logging/issues/33) 43 | 44 | 45 | 46 | 47 | ## [1.3.1](https://github.com/aurelia/logging/compare/1.3.0...v1.3.1) (2017-03-26) 48 | 49 | 50 | ### Bug Fixes 51 | 52 | * **logging:** restore ES5 compatibility ([70bb834](https://github.com/aurelia/logging/commit/70bb834)) 53 | 54 | 55 | 56 | 57 | # [1.3.0](https://github.com/aurelia/logging/compare/1.2.0...v1.3.0) (2017-02-21) 58 | 59 | 60 | 61 | 62 | # [1.2.0](https://github.com/aurelia/logging/compare/1.1.1...v1.2.0) (2016-12-03) 63 | 64 | 65 | ### Features 66 | 67 | * **logging:** Allow global logLevel to be returned ([1c61077](https://github.com/aurelia/logging/commit/1c61077)) 68 | 69 | 70 | 71 | 72 | ## [1.1.1](https://github.com/aurelia/logging/compare/1.1.0...v1.1.1) (2016-11-08) 73 | 74 | 75 | ### Bug Fixes 76 | 77 | * **logging:** carry a globalDefaultLevel with which subsequent loggers are created ([ec9af2a](https://github.com/aurelia/logging/commit/ec9af2a)) 78 | * **logging:** relax type on Logger.setLevel() for compatibility with TypeScript ([d52bec2](https://github.com/aurelia/logging/commit/d52bec2)) 79 | 80 | 81 | 82 | # 1.1.0 83 | 84 | ### Features 85 | 86 | * Individual loggers now have a `level` property that can be used to override the default log level. 87 | 88 | 89 | # [1.0.0](https://github.com/aurelia/logging/compare/1.0.0-rc.1.0.1...v1.0.0) (2016-07-27) 90 | 91 | 92 | 93 | 94 | # [1.0.0-rc.1.0.1](https://github.com/aurelia/logging/compare/1.0.0-rc.1.0.0...v1.0.0-rc.1.0.1) (2016-07-12) 95 | 96 | 97 | 98 | 99 | # [1.0.0-rc.1.0.0](https://github.com/aurelia/logging/compare/1.0.0-beta.2.0.1...v1.0.0-rc.1.0.0) (2016-06-22) 100 | 101 | 102 | 103 | ### 1.0.0-beta.1.2.1 (2016-05-10) 104 | 105 | 106 | ### 1.0.0-beta.1.2.0 (2016-03-22) 107 | 108 | * Update to Babel 6 109 | 110 | ### 1.0.0-beta.1.1.2 (2016-03-01) 111 | 112 | 113 | #### Bug Fixes 114 | 115 | * **logging:** fix the interface ([6276c3b0](http://github.com/aurelia/logging/commit/6276c3b0e89e2ecb37c873f467a47499c60386ed)) 116 | 117 | 118 | ## 1.0.0-beta.1.1.1 (2016-01-28) 119 | 120 | * fix package metadata for jspm 121 | 122 | ## 1.0.0-beta.1.1.0 (2016-01-28) 123 | 124 | 125 | #### Features 126 | 127 | * **all:** update for jspm and core-js ([d71d0a4a](http://github.com/aurelia/logging/commit/d71d0a4aa5db4e5697f91dc16e021c0796cf8fa5)) 128 | 129 | 130 | ### 1.0.0-beta.1 (2015-11-15) 131 | 132 | 133 | ## 0.9.0 (2015-11-09) 134 | 135 | 136 | ## 0.8.0 (2015-10-13) 137 | 138 | 139 | #### Bug Fixes 140 | 141 | * **all:** 142 | * remove unnecessary parts of doc comments ([b9d0f92e](http://github.com/aurelia/logging/commit/b9d0f92e39c8cf72b1f43a35ddea0a0c7d29f267)) 143 | * address more lint issues ([ceef9eb3](http://github.com/aurelia/logging/commit/ceef9eb3761211d75851cf1cb27f7dd42ae7789d)) 144 | * working on linting ([5c3f04bd](http://github.com/aurelia/logging/commit/5c3f04bd4d60401b8488ea6842762342efe93bc7)) 145 | * change levels enum to logLevel ([6d1de07c](http://github.com/aurelia/logging/commit/6d1de07c0f2a9e9e747df6f3bef4f74adf9c7074), closes [#7](http://github.com/aurelia/logging/issues/7)) 146 | * update compiler ([ffe2e20f](http://github.com/aurelia/logging/commit/ffe2e20f0249b0cd1d7378ec42ca07df63b61ed0)) 147 | * **build:** 148 | * update linting, testing and tools ([88398cc2](http://github.com/aurelia/logging/commit/88398cc215d75a2d90b25250b534d9b4f4e131a5)) 149 | * add missing bower bump ([0a682c5e](http://github.com/aurelia/logging/commit/0a682c5e50345a93f242463f16416feb9a6950ed)) 150 | * **eslintrc:** adjust the rules ([fc14ab5a](http://github.com/aurelia/logging/commit/fc14ab5a8914678e65ba9a18fcc10dc639f58e04)) 151 | * **index:** 152 | * remove AggregateError ([16784ddf](http://github.com/aurelia/logging/commit/16784ddfbbbfb57fda71ab2b0cdd26f8dd5b0cd0)) 153 | * remove methods from interfaces ([e7d0d342](http://github.com/aurelia/logging/commit/e7d0d3421e59d9964c8dde5fe01e08c2f58b5e6a)) 154 | * **jspm:** fix jspm config. resolve #10 ([5ece2e3c](http://github.com/aurelia/logging/commit/5ece2e3cd8400fff38e6829c9a8270ae826382c0)) 155 | * **package:** 156 | * correct aurelia section ([acffd659](http://github.com/aurelia/logging/commit/acffd6598b64c145c1b72e9f7da527fcb09b35d9)) 157 | * update aurelia tools and dts generator ([5d4190ce](http://github.com/aurelia/logging/commit/5d4190cec35bb8254aa2e33a4fdc3848084f56ce)) 158 | * change jspm directories ([29de7599](http://github.com/aurelia/logging/commit/29de75997081b59485313679e451ae53d0f58fe9)) 159 | 160 | 161 | #### Features 162 | 163 | * **AggregateError:** add ability to skip wrap if inner already exists ([98da4c32](http://github.com/aurelia/logging/commit/98da4c32c92ae12c654f3b3c827d48516970f174)) 164 | * **all:** enable error aggregation with new AggregateError ([88073ddb](http://github.com/aurelia/logging/commit/88073ddb7bb3d8c4ec86fb37d42978ae8c1b369f)) 165 | * **build:** update compiler and switch to register module format ([7eb9aec5](http://github.com/aurelia/logging/commit/7eb9aec56eb616c2bbfbb38e59b8813f3f42a2e9)) 166 | * **docs:** generate api.json from .d.ts file ([bac61cfe](http://github.com/aurelia/logging/commit/bac61cfe14f700e911ec520336e7c7acc9720954)) 167 | * **index:** add the Appender interface ([fe39b380](http://github.com/aurelia/logging/commit/fe39b380ad77d362f282a783da2f52e0706c8a44)) 168 | * **logging:** Add new "none" log level. ([8f1ffdd6](http://github.com/aurelia/logging/commit/8f1ffdd6291c77874388944edc4a897d7078dcbd)) 169 | 170 | 171 | #### Breaking Changes 172 | 173 | * AggregateError has now been moved to the pal library. 174 | 175 | ([16784ddf](http://github.com/aurelia/logging/commit/16784ddfbbbfb57fda71ab2b0cdd26f8dd5b0cd0)) 176 | 177 | 178 | ## 0.7.0 (2015-09-04) 179 | 180 | 181 | #### Bug Fixes 182 | 183 | * **all:** 184 | * remove unnecessary parts of doc comments ([b9d0f92e](http://github.com/aurelia/logging/commit/b9d0f92e39c8cf72b1f43a35ddea0a0c7d29f267)) 185 | * address more lint issues ([ceef9eb3](http://github.com/aurelia/logging/commit/ceef9eb3761211d75851cf1cb27f7dd42ae7789d)) 186 | * working on linting ([5c3f04bd](http://github.com/aurelia/logging/commit/5c3f04bd4d60401b8488ea6842762342efe93bc7)) 187 | * **build:** update linting, testing and tools ([88398cc2](http://github.com/aurelia/logging/commit/88398cc215d75a2d90b25250b534d9b4f4e131a5)) 188 | * **eslintrc:** adjust the rules ([fc14ab5a](http://github.com/aurelia/logging/commit/fc14ab5a8914678e65ba9a18fcc10dc639f58e04)) 189 | 190 | 191 | #### Features 192 | 193 | * **docs:** generate api.json from .d.ts file ([bac61cfe](http://github.com/aurelia/logging/commit/bac61cfe14f700e911ec520336e7c7acc9720954)) 194 | 195 | 196 | ### 0.6.4 (2015-08-14) 197 | 198 | 199 | #### Bug Fixes 200 | 201 | * **index:** remove methods from interfaces ([e7d0d342](http://github.com/aurelia/logging/commit/e7d0d3421e59d9964c8dde5fe01e08c2f58b5e6a)) 202 | 203 | 204 | ### 0.6.3 (2015-08-14) 205 | 206 | 207 | #### Features 208 | 209 | * **index:** add the Appender interface ([fe39b380](http://github.com/aurelia/logging/commit/fe39b380ad77d362f282a783da2f52e0706c8a44)) 210 | 211 | 212 | ### 0.6.2 (2015-07-29) 213 | 214 | * Update build with better file name output 215 | 216 | ### 0.6.1 (2015-07-13) 217 | 218 | 219 | #### Bug Fixes 220 | 221 | * **jspm:** fix jspm config. resolve #10 ([5ece2e3c](http://github.com/aurelia/logging/commit/5ece2e3cd8400fff38e6829c9a8270ae826382c0)) 222 | 223 | 224 | ## 0.6.0 (2015-07-01) 225 | 226 | 227 | #### Bug Fixes 228 | 229 | * **package:** update aurelia tools and dts generator ([5d4190ce](http://github.com/aurelia/logging/commit/5d4190cec35bb8254aa2e33a4fdc3848084f56ce)) 230 | 231 | 232 | ## 0.5.0 (2015-06-08) 233 | 234 | 235 | ## 0.4.0 (2015-04-30) 236 | 237 | 238 | #### Bug Fixes 239 | 240 | * **all:** change levels enum to logLevel ([6d1de07c](http://github.com/aurelia/logging/commit/6d1de07c0f2a9e9e747df6f3bef4f74adf9c7074), closes [#7](http://github.com/aurelia/logging/issues/7)) 241 | 242 | 243 | ## 0.3.0 (2015-04-09) 244 | 245 | 246 | #### Bug Fixes 247 | 248 | * **all:** update compiler ([ffe2e20f](http://github.com/aurelia/logging/commit/ffe2e20f0249b0cd1d7378ec42ca07df63b61ed0)) 249 | 250 | 251 | ### 0.2.7 (2015-03-27) 252 | 253 | 254 | #### Features 255 | 256 | * **AggregateError:** add ability to skip wrap if inner already exists ([98da4c32](http://github.com/aurelia/logging/commit/98da4c32c92ae12c654f3b3c827d48516970f174)) 257 | 258 | 259 | ### 0.2.6 (2015-03-24) 260 | 261 | 262 | #### Features 263 | 264 | * **all:** enable error aggregation with new AggregateError ([88073ddb](http://github.com/aurelia/logging/commit/88073ddb7bb3d8c4ec86fb37d42978ae8c1b369f)) 265 | 266 | 267 | ### 0.2.5 (2015-02-28) 268 | 269 | 270 | #### Bug Fixes 271 | 272 | * **package:** change jspm directories ([29de7599](http://github.com/aurelia/logging/commit/29de75997081b59485313679e451ae53d0f58fe9)) 273 | 274 | 275 | ### 0.2.4 (2015-02-27) 276 | 277 | * Updated compiler. 278 | 279 | ### 0.2.3 (2015-02-18) 280 | 281 | 282 | #### Bug Fixes 283 | 284 | * **build:** add missing bower bump ([0a682c5e](http://github.com/aurelia/logging/commit/0a682c5e50345a93f242463f16416feb9a6950ed)) 285 | 286 | 287 | ### 0.2.2 (2015-01-22) 288 | 289 | * Added preliminary API docs. 290 | 291 | ### 0.2.1 (2015-01-12) 292 | 293 | * Compiled output update. 294 | 295 | ## 0.2.0 (2015-01-06) 296 | 297 | #### Features 298 | 299 | * **build:** update compiler and switch to register module format ([7eb9aec5](http://github.com/aurelia/logging/commit/7eb9aec56eb616c2bbfbb38e59b8813f3f42a2e9)) 300 | * **logging:** Add new "none" log level. ([8f1ffdd6](http://github.com/aurelia/logging/commit/8f1ffdd6291c77874388944edc4a897d7078dcbd)) 301 | -------------------------------------------------------------------------------- /doc/api.json: -------------------------------------------------------------------------------- 1 | {"name":"aurelia-logging","children":[{"id":27,"name":"Logger","kind":128,"kindString":"Class","flags":{"isExported":true},"comment":{"shortText":"A logger logs messages to a set of appenders, depending on the log level that is set."},"children":[{"id":30,"name":"constructor","kind":512,"kindString":"Constructor","flags":{"isExported":true},"comment":{"shortText":"You cannot instantiate the logger directly - you must use the getLogger method instead."},"signatures":[{"id":31,"name":"new Logger","kind":16384,"kindString":"Constructor signature","flags":{},"comment":{"shortText":"You cannot instantiate the logger directly - you must use the getLogger method instead."},"parameters":[{"id":32,"name":"id","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Logger","id":27}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":162,"character":16}]},{"id":28,"name":"id","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The id that the logger was created with."},"sources":[{"fileName":"aurelia-logging.d.ts","line":157,"character":4}],"type":{"type":"instrinct","name":"string"}},{"id":29,"name":"level","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"The logging severity level for this logger"},"sources":[{"fileName":"aurelia-logging.d.ts","line":162,"character":7}],"type":{"type":"instrinct","name":"number"}},{"id":33,"name":"debug","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":34,"name":"debug","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Logs a debug message."},"parameters":[{"id":35,"name":"message","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The message to log."},"type":{"type":"instrinct","name":"string"}},{"id":36,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The data to log.\n"},"type":{"type":"instrinct","isArray":true,"name":"any"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":175,"character":7}]},{"id":45,"name":"error","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":46,"name":"error","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Logs an error."},"parameters":[{"id":47,"name":"message","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The message to log."},"type":{"type":"instrinct","name":"string"}},{"id":48,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The data to log.\n"},"type":{"type":"instrinct","isArray":true,"name":"any"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":199,"character":7}]},{"id":37,"name":"info","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":38,"name":"info","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Logs info."},"parameters":[{"id":39,"name":"message","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The message to log."},"type":{"type":"instrinct","name":"string"}},{"id":40,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The data to log.\n"},"type":{"type":"instrinct","isArray":true,"name":"any"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":183,"character":6}]},{"id":52,"name":"isDebugEnabled","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":53,"name":"isDebugEnabled","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Returns if the logger is in debug mode or not."},"type":{"type":"instrinct","name":"boolean"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":211,"character":16}]},{"id":49,"name":"setLevel","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":50,"name":"setLevel","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Sets the level of logging for this logger instance"},"parameters":[{"id":51,"name":"level","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"Matches a value of logLevel specifying the level of logging.\n"},"type":{"type":"instrinct","name":"number"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":206,"character":10}]},{"id":41,"name":"warn","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":42,"name":"warn","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Logs a warning."},"parameters":[{"id":43,"name":"message","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The message to log."},"type":{"type":"instrinct","name":"string"}},{"id":44,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The data to log.\n"},"type":{"type":"instrinct","isArray":true,"name":"any"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":191,"character":6}]}],"groups":[{"title":"Constructors","kind":512,"children":[30]},{"title":"Properties","kind":1024,"children":[28,29]},{"title":"Methods","kind":2048,"children":[33,45,37,52,49,41]}],"sources":[{"fileName":"aurelia-logging.d.ts","line":152,"character":27}]},{"id":10,"name":"Appender","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"Implemented by classes which wish to append log data to a target data store."},"children":[{"id":11,"name":"debug","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":12,"name":"debug","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Appends a debug log."},"parameters":[{"id":13,"name":"logger","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The source logger."},"type":{"type":"reference","name":"Logger","id":27}},{"id":14,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The data to log.\n"},"type":{"type":"instrinct","isArray":true,"name":"any"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":49,"character":7}]},{"id":23,"name":"error","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":24,"name":"error","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Appends an error log."},"parameters":[{"id":25,"name":"logger","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The source logger."},"type":{"type":"reference","name":"Logger","id":27}},{"id":26,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The data to log.\n"},"type":{"type":"instrinct","isArray":true,"name":"any"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":73,"character":7}]},{"id":15,"name":"info","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":16,"name":"info","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Appends an info log."},"parameters":[{"id":17,"name":"logger","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The source logger."},"type":{"type":"reference","name":"Logger","id":27}},{"id":18,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The data to log.\n"},"type":{"type":"instrinct","isArray":true,"name":"any"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":57,"character":6}]},{"id":19,"name":"warn","kind":2048,"kindString":"Method","flags":{"isExported":true},"signatures":[{"id":20,"name":"warn","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Appends a warning log."},"parameters":[{"id":21,"name":"logger","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The source logger."},"type":{"type":"reference","name":"Logger","id":27}},{"id":22,"name":"rest","kind":32768,"kindString":"Parameter","flags":{"isRest":true},"comment":{"text":"The data to log.\n"},"type":{"type":"instrinct","isArray":true,"name":"any"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":65,"character":6}]}],"groups":[{"title":"Methods","kind":2048,"children":[11,23,15,19]}],"sources":[{"fileName":"aurelia-logging.d.ts","line":41,"character":33}]},{"id":2,"name":"LogLevel","kind":256,"kindString":"Interface","flags":{"isExported":true},"comment":{"shortText":"Specifies the available logging levels."},"indexSignature":[{"id":8,"name":"__index","kind":8192,"kindString":"Index signature","flags":{},"comment":{"shortText":"Additional log levels defined at runtime."},"parameters":[{"id":9,"name":"level","kind":32768,"kindString":"Parameter","flags":{},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"instrinct","name":"number"}}],"children":[{"id":7,"name":"debug","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Log all messages."},"sources":[{"fileName":"aurelia-logging.d.ts","line":30,"character":7}],"type":{"type":"instrinct","name":"number"}},{"id":4,"name":"error","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Log only error messages."},"sources":[{"fileName":"aurelia-logging.d.ts","line":15,"character":7}],"type":{"type":"instrinct","name":"number"}},{"id":6,"name":"info","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Log informational messages or above."},"sources":[{"fileName":"aurelia-logging.d.ts","line":25,"character":6}],"type":{"type":"instrinct","name":"number"}},{"id":3,"name":"none","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"No logging."},"sources":[{"fileName":"aurelia-logging.d.ts","line":10,"character":6}],"type":{"type":"instrinct","name":"number"}},{"id":5,"name":"warn","kind":1024,"kindString":"Property","flags":{"isExported":true},"comment":{"shortText":"Log warnings messages or above."},"sources":[{"fileName":"aurelia-logging.d.ts","line":20,"character":6}],"type":{"type":"instrinct","name":"number"}}],"groups":[{"title":"Properties","kind":1024,"children":[7,4,6,3,5]}],"sources":[{"fileName":"aurelia-logging.d.ts","line":5,"character":33}]},{"id":54,"name":"logLevel","kind":32,"kindString":"Variable","flags":{"isExported":true},"comment":{"shortText":"Specifies the available logging levels."},"sources":[{"fileName":"aurelia-logging.d.ts","line":82,"character":29}],"type":{"type":"reference","name":"LogLevel","id":2}},{"id":58,"name":"addAppender","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":59,"name":"addAppender","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Adds an appender capable of processing logs and channeling them to an output."},"parameters":[{"id":60,"name":"appender","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"An appender instance to begin processing logs with.\n"},"type":{"type":"reference","name":"Appender","id":10}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":102,"character":35}]},{"id":68,"name":"addCustomLevel","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":69,"name":"addCustomLevel","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Adds a custom log level that will be added as an additional method to Logger.\nLogger will call the corresponding method on any appenders that support it."},"parameters":[{"id":70,"name":"name","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The name for the new log level."},"type":{"type":"instrinct","name":"string"}},{"id":71,"name":"value","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The numeric severity value for the level (higher is more severe).\n"},"type":{"type":"instrinct","name":"number"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":127,"character":38}]},{"id":66,"name":"clearAppenders","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":67,"name":"clearAppenders","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Removes all appenders."},"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":118,"character":38}]},{"id":64,"name":"getAppenders","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":65,"name":"getAppenders","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Gets an array of all appenders."},"type":{"type":"instrinct","name":"any"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":113,"character":36}]},{"id":78,"name":"getLevel","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":79,"name":"getLevel","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Gets the level of logging of ALL the application loggers.","returns":"The logLevel value used in all loggers.\n"},"type":{"type":"instrinct","name":"number"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":147,"character":32}]},{"id":55,"name":"getLogger","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":56,"name":"getLogger","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Gets the instance of a logger associated with a particular id (or creates one if it doesn't already exist).","returns":"The instance of the logger, or creates a new logger if none exists for that id.\n"},"parameters":[{"id":57,"name":"id","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The id of the logger you wish to get an instance of."},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"reference","name":"Logger","id":27}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":90,"character":33}]},{"id":61,"name":"removeAppender","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":62,"name":"removeAppender","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Removes an appender."},"parameters":[{"id":63,"name":"appender","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"An appender that has been added previously.\n"},"type":{"type":"reference","name":"Appender","id":10}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":108,"character":38}]},{"id":72,"name":"removeCustomLevel","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":73,"name":"removeCustomLevel","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Removes a custom log level."},"parameters":[{"id":74,"name":"name","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"The name of a custom log level that has been added previously.\n"},"type":{"type":"instrinct","name":"string"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":133,"character":41}]},{"id":75,"name":"setLevel","kind":64,"kindString":"Function","flags":{"isExported":true},"signatures":[{"id":76,"name":"setLevel","kind":4096,"kindString":"Call signature","flags":{},"comment":{"shortText":"Sets the level of logging for ALL the application loggers."},"parameters":[{"id":77,"name":"level","kind":32768,"kindString":"Parameter","flags":{},"comment":{"text":"Matches a value of logLevel specifying the level of logging.\n"},"type":{"type":"instrinct","name":"number"}}],"type":{"type":"instrinct","name":"void"}}],"sources":[{"fileName":"aurelia-logging.d.ts","line":140,"character":32}]}],"groups":[{"title":"Classes","kind":128,"children":[27]},{"title":"Interfaces","kind":256,"children":[10,2]},{"title":"Variables","kind":32,"children":[54]},{"title":"Functions","kind":64,"children":[58,68,66,64,78,55,61,72,75]}]} -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | require('require-dir')('build/tasks'); 2 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | // Generated on Fri Dec 05 2014 16:49:29 GMT-0500 (EST) 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | 7 | // base path that will be used to resolve all patterns (eg. files, exclude) 8 | basePath: '', 9 | 10 | 11 | // frameworks to use 12 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 13 | frameworks: ['jspm', 'jasmine'], 14 | 15 | jspm: { 16 | // Edit this to your needs 17 | loadFiles: ['src/**/*.js', 'test/**/*.js'] 18 | }, 19 | 20 | 21 | // list of files / patterns to load in the browser 22 | files: [], 23 | 24 | 25 | // list of files to exclude 26 | exclude: [ 27 | ], 28 | 29 | 30 | // preprocess matching files before serving them to the browser 31 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 32 | preprocessors: { 33 | 'test/**/*.js': ['babel'], 34 | 'src/**/*.js': ['babel'] 35 | }, 36 | 'babelPreprocessor': { 37 | options: { 38 | sourceMap: 'inline', 39 | presets: [ 'es2015-loose', 'stage-1'], 40 | plugins: [ 41 | 'syntax-flow', 42 | 'transform-decorators-legacy', 43 | 'transform-flow-strip-types' 44 | ] 45 | } 46 | }, 47 | 48 | 49 | // test results reporter to use 50 | // possible values: 'dots', 'progress' 51 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 52 | reporters: ['progress'], 53 | 54 | 55 | // web server port 56 | port: 9876, 57 | 58 | 59 | // enable / disable colors in the output (reporters and logs) 60 | colors: true, 61 | 62 | 63 | // level of logging 64 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 65 | logLevel: config.LOG_INFO, 66 | 67 | 68 | // enable / disable watching file and executing tests whenever any file changes 69 | autoWatch: true, 70 | 71 | 72 | // start these browsers 73 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 74 | browsers: ['Chrome'], 75 | 76 | 77 | // Continuous Integration mode 78 | // if true, Karma captures browsers, runs the tests and exits 79 | singleRun: false 80 | }); 81 | }; 82 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aurelia-logging", 3 | "version": "1.5.3", 4 | "description": "A minimal but effective logging mechanism with support for log levels and pluggable log appenders.", 5 | "keywords": [ 6 | "aurelia", 7 | "logging" 8 | ], 9 | "homepage": "http://aurelia.io", 10 | "bugs": { 11 | "url": "https://github.com/aurelia/logging/issues" 12 | }, 13 | "license": "MIT", 14 | "author": "Rob Eisenberg (http://robeisenberg.com/)", 15 | "main": "dist/commonjs/aurelia-logging.js", 16 | "module": "dist/native-modules/aurelia-logging.js", 17 | "typings": "dist/aurelia-logging.d.ts", 18 | "repository": { 19 | "type": "git", 20 | "url": "http://github.com/aurelia/logging" 21 | }, 22 | "scripts": { 23 | "test": "karma start --single-run", 24 | "build": "gulp build", 25 | "cut-release": "gulp prepare-release" 26 | }, 27 | "files": [ 28 | "dist", 29 | "doc", 30 | "src", 31 | "typings.json", 32 | "README.md", 33 | "LICENSE" 34 | ], 35 | "jspm": { 36 | "registry": "npm", 37 | "main": "aurelia-logging", 38 | "format": "amd", 39 | "directories": { 40 | "dist": "dist/amd" 41 | }, 42 | "devDependencies": { 43 | "babel": "babel-core@^5.1.13", 44 | "babel-runtime": "^5.1.13", 45 | "core-js": "^2.0.3" 46 | } 47 | }, 48 | "devDependencies": { 49 | "aurelia-tools": "^0.2.4", 50 | "babel-dts-generator": "^0.6.1", 51 | "babel-eslint": "^6.1.2", 52 | "babel-plugin-syntax-flow": "^6.8.0", 53 | "babel-plugin-transform-decorators-legacy": "^1.3.4", 54 | "babel-plugin-transform-es2015-modules-amd": "^6.8.0", 55 | "babel-plugin-transform-es2015-modules-commonjs": "^6.11.5", 56 | "babel-plugin-transform-es2015-modules-systemjs": "^6.11.6", 57 | "babel-plugin-transform-flow-strip-types": "^6.8.0", 58 | "babel-preset-es2015": "^6.9.0", 59 | "babel-preset-es2015-loose": "^7.0.0", 60 | "babel-preset-es2015-loose-native-modules": "^1.0.0", 61 | "babel-preset-stage-1": "^6.5.0", 62 | "del": "^2.2.1", 63 | "eslint": "^3.1.1", 64 | "gulp": "^3.9.1", 65 | "gulp-babel": "^6.1.2", 66 | "gulp-bump": "^2.2.0", 67 | "gulp-concat": "^2.6.0", 68 | "gulp-conventional-changelog": "^1.1.0", 69 | "gulp-eslint": "^3.0.1", 70 | "gulp-ignore": "^2.0.1", 71 | "gulp-insert": "^0.5.0", 72 | "gulp-rename": "^1.2.2", 73 | "gulp-typedoc": "^2.0.0", 74 | "gulp-typedoc-extractor": "^0.0.8", 75 | "gulp-typescript": "^2.13.6", 76 | "gulp-util": "^3.0.7", 77 | "jasmine-core": "^2.4.1", 78 | "jspm": "^0.16.53", 79 | "karma": "^1.1.2", 80 | "karma-babel-preprocessor": "^6.0.1", 81 | "karma-chrome-launcher": "^1.0.1", 82 | "karma-coverage": "^1.1.1", 83 | "karma-jasmine": "^1.0.2", 84 | "karma-jspm": "^2.2.0", 85 | "merge2": "^1.0.2", 86 | "object.assign": "^4.0.4", 87 | "require-dir": "^0.3.0", 88 | "run-sequence": "^1.2.2", 89 | "through2": "^2.0.1", 90 | "typedoc": "^0.4.4", 91 | "typescript": "^1.9.0-dev.20160622-1.0", 92 | "vinyl": "^1.1.1", 93 | "vinyl-paths": "^2.1.0", 94 | "yargs": "^4.8.1" 95 | }, 96 | "aurelia": { 97 | "documentation": { 98 | "articles": [] 99 | } 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Specifies the available logging levels. 3 | */ 4 | interface LogLevel { 5 | /** 6 | * No logging. 7 | */ 8 | none: number, 9 | /** 10 | * Log only error messages. 11 | */ 12 | error: number, 13 | /** 14 | * Log warnings messages or above. 15 | */ 16 | warn: number, 17 | /** 18 | * Log informational messages or above. 19 | */ 20 | info: number, 21 | /** 22 | * Log all messages. 23 | */ 24 | debug: number, 25 | 26 | /** 27 | * Additional log levels defined at runtime. 28 | */ 29 | [level: string]: number 30 | } 31 | 32 | /** 33 | * Specifies the available logging levels. 34 | */ 35 | export const logLevel: LogLevel = { 36 | none: 0, 37 | error: 10, 38 | warn: 20, 39 | info: 30, 40 | debug: 40 41 | }; 42 | 43 | let loggers = {}; 44 | let appenders = []; 45 | let globalDefaultLevel = logLevel.none; 46 | 47 | const standardLevels = ['none', 'error', 'warn', 'info', 'debug']; 48 | function isStandardLevel(level: string) { 49 | return standardLevels.filter(l => l === level).length > 0; 50 | } 51 | 52 | function appendArgs() { 53 | return [this, ...arguments]; 54 | } 55 | 56 | function logFactory(level) { 57 | const threshold = logLevel[level]; 58 | return function() { 59 | // In this function, this === logger 60 | if (this.level < threshold) { 61 | return; 62 | } 63 | // We don't want to disable optimizations (such as inlining) in this function 64 | // so we do the arguments manipulation in another function. 65 | // Note that Function#apply is very special for V8. 66 | const args = appendArgs.apply(this, arguments); 67 | let i = appenders.length; 68 | while (i--) { 69 | appenders[i][level](...args); 70 | } 71 | }; 72 | } 73 | 74 | function logFactoryCustom(level) { 75 | //This function is the same as logFactory() except that it checks that the method 76 | //is defined on the appender. 77 | const threshold = logLevel[level]; 78 | return function() { 79 | // In this function, this === logger 80 | if (this.level < threshold) { 81 | return; 82 | } 83 | // We don't want to disable optimizations (such as inlining) in this function 84 | // so we do the arguments manipulation in another function. 85 | // Note that Function#apply is very special for V8. 86 | const args = appendArgs.apply(this, arguments); 87 | let i = appenders.length; 88 | while (i--) { 89 | const appender = appenders[i]; 90 | if (appender[level] !== undefined) { 91 | appender[level](...args); 92 | } 93 | } 94 | }; 95 | } 96 | 97 | function connectLoggers() { 98 | let proto = Logger.prototype; 99 | for (let level in logLevel) { 100 | if (isStandardLevel(level)) { 101 | if (level !== 'none') { 102 | proto[level] = logFactory(level); 103 | } 104 | } else { 105 | proto[level] = logFactoryCustom(level); 106 | } 107 | } 108 | } 109 | 110 | function disconnectLoggers() { 111 | let proto = Logger.prototype; 112 | for (let level in logLevel) { 113 | if (level !== 'none') { 114 | proto[level] = function() { }; 115 | } 116 | } 117 | } 118 | 119 | /** 120 | * Gets the instance of a logger associated with a particular id (or creates one if it doesn't already exist). 121 | * 122 | * @param id The id of the logger you wish to get an instance of. 123 | * @return The instance of the logger, or creates a new logger if none exists for that id. 124 | */ 125 | export function getLogger(id: string): Logger { 126 | return loggers[id] || new Logger(id); 127 | } 128 | 129 | /** 130 | * Implemented by classes which wish to append log data to a target data store. 131 | */ 132 | interface Appender { 133 | 134 | /** 135 | * Appends a debug log. 136 | * 137 | * @param logger The source logger. 138 | * @param rest The data to log. 139 | */ 140 | debug(logger: Logger, ...rest: any[]): void; 141 | 142 | /** 143 | * Appends an info log. 144 | * 145 | * @param logger The source logger. 146 | * @param rest The data to log. 147 | */ 148 | info(logger: Logger, ...rest: any[]): void; 149 | 150 | /** 151 | * Appends a warning log. 152 | * 153 | * @param logger The source logger. 154 | * @param rest The data to log. 155 | */ 156 | warn(logger: Logger, ...rest: any[]): void; 157 | 158 | /** 159 | * Appends an error log. 160 | * 161 | * @param logger The source logger. 162 | * @param rest The data to log. 163 | */ 164 | error(logger: Logger, ...rest: any[]): void; 165 | } 166 | 167 | /** 168 | * Adds an appender capable of processing logs and channeling them to an output. 169 | * 170 | * @param appender An appender instance to begin processing logs with. 171 | */ 172 | export function addAppender(appender: Appender): void { 173 | if (appenders.push(appender) === 1) { 174 | connectLoggers(); 175 | } 176 | } 177 | 178 | /** 179 | * Removes an appender. 180 | * @param appender An appender that has been added previously. 181 | */ 182 | export function removeAppender(appender: Appender): void { 183 | appenders = appenders.filter(a => a !== appender); 184 | } 185 | 186 | /** 187 | * Gets an array of all appenders. 188 | */ 189 | export function getAppenders() { 190 | return [...appenders]; 191 | } 192 | 193 | /** 194 | * Removes all appenders. 195 | */ 196 | export function clearAppenders(): void { 197 | appenders = []; 198 | disconnectLoggers(); 199 | } 200 | 201 | /** 202 | * Adds a custom log level that will be added as an additional method to Logger. 203 | * Logger will call the corresponding method on any appenders that support it. 204 | * 205 | * @param name The name for the new log level. 206 | * @param value The numeric severity value for the level (higher is more severe). 207 | */ 208 | export function addCustomLevel(name: string, value: number): void { 209 | if (logLevel[name] !== undefined) { 210 | throw Error(`Log level "${name}" already exists.`); 211 | } 212 | 213 | if (isNaN(value)) { 214 | throw Error('Value must be a number.'); 215 | } 216 | 217 | logLevel[name] = value; 218 | 219 | if (appenders.length > 0) { 220 | //Reinitialize the Logger prototype with the new method. 221 | connectLoggers(); 222 | } else { 223 | //Add the custom level as a noop by default. 224 | Logger.prototype[name] = function() { }; 225 | } 226 | } 227 | 228 | /** 229 | * Removes a custom log level. 230 | * @param name The name of a custom log level that has been added previously. 231 | */ 232 | export function removeCustomLevel(name: string): void { 233 | if (logLevel[name] === undefined) { 234 | return; 235 | } 236 | 237 | if (isStandardLevel(name)) { 238 | throw Error(`Built-in log level "${name}" cannot be removed.`); 239 | } 240 | 241 | delete logLevel[name]; 242 | delete Logger.prototype[name]; 243 | } 244 | 245 | /** 246 | * Sets the level of logging for ALL the application loggers. 247 | * 248 | * @param level Matches a value of logLevel specifying the level of logging. 249 | */ 250 | export function setLevel(level: number): void { 251 | globalDefaultLevel = level; 252 | for (let key in loggers) { 253 | loggers[key].setLevel(level); 254 | } 255 | } 256 | 257 | /** 258 | * Gets the level of logging of ALL the application loggers. 259 | * 260 | * @return The logLevel value used in all loggers. 261 | */ 262 | export function getLevel(): number { 263 | return globalDefaultLevel; 264 | } 265 | 266 | /** 267 | * A logger logs messages to a set of appenders, depending on the log level that is set. 268 | */ 269 | export class Logger { 270 | /** 271 | * The id that the logger was created with. 272 | */ 273 | id: string; 274 | 275 | /** 276 | * The logging severity level for this logger 277 | */ 278 | level: number; 279 | 280 | /** 281 | * You cannot instantiate the logger directly - you must use the getLogger method instead. 282 | */ 283 | constructor(id: string) { 284 | let cached = loggers[id]; 285 | if (cached) { 286 | return cached; 287 | } 288 | 289 | loggers[id] = this; 290 | this.id = id; 291 | this.level = globalDefaultLevel; 292 | } 293 | 294 | /** 295 | * Logs a debug message. 296 | * 297 | * @param message The message to log. 298 | * @param rest The data to log. 299 | */ 300 | debug(message: string, ...rest: any[]): void {} 301 | 302 | /** 303 | * Logs info. 304 | * 305 | * @param message The message to log. 306 | * @param rest The data to log. 307 | */ 308 | info(message: string, ...rest: any[]): void {} 309 | 310 | /** 311 | * Logs a warning. 312 | * 313 | * @param message The message to log. 314 | * @param rest The data to log. 315 | */ 316 | warn(message: string, ...rest: any[]): void {} 317 | 318 | /** 319 | * Logs an error. 320 | * 321 | * @param message The message to log. 322 | * @param rest The data to log. 323 | */ 324 | error(message: string, ...rest: any[]): void {} 325 | 326 | /** 327 | * Sets the level of logging for this logger instance 328 | * 329 | * @param level Matches a value of logLevel specifying the level of logging. 330 | */ 331 | setLevel(level: number): void { 332 | this.level = level; 333 | } 334 | 335 | /** 336 | * Returns if the logger is in debug mode or not. 337 | */ 338 | isDebugEnabled(): boolean { 339 | return this.level === logLevel.debug; 340 | } 341 | } 342 | -------------------------------------------------------------------------------- /test/custom-levels.spec.js: -------------------------------------------------------------------------------- 1 | import * as LogManager from '../src/index'; 2 | 3 | describe('The log manager', () => { 4 | var logName = 'test', logger, testAppender, customLevelAppender; 5 | var customLevel = { name: 'trace', value: 35 }; // Value between info and debug. 6 | 7 | class TestAppender { 8 | debug(args) { } 9 | info(args){} 10 | warn(args){} 11 | error(args){} 12 | } 13 | 14 | class CustomLevelAppender { 15 | debug(args) { } 16 | info(args){} 17 | warn(args){} 18 | error(args){} 19 | trace(args){} 20 | } 21 | 22 | beforeEach(() => { 23 | LogManager.clearAppenders(); 24 | testAppender = new TestAppender(); 25 | customLevelAppender = new CustomLevelAppender(); 26 | }); 27 | 28 | function addLevel() { LogManager.addCustomLevel(customLevel.name, customLevel.value); } 29 | function removeLevel() { LogManager.removeCustomLevel(customLevel.name) } 30 | 31 | describe('calling addCustomLevel', () => { 32 | describe('should add level to logLevels', () => { 33 | beforeEach(addLevel); 34 | afterEach(removeLevel); 35 | 36 | it('with provided name', () => { 37 | expect(LogManager.logLevel[customLevel.name]).toBeDefined(); 38 | }); 39 | 40 | it('with the provided severity value', () => { 41 | expect(LogManager.logLevel[customLevel.name]).toBe(customLevel.value); 42 | }); 43 | }); 44 | 45 | it('should throw when level exists.', () => { 46 | expect(() => { LogManager.addCustomLevel("info", customLevel.value) }).toThrow(); 47 | }); 48 | 49 | it('should throw when severity value is not a number.', () => { 50 | expect(() => { LogManager.addCustomLevel(customLevel.name, "Invalid") }).toThrow(); 51 | }); 52 | 53 | function addsLevelAsMethod() { 54 | it('adds the level as a method of Logger', () => { 55 | const logger = LogManager.getLogger(logName); 56 | expect(logger.trace).toBeUndefined(); 57 | addLevel(); 58 | expect(typeof logger.trace).toBe("function"); 59 | removeLevel(); 60 | }); 61 | } 62 | 63 | describe('before appenders have been added', () => { 64 | addsLevelAsMethod(); 65 | }); 66 | 67 | describe('after appenders have been added', () => { 68 | beforeEach(() => { 69 | LogManager.addAppender(testAppender); 70 | LogManager.addAppender(customLevelAppender); 71 | }); 72 | 73 | addsLevelAsMethod(); 74 | }); 75 | }); 76 | 77 | describe('calling removeCustomLevel', () => { 78 | it('removes level from logLevels', () => { 79 | addLevel(); 80 | expect(LogManager.logLevel[customLevel.name]).toBeDefined(); 81 | removeLevel(); 82 | expect(LogManager.logLevel[customLevel.name]).toBeUndefined(); 83 | }); 84 | 85 | it('does nothing if level does not exist.', () => { 86 | expect(() => { LogManager.removeCustomLevel("nonexistent"); }).not.toThrow(); 87 | }); 88 | 89 | let level; 90 | for (level in LogManager.logLevels) { 91 | it(`should throw when called with built-in level "${level}"`, () => { 92 | expect(() => { LogManager.removeCustomLevel(level); }).toThrow(); 93 | }); 94 | } 95 | 96 | it('removes the level as a method of Logger', () => { 97 | const logger = LogManager.getLogger(logName); 98 | addLevel(); 99 | expect(logger.trace).toBeDefined(); 100 | removeLevel(); 101 | expect(logger.trace).toBeUndefined(); 102 | }); 103 | 104 | }); 105 | 106 | describe('', () => { 107 | beforeEach(() => { 108 | addLevel(); 109 | LogManager.clearAppenders(); 110 | customLevelAppender = new CustomLevelAppender(); 111 | spyOn(customLevelAppender, 'trace'); 112 | }); 113 | afterEach(removeLevel); 114 | 115 | it('calls custom method on supported appenders.', () => { 116 | LogManager.addAppender(customLevelAppender); 117 | const logger = LogManager.getLogger(logName); 118 | logger.setLevel(LogManager.logLevel.debug); 119 | logger.trace('foo'); 120 | expect(customLevelAppender.trace.calls.count()).toBe(1); 121 | }); 122 | 123 | it('does not call custom method on appender when level is higher than custom severity value.', () => { 124 | LogManager.addAppender(customLevelAppender); 125 | const logger = LogManager.getLogger(logName); 126 | logger.setLevel(LogManager.logLevel.info); 127 | logger.trace('foo'); 128 | expect(customLevelAppender.trace.calls.count()).toBe(0); 129 | }); 130 | 131 | it('does not attempt to call custom method on unsupported appenders.', () => { 132 | testAppender = new TestAppender(); 133 | LogManager.addAppender(testAppender); 134 | const logger = LogManager.getLogger(logName); 135 | logger.setLevel(LogManager.logLevel.debug); 136 | expect(() => { logger.trace('foo'); }).not.toThrow(); 137 | }); 138 | }); 139 | 140 | }); 141 | -------------------------------------------------------------------------------- /test/logging.spec.js: -------------------------------------------------------------------------------- 1 | import * as LogManager from '../src/index'; 2 | 3 | describe('A simple log manager test', () => { 4 | it('should return a logger', () => { 5 | var logger = LogManager.getLogger('test'); 6 | expect(logger).not.toBe(null); 7 | }); 8 | it('should default to logLevel none', () => { 9 | var logger = LogManager.getLogger('test2'); 10 | expect(logger.level).toBe(LogManager.logLevel.none); 11 | }); 12 | }); 13 | 14 | describe('The log manager ', () => { 15 | var logName = 'test', logger, testAppender; 16 | 17 | class TestAppender { 18 | debug(args) { } 19 | info(args){} 20 | warn(args){} 21 | error(args){} 22 | } 23 | 24 | beforeEach(() => { 25 | testAppender = new TestAppender(); 26 | 27 | spyOn(testAppender, 'debug'); 28 | spyOn(testAppender, 'info'); 29 | spyOn(testAppender, 'warn'); 30 | spyOn(testAppender, 'error'); 31 | 32 | LogManager.clearAppenders(); 33 | LogManager.addAppender(testAppender); 34 | 35 | logger = LogManager.getLogger(logName); 36 | LogManager.setLevel(LogManager.logLevel.none); 37 | }); 38 | 39 | describe('when calling getAppenders ', () => { 40 | it('should return an array of added appenders', () => { 41 | const testAppender2 = new TestAppender(); 42 | LogManager.addAppender(testAppender2); 43 | const appenders = LogManager.getAppenders(); 44 | expect(appenders instanceof Array).toBeTruthy(); 45 | expect(appenders).toEqual([testAppender, testAppender2]); 46 | }); 47 | 48 | it('should not expose the internal appenders array', () => { 49 | LogManager.getAppenders().push(new TestAppender()); 50 | expect(LogManager.getAppenders()).toEqual([testAppender]); 51 | }); 52 | }); 53 | 54 | it('should remove all appenders when calling clearAppenders', () => { 55 | LogManager.addAppender(new TestAppender()); 56 | expect(LogManager.getAppenders().length).toBe(2); 57 | LogManager.clearAppenders(); 58 | expect(LogManager.getAppenders().length).toBe(0); 59 | }); 60 | 61 | it('should remove the test appender', () => { 62 | LogManager.setLevel(LogManager.logLevel.debug); 63 | LogManager.removeAppender(testAppender); 64 | logger.debug('foo'); 65 | expect(testAppender.debug.calls.count()).toBe(0); 66 | }); 67 | 68 | it('should not add logLevel "none" as a method of Logger.', () => { 69 | expect(logger.none).toBeUndefined(); 70 | }); 71 | 72 | it('should call only call debug when logLevel is debug', () => { 73 | LogManager.setLevel(LogManager.logLevel.debug); 74 | logger.debug('foo'); 75 | 76 | LogManager.setLevel(LogManager.logLevel.info); 77 | logger.debug('foo'); 78 | 79 | LogManager.setLevel(LogManager.logLevel.warn); 80 | logger.debug('foo'); 81 | 82 | LogManager.setLevel(LogManager.logLevel.error); 83 | logger.debug('foo'); 84 | 85 | LogManager.setLevel(LogManager.logLevel.none); 86 | logger.debug('foo'); 87 | 88 | expect(testAppender.debug.calls.count()).toBe(1); 89 | }); 90 | 91 | it('should call only call info when logLevel is debug or info', () => { 92 | LogManager.setLevel(LogManager.logLevel.debug); 93 | logger.info('foo'); 94 | 95 | LogManager.setLevel(LogManager.logLevel.info); 96 | logger.info('foo'); 97 | 98 | LogManager.setLevel(LogManager.logLevel.warn); 99 | logger.info('foo'); 100 | 101 | LogManager.setLevel(LogManager.logLevel.error); 102 | logger.info('foo'); 103 | 104 | LogManager.setLevel(LogManager.logLevel.none); 105 | logger.info('foo'); 106 | 107 | expect(testAppender.info.calls.count()).toBe(2); 108 | }); 109 | 110 | it('should call only call warn when logLevel is debug, info, or warn', () => { 111 | LogManager.setLevel(LogManager.logLevel.debug); 112 | logger.warn('foo'); 113 | 114 | LogManager.setLevel(LogManager.logLevel.info); 115 | logger.warn('foo'); 116 | 117 | LogManager.setLevel(LogManager.logLevel.warn); 118 | logger.warn('foo'); 119 | 120 | LogManager.setLevel(LogManager.logLevel.error); 121 | logger.warn('foo'); 122 | 123 | LogManager.setLevel(LogManager.logLevel.none); 124 | logger.warn('foo'); 125 | 126 | expect(testAppender.warn.calls.count()).toBe(3); 127 | }); 128 | 129 | it('should call only call error when logLevel is debug, info, warn, or error', () => { 130 | LogManager.setLevel(LogManager.logLevel.debug); 131 | logger.error('foo'); 132 | 133 | LogManager.setLevel(LogManager.logLevel.info); 134 | logger.error('foo'); 135 | 136 | LogManager.setLevel(LogManager.logLevel.warn); 137 | logger.error('foo'); 138 | 139 | LogManager.setLevel(LogManager.logLevel.error); 140 | logger.error('foo'); 141 | 142 | LogManager.setLevel(LogManager.logLevel.none); 143 | logger.error('foo'); 144 | 145 | expect(testAppender.error.calls.count()).toBe(4); 146 | }); 147 | 148 | it('should pass arguments to the appender', () => { 149 | LogManager.setLevel(LogManager.logLevel.debug); 150 | logger.debug(123); 151 | 152 | expect(testAppender.debug).toHaveBeenCalledWith( logger, 123); 153 | }); 154 | 155 | it('should pass multiple arguments to the appender', () => { 156 | var objectToLog = { 157 | id: 1, 158 | name: 'John' 159 | }; 160 | 161 | LogManager.setLevel(LogManager.logLevel.debug); 162 | logger.debug(123, objectToLog); 163 | 164 | expect(testAppender.debug).toHaveBeenCalledWith( logger, 123, objectToLog); 165 | }); 166 | 167 | it('should throw an exception if the Logger class is newed up by the developer', () => { 168 | var attemptingToNewUpALogger = () => { var myNewLogger = new Logger(); }; 169 | expect(attemptingToNewUpALogger).toThrow(); 170 | }); 171 | 172 | it('should be able to return the global logLevel', () => { 173 | LogManager.setLevel(LogManager.logLevel.debug); 174 | var globalLogLevel = LogManager.getLevel(); 175 | 176 | expect(globalLogLevel).toEqual( LogManager.logLevel.debug); 177 | }); 178 | 179 | it('should be able to tell if the log level is debug', () => { 180 | LogManager.setLevel(LogManager.logLevel.debug); 181 | var isDebugEnabledAtDebugLevel = logger.isDebugEnabled(); 182 | 183 | LogManager.setLevel(LogManager.logLevel.warn); 184 | var isDebugEnabledAtWarnLevel = logger.isDebugEnabled(); 185 | 186 | expect(isDebugEnabledAtDebugLevel).toEqual(true); 187 | expect(isDebugEnabledAtWarnLevel).toEqual(false); 188 | }); 189 | 190 | describe('setting logLevel per individual logger instance', () => 191 | { 192 | it('should not log if specific logger logLevel is none', () => { 193 | // get a new logger we can squelch individually 194 | let logger2 = LogManager.getLogger('test2'); 195 | 196 | // sets log level for ALL loggers to debug 197 | LogManager.setLevel(LogManager.logLevel.debug); 198 | 199 | // set logger-specific level - turning off logging for the logger2 source 200 | logger2.setLevel(LogManager.logLevel.none); 201 | 202 | logger.debug('foo'); // this should log 203 | logger2.debug('foo'); // this should not 204 | 205 | expect(testAppender.debug.calls.count()).toBe(1); 206 | }); 207 | 208 | it('can log at different levels for different loggers', () => { 209 | var logger2 = LogManager.getLogger('test2'); 210 | 211 | logger.setLevel(LogManager.logLevel.error); 212 | logger2.setLevel(LogManager.logLevel.debug); 213 | 214 | logger.debug('foo'); 215 | logger.info('for'); 216 | logger.error('foo'); 217 | logger.warn('foo'); 218 | 219 | logger2.debug('foo'); 220 | 221 | expect(testAppender.debug.calls.count()).toBe(1); 222 | expect(testAppender.debug.calls.argsFor(0)).toEqual([jasmine.objectContaining({ id: 'test2'}), 'foo']); 223 | expect(testAppender.error.calls.count()).toBe(1); 224 | expect(testAppender.error.calls.argsFor(0)).toEqual([jasmine.objectContaining({ id: 'test'}), 'foo']); 225 | }); 226 | 227 | it('setting LogManager log level resets any logger-specific levels', () => { 228 | var logger2 = LogManager.getLogger('test2'); 229 | 230 | logger.setLevel(LogManager.logLevel.warn); 231 | logger2.setLevel(LogManager.logLevel.debug); 232 | // this overrides the individual log levels set above 233 | LogManager.setLevel(LogManager.logLevel.error); 234 | 235 | expect(logger2.level).toBe(LogManager.logLevel.error); 236 | expect(logger.level).toBe(LogManager.logLevel.error); 237 | }); 238 | 239 | it('carries a global logLevel with which all created loggers are initialized', () => { 240 | LogManager.setLevel(LogManager.logLevel.debug); 241 | var logger2 = LogManager.getLogger('test2'); 242 | expect(logger2.level).toBe(LogManager.logLevel.debug); 243 | }); 244 | }); 245 | }); 246 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2015", 4 | "module": "es2015", 5 | "experimentalDecorators": true, 6 | "emitDecoratorMetadata": false, 7 | "moduleResolution": "node", 8 | "stripInternal": true, 9 | "preserveConstEnums": true, 10 | "listFiles": true, 11 | "declaration": true, 12 | "removeComments": true, 13 | "lib": ["es2015", "dom"] 14 | }, 15 | "exclude": [ 16 | "node_modules", 17 | "dist", 18 | "build", 19 | "doc", 20 | "test", 21 | "config.js", 22 | "gulpfile.js", 23 | "karma.conf.js" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /typings.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "aurelia-logging", 3 | "main": "dist/aurelia-logging.d.ts" 4 | } 5 | --------------------------------------------------------------------------------