1.14.2 • Published 2 years ago

brolog v1.14.2

Weekly downloads
860
License
Apache-2.0
Repository
github
Last release
2 years ago

BROLOG

npm version Build Status Greenkeeper badge TypeScript definitions on DefinitelyTyped

Brolog

Brolog is Logger for Angular in Browser like Npmlog.

FEATURE

  1. Out-of-Box Browser Support.(with <script src='//unpkg.com/brolog'></script>)
  2. Out-of-Box Angular & SystemJS Support.(See: brolog-angular-demo project)
  3. Npmlog compatible interface.(i.e. log.verbose('Brolog', 'Hello, %s', 'world!''))
  4. Native TypeScript Support.(With typings)
  5. Node.js Support.(Node.js example)
  6. Support show real line number in browser console.

    What I really get frustrated by is that I cannot wrap console.* and preserve line numbers

    We enabled this in Chrome DevTools via blackboxing a bit ago.

EXAMPLE

Here's two example:

  1. First example to demo easy to use in browser, and how it looks like npmlog.
  2. Second example to demo intergrate with angular DI & SystemJS.

1. Super Easy to use in Browser

You can enable Brolog in your page by simple add the following script tag.

<script src="//unpkg.com/brolog"></script>
<html>
  <head>
    <script src="//unpkg.com/brolog"></script>
  </head>
  <body>
    <h1>Brolog in Browser Demo</h1>
    <script>

      var log = Brolog.instance('verbose')

      log.info('Test', '123 info message')
      log.verbose('Test', '123 verbose message')
      log.silly('Test', '123 silly message(should not appear)')

    </script>
  </body>
</html>

Link: Brolog Live demo

2. Quick Setup to use in Angular

Brolog is writen mainly for act as a logger with Angular. Here's how to Inject Brolog in Angular.

  1. install brolog

    $ npm install brolog --save
  2. setup SystemJS

    System.config({
      map: {
        brolog: 'node_modules/brolog/bundles/brolog.js'
      }
    })
  3. import

    import { Brolog } from 'brolog'
  4. inject to @NgModule

    providers: [
      Brolog,
    ]
  5. inject to constructor

    class LogApp {
      constructor(
        private log: Brolog
      ) {}
    }
  6. log

    class LogApp {
      testLog() {
        this.log.verbose('Brolog', 'test log:%s', 123)
        // this will log to browser console
      }
    }

More details, please see the brolog-angular-demo git repository at here.

Link: Brolog ♥ Angular Live demo

BASIC USAGE

Get a out-of-the-box log instance to use it directly.

import { log } from 'brolog'

If fhe environment variable BROLOG_LEVEL is set, that will be used to set log.level() for the global Brolog instance log.

log.{error,warn,info,verbose,silly}

import { Brolog } from 'brolog'

const log = new Brolog()

// additional stuff ---------------------------+
// message ----------+                         |
// prefix ----+      |                         |
// level -+   |      |                         |
//        v   v      v                         v
    log.info('fyi', 'I have a kitty cat: %j', myKittyCat)

log.level(newLevel)

  • {String} 'silent' | 'error' | 'warn' | 'info' | 'verbose' | 'silly'

The level to display logs at. Any logs at or above this level will be displayed. The special level silent will prevent anything from being displayed ever.

log[level](prefix, message, ...)

  • level {String} The level to emit the message at
  • prefix {String} A string prefix. Set to "" to skip.
  • message... Arguments to util.format

Emit a log message at the specified level.

For example,

  • log.silly(prefix, message, ...)
  • log.verbose(prefix, message, ...)
  • log.info(prefix, message, ...)
  • log.warn(prefix, message, ...)
  • log.error(prefix, message, ...)

TEST

Brolog comes with well test suit to ensure the behaviour is expected.

Unit Test

$ npm run unit

Unite Test Suite: link

End to End Test

$ npm run e2e

End to End Test Suite: link

P.S. runing E2E test is based on brolog demo project: git repository

CHANGELOG

Master

v1.4 (May 2018)

  1. Continus Deployment to brolog@next when the minor version in SemVer is odd(development release).

v1.3 (Apr 2018)

  1. Node.js: Add environment variable BROLOG_LEVEL to set the loglevel of global log instance.
  2. Browser: Add URL parameter variable BROLOG_LEVEL to set the loglevel of global log instance.

v1.2 (Sep 2017)

  1. Add Brolog.enableLogging() method for:
    1. false for disable logging
    2. true for enable logging
    3. printTextFunc: (text: string) for enable logging to a function.

v1.1 (May 2017)

  1. Support for creating individual instances.(We only have one singleton instance before)

v1.0 (Apr 2017)

Compatible with AOT & WebPack with Angular v4

  1. Rewrite from JavaScript to TypeScript
  2. Add UMD/AMD/System Module support
  3. Add a new method: enableLogging() to get/set logger

v0.4 (Mar 2017)

  1. added timestamp to log output
  2. fix CI back to work
  3. added CD to auto deploy source code to NPM after passed CI

v0.3.7 (Aug 2016)

  1. added End to End test with Angular
  2. supported include by script tag
  3. full support unpkg.com

v0.2.0 (Jul 16 2016)

  1. added Unit Test
  2. supported Angular Dependience Injection

v0.1.0 (Jul 14 2016)

  1. supported show real line number by set blackbox
  2. added TypeScript definition file
  3. supported work with SystemJS & Angular

REFERENCE

  1. JavaScript Modules & Build Tools - YouTube
  2. Writing Declaration Files
  3. Angular Dependency injection tokens
  4. Angular 2 Errors
  5. ES6 vs ES2015 - What to call a JavaScript version?

AUTHOR

Huan LI \zixia@zixia.net\ (http://linkedin.com/in/zixia)

COPYRIGHT & LICENSE

  • Code & Docs © 2017-2018 Huan LI \zixia@zixia.net\
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons
1.15.1

2 years ago

1.14.2

2 years ago

1.13.1

3 years ago

1.13.6

3 years ago

1.13.5

3 years ago

1.13.3

3 years ago

1.12.4

4 years ago

1.12.3

4 years ago

1.8.3

5 years ago

1.8.1

6 years ago

1.6.5

6 years ago

1.6.4

6 years ago

1.6.2

6 years ago

1.6.1

6 years ago

1.6.0

6 years ago

1.4.10

6 years ago

1.4.9

6 years ago

1.4.8

6 years ago

1.4.3

6 years ago

1.4.2

6 years ago

1.3.22

6 years ago

1.3.3

6 years ago

1.3.1

6 years ago

1.2.17

6 years ago

1.2.16

6 years ago

1.2.15

6 years ago

1.2.14

6 years ago

1.2.8

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.1.35

7 years ago

1.1.34

7 years ago

1.1.33

7 years ago

1.1.32

7 years ago

1.1.30

7 years ago

1.1.29

7 years ago

1.1.28

7 years ago

1.1.27

7 years ago

1.1.24

7 years ago

1.1.23

7 years ago

1.1.22

7 years ago

1.1.21

7 years ago

1.1.18

7 years ago

1.1.1

7 years ago

1.0.18

7 years ago

1.1.16

7 years ago

1.1.15

7 years ago

1.1.14

7 years ago

1.1.13

7 years ago

1.1.10

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.10

7 years ago

1.0.11

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

0.4.3

7 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.3.11

8 years ago

0.3.10

8 years ago

0.3.9

8 years ago

0.3.8

8 years ago

0.3.7

8 years ago

0.3.6

8 years ago

0.3.5

8 years ago

0.3.4

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago