All Projects → akoidan → lines-logger

akoidan / lines-logger

Licence: MIT license
Browser logger that rests lines in peace

Programming Languages

typescript
32286 projects
HTML
75241 projects
javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to lines-logger

Golog
A high-performant Logging Foundation for Go Applications. X3 faster than the rest leveled loggers.
Stars: ✭ 208 (+700%)
Mutual labels:  logger
ng-logger
Angular logger service
Stars: ✭ 65 (+150%)
Mutual labels:  logger
ets2-job-logger
ETS2 Job Logger
Stars: ✭ 15 (-42.31%)
Mutual labels:  logger
Bus
Bus 是一个基础框架、服务套件,它基于Java8编写,参考、借鉴了大量已有框架、组件的设计,可以作为后端服务的开发基础中间件。代码简洁,架构清晰,非常适合学习使用。
Stars: ✭ 253 (+873.08%)
Mutual labels:  logger
log
Aplus Framework Log Library
Stars: ✭ 14 (-46.15%)
Mutual labels:  logger
Torch-Scope
A Toolkit for Training, Tracking, Saving Models and Syncing Results
Stars: ✭ 62 (+138.46%)
Mutual labels:  logger
Odin
Fast & Functional logger in Scala
Stars: ✭ 225 (+765.38%)
Mutual labels:  logger
perforce-commit-discord-bot
🗒️ ✏️Posts the most recent commit messages from a Perforce version control server to a Discord channel.
Stars: ✭ 22 (-15.38%)
Mutual labels:  logger
DustViewerSharp
UART-USB based dust sensor viewer(and also logging) program by C#
Stars: ✭ 38 (+46.15%)
Mutual labels:  logger
loggers
Abstract logging for Golang projects. A kind of log4go in the spirit of log4j
Stars: ✭ 17 (-34.62%)
Mutual labels:  logger
mini-async-log-c
Mini async log C port. Now with C++ wrappers.
Stars: ✭ 69 (+165.38%)
Mutual labels:  logger
QuickTraceiOSLogger
A real time iOS log trace tool, view iOS log with pc web browser under local area network, which will automatically scroll like xcode. 一个实时的iOS日志跟踪工具,在局域网中使用 PC Web 浏览器查看 iOS 日志,它将像xcode一样自动滚动。
Stars: ✭ 16 (-38.46%)
Mutual labels:  logger
WormholyForObjectiveC
Network debugging made easy,This network debugging tool is developed based on the swift version of Wormholy.
Stars: ✭ 21 (-19.23%)
Mutual labels:  logger
Chipmunk
log analysis tool
Stars: ✭ 247 (+850%)
Mutual labels:  logger
Web-Tracker
Stand alone program that Tracks/Logs all the opened websites in the Chrome Browser. Even incognito! *No need to install anything in browser*
Stars: ✭ 34 (+30.77%)
Mutual labels:  logger
Timber Elixir
🌲 Great Elixir logging made easy
Stars: ✭ 226 (+769.23%)
Mutual labels:  logger
junit.testlogger
JUnit test logger for vstest platform
Stars: ✭ 61 (+134.62%)
Mutual labels:  logger
logback-access-spring-boot-starter
Spring Boot Starter for Logback-access.
Stars: ✭ 153 (+488.46%)
Mutual labels:  logger
LogDNA-Android-Client
Android client for LogDNA
Stars: ✭ 22 (-15.38%)
Mutual labels:  logger
l
Golang Pretty Logger
Stars: ✭ 51 (+96.15%)
Mutual labels:  logger

lines-logger GitHub license npm version Build Status codecov contributions welcome Code Style: Google

NPM

A simple browser logger that features:

  • Colored tags
  • Show origin source files
  • Supports log levels that can be changed in runtime.

Make your logs look like this:

logs example

Installation:

With npm:

Install the logger npm install lines-logger --save.

By including a link:

<script src="https://cdn.jsdelivr.net/npm/lines-logger@{{VERSION}}/lib/browser.js"></script>
<script>
var LoggerFactory  = linesLogger.LoggerFactory;
var loggerFactory = new LoggerFactory();
var logger = loggerFactory.getLogger('tag');
</script>

where {{VERSION}} is npm version. e.g. https://cdn.jsdelivr.net/npm/[email protected]/lib/browser.js

Configuration

Create logger

If you use javascript:

var LoggerFactory = require('lines-logger').LoggerFactory; // import {LoggerFactory} from 'lines-logger';
var loggerFactory = new LoggerFactory();
var logger = loggerFactory.getLogger('tag');

If you use Typescript:

import {Logger, LoggerFactory} from 'lines-logger';

let factory: LoggerFactory = new LoggerFactory();
let logger: Logger = factory.getLogger('tag');

Log anywhere in your code:

logger.log('Hello world')(); // pay attention to () in the end. `logger.log` returns a function that should be called, thus `console.log` is called from YOUR location instead of the library.
logger.debug('My array is {}, object is {}', [1,2,3], {1:1, 2:2})();

Documentation

LoggerFactory API

method description
getLogger Returns a logger object that has binded functions warn/error/log/debug/trace
setLogWarnings(LEVEL) Sets logger level see LogLevel
getSingleLoggerStyle Returns single logger function with specified style
getSingleLogger Returns single logger function with random color (color persist if tag is the same)
getSingleLoggerColor Same as getSingleLogger but with predefined tag color
getLoggerColor Same as getLogger, but with predefined tag style

LogLevel

name importance description
log_raise_error 1 Log everything and if params specified in string construct mismatch actual arguments, e.g. logger.log('two params given {} {}', one_suplied)(); throw an error.
log_with_warnings 2 Log everything and if params specified in string construct mismatch actual arguments, e.g. logger.log('one param given {}', one_suplied, two_supplied)(); warn in console about it.
trace 3 Log everything.
debug 4 Log debug, info, warn, error only. trace won't be printed.
info 5 Log info, warn, error only. debug and trace won't be printed.
warn 6 Log warn, error only. info, debug and trace won't be printed.
error 7 Log error only. warn info, debug and trace won't be printed.
disable 8 Disable all logs completely

Logger API

method description
logger.trace('Hello world')() Executes console.trace('YOUR TEXT') if log level is less\equal trace, level 3
logger.debug('Hello world')() Executes console.debug('YOUR TEXT') if log level is less\equal debug level 4
logger.log('Hello world')() Executes console.log('YOUR TEXT') if log level is less\equal info level 5
logger.warn('Hello world')() Executes console.warn('YOUR TEXT') if log level is less\equal warn level 6
logger.error('Hello world')() Executes console.log('YOUR TEXT') if log level is less\equal error level 7
logger.log('Hello {}!', 'world')() Logger allow to print params to the middle of the line, by using {}

Best practices:

  • Check vue-webpack-typescript repository for an example of project structure with lines logger.
  • Use positional arguments like logger.log('Hello {}', { text: 'world'} ) when you want a browser to paste an object instead of string. Remember chrome and some other browsers don't freeze this object, meaning it's live. So when you later change its value it automatically changes in the log (if it's not rendered yet). So if you need to paste just a simple text use es6 templates: logger.log(``Hello world``) .
  • If you need time for your logs, modern browser provide that out of the box. E.g. in chrome you can go to preferences -> console -> Show timestamps.
  • You can turn off logs for production builds, while creating logger factory new LoggerFactory('disable'); or using method setLogWarnings('disable'). E.g. for webpack you can use DefinePlugin, the example is here
  • You would probably like to expose loggerFactory to global scope (window). Thus in case of troubleshooting you can go to production site and turn on logs during runtime.
var LoggerFactory = require('lines-logger').LoggerFactory;
var loggerFactory = new LoggerFactory();
window.loggerFactory = loggerFactory

Now if you need to debug your production site you can just open devtools and type loggerFactory.setLogWarnings('trace')

  • If you want to intercept/mock logs for testing or any other purpose, you can pass object callbacks as a 2nd param to a loggerFactory constructor
import { spy } from 'sinon'
var loggerSpy = spy()
new LoggerFactory('trace', {
  error: function () {
    loggerSpy(arguments)
  },
  warn: function () {
    loggerSpy(arguments)
  },
  trace: function () {
    loggerSpy(arguments)
  },
  debug: function () {
    loggerSpy(arguments)
  },
  log: function () {
    loggerSpy(arguments)
  }
})
  • Timestamps . I inspire to use integrated timestamps feature in the browser instead of custom parameter in the logger. See this feature

Contributions

This package uses only ts with target es5. I also added babel config, but it seems like it's redundant, so it's not used.

  • yarn install - installs devDependencies. I use yarn.lock but npm work as well.
  • yarn build - compiles code to ./lib directory. This build has:
    • Type definitions in index.d.ts
    • Umd version for import via script tag browser.js
    • CommonJS version for if you use bundler like webpack index.js.
  • yarn test - runs mocha tests from `./test/index.ts.
  • yarn lint:check - lints the src directory. Ignore the test dir.
  • yarn lint:fix - automatically fixes wrong formatting in src.
  • yarn publish - updates npm version
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].