• Stars
    star
    158
  • Rank 228,927 (Top 5 %)
  • Language
    Go
  • License
    Do What The F*ck ...
  • Created over 9 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Minimalistic logging library for Go.

logger

Minimalistic logging library for Go. Features:

Install

$ go get github.com/azer/logger

Getting Started

Create an instance with a preferred name;

import "github.com/azer/logger"

var log = logger.New("example-app")

Every logger has three methods: Info, Timer and Error.

log.Info("Running at %d", 8080)

err := DoSomething()

if err != nil {
  log.Error("Failed: %s", err.Error())
}

Done. Now run your app, passing LOG=* environment variable. If you don't pass LOG=*, (logging will be silent by default);

$ LOG=* go run example-app.go
01:23:21.251 example-app Running at 8080

You can filter logs by level, too. The hierarchy is; mute, info, timer and error. After the package selector, you can optionally specify minimum log level:

$ LOG=*@timer go run example-app.go
01:23:21.251 example-app Running at 8080

The above example will only show timer and error levels. If you choose error, it'll show only error logs.

Check out examples for a more detailed example.

Filters

You can enable all logs by specifying *:

$ LOG=* go run example-app.go

Or, choose specific packages that you want to see logs from:

$ LOG=images,users go run example-app.go

In the above example, you'll only see logs from images and users packages. What if we want to see only timer and error level logs?

$ LOG=images@timer,users go run example-app.go

Another example; show error logs from all packages, but hide logs from database package:

$ LOG=*@error,database@mute go run example-app.go

Timers

You can use timer logs for measuring your program. For example;

timer := log.Timer()

image, err := PullImage("http://foo.com/bar.jpg")

timer.End("Fetched foo.com/bar.jpg")

Timer log lines will be outputting the elapsed time in time.Duration in a normal terminal, or in int64 format when your program is running on a non-terminal environment. See below documentation for more info.

Structured Output

When your app isn't running on a terminal, it'll change the output in JSON:

{ "time":"2014-10-04 11:44:22.418595705 -0700 PDT", "package":"database", "level":"INFO", "msg":"Connecting to mysql://azer@localhost:9900/foobar" }
{ "time":"2014-10-04 11:44:22.418600851 -0700 PDT", "package":"images", "level":"INFO", "msg":"Requesting an image at foo/bar.jpg" }
{ "time":"2014-10-04 11:44:22.668645527 -0700 PDT", "package":"images", "level":"TIMER", "elapsed":"250032416", "msg":"Fetched foo/bar.jpg" }
{ "time":"2014-10-04 11:44:22.668665527 -0700 PDT", "package":"database", "level":"ERROR", "msg":"Fatal connection error." }

So you can parse & process the output easily. Here is a command that lets you see the JSON output in your terminal;

LOG=* go run examples/simple.go 2>&1 | less

Attributes

To add custom attributes to the structured output;

log.Info("Sending an e-mail...", logger.Attrs{
  "from": "[email protected]",
  "to": "[email protected]",
})

The above log will appear in the structured output as:

{ "time":"2014-10-04 11:44:22.919726985 -0700 PDT", "package":"mail", "level":"INFO", "msg":"Sending an e-mail", "from": "[email protected]", "to": "[email protected]" }

In your command-line as:

Programmatical Usage

Customizing the default behavior is easy. You can implement your own output;

import (
  "github.com/azer/logger"
)

type CustomWriter struct {}

func (cw CustomWriter) Write (log *logger.Log) {
  fmt.Println("custom log -> ", log.Package, log.Level, log.Message, log.Attrs)
}

func main () {
  logger.Hook(&CustomWriter{})
}

See examples/programmatical.go for a working version of this example.

Hooks

  • Slack: Stream logs into a Slack channel.

More Repositories

1

boxcars-archived

Easy-to-configure Static Web & Reverse Proxy Server in Go
Go
625
star
2

kaktus

Experimental web browser with minimalistic design
JavaScript
417
star
3

prova

Test runner based on Tape and Browserify
JavaScript
334
star
4

crud

Relational database library for SQL databases & Go.
Go
311
star
5

go-makefile-example

Example Makefile for Go projects
Makefile
265
star
6

emacs

Ready-to-use Emacs Setup for JavaScript and Go
Emacs Lisp
226
star
7

atlas

DEPRECATED: I'm using labstack/echo now.
Go
181
star
8

memdiff

BDD style memory leak hunting tool
JavaScript
153
star
9

yolo

File watcher with web UI.
Go
133
star
10

alert

JavaScript library to play sound alerts
JavaScript
111
star
11

mao

Pragmatic BDD Testing Framework For Go
Go
102
star
12

shell-jobs

Human-friendly Cron replacement in NodeJS
JavaScript
96
star
13

english-time

Parses times written in simple English to unix time.
JavaScript
88
star
14

relative-date

Javascript module for outputting relative dates.
JavaScript
81
star
15

functools

DEPRECATED: Use small modules instead
JavaScript
79
star
16

radio-paradise

Radio Paradise Client made with Elm and Go
JavaScript
76
star
17

play-audio

Lightweight Wrapper For HTML5 Audio API
JavaScript
70
star
18

developers-in-turkey

A list of Turkish provinces by the count of software developers.
JavaScript
66
star
19

lowkick

simplifies running javascript tests on varied environments, from command-line.
JavaScript
61
star
20

watch-array

Lets you subscribe to any changes on native JavaScript arrays.
JavaScript
59
star
21

distractions

A command-line tool to define distracting websites and turn them on/off when needed.
Shell
58
star
22

prova-retired

RETIRED Check out http://github.com/azer/prova
JavaScript
57
star
23

personal-api

NodeJS API server to publish personal info.
JavaScript
49
star
24

declarative-js

Declarative async programming with JavaScript
JavaScript
49
star
25

door

Minimalistic HTTP proxy server with config auto-reloading and static file serving.
JavaScript
47
star
26

indexeddb

Well-tested, low-level wrapper around the IndexedDB API. It can sync locally and remotely.
TypeScript
45
star
27

homepage

My personal website
JavaScript
39
star
28

html-patcher

Virtual DOM Diff & Patch with HTML Templates
JavaScript
35
star
29

environ

Cross-platform environment detection library for JavaScript
JavaScript
32
star
30

miso-emacs

Opinionated Emacs distro for minimalists.
Emacs Lisp
32
star
31

ourtunes

Roll your music player in a few minutes, with single command.
JavaScript
31
star
32

jsbuild

JSBuild is a command-line utility that provides building CommonJS modules and packages for web
Python
30
star
33

observer

CommonJS Implementation of the Observer Pattern
JavaScript
29
star
34

prettify-error

Prettify given error objects for console outputs
JavaScript
29
star
35

js-yasnippets

OUT OF DATE
28
star
36

.w3

A Google Chrome extension that executes JavaScript and CSS files in ~/.w3
D
27
star
37

debug

Tiny Debugging Tool For Golang
Go
27
star
38

get-object-path

Return the value at given object path.
JavaScript
23
star
39

toledo-chess

Unobtrusive, indented fork of Oscar Toledo's Javascript Chess
JavaScript
21
star
40

npm.el

Create and rule NPM packages from Emacs
Emacs Lisp
21
star
41

go-preact-starter

Starter for combining Go and Preact in any web project.
Go
20
star
42

play-url

Unified API for playing Youtube, Rdio, SoundCloud and Mp3 URLs.
JavaScript
19
star
43

remotely

Run given command remotely via SSH
JavaScript
18
star
44

new-list

Array-like objects with PubSub interfaces that you can subscribe to changes.
JavaScript
17
star
45

new-struct

Structs inspred from Golang
JavaScript
17
star
46

strip

Strip HTML Tags
JavaScript
17
star
47

gezi

Gezi Web Browser
JavaScript
17
star
48

render-loop

Async DOM render loop with Virtual DOM diffing
JavaScript
16
star
49

with-env

Read and apply .env file (if exists) in the working directory.
JavaScript
16
star
50

node-eksi-sozluk

NodeJS client to query Eksi Sozluk
JavaScript
16
star
51

javascript-guide

Azer's JavaScript Guide
16
star
52

measure-time

create benchmark suites and see the time consumption per given functions.
JavaScript
15
star
53

indexhtml

Generate a customized index.html file
JavaScript
15
star
54

highkick

HighKick is a small testing framework that I like.
JavaScript
15
star
55

juxt.js

Take a set of functions, return a function that is the juxtaposition of those functions.
JavaScript
14
star
56

7min.io

7min Workout App
JavaScript
13
star
57

pubsub

Minimalistic Pubsub Implementation
JavaScript
13
star
58

turkish-dictionary-api

API Server for the official Turkish-to-turkish dictionary by TDK
JavaScript
12
star
59

dotfiles

my dotfiles
Emacs Lisp
12
star
60

snakecase

Go library for converting given string to snake case
Go
12
star
61

new-chain

Create chaining APIs from functions
JavaScript
11
star
62

virtual-glue

Render HTML with Hyperglue and VirtualDOM
JavaScript
11
star
63

subscription

NodeJS library to simplify paid subscriptions with Stripe and LevelDB.
JavaScript
11
star
64

go-choo-starter

Starter for choo projects with Go backend.
Go
10
star
65

run-after

Run a command after given time based on english-time
Ruby
10
star
66

format-text

String formatting library inspired from Python
JavaScript
10
star
67

ethereum-tipping-wallet

Chrome extension for tipping websites with Ethereum
TypeScript
10
star
68

style-format

Library to easily style texts with string formatting.
JavaScript
10
star
69

remote-control

Run remote commands in a web page via HTTP requests.
JavaScript
10
star
70

go-style

Console styling library for Golang
Go
10
star
71

redux-starter

Hek Module for Redux
JavaScript
10
star
72

require-sdk

JavaScript library for making sure given SDK is loaded and executed. Designed for popular APIs like Youtube, Rdio, Soundcloud etc.
JavaScript
9
star
73

afrikaradyo.com

JavaScript
9
star
74

after-time

Declarative setTimeout
JavaScript
8
star
75

expand-home-dir

Expand ~/
JavaScript
8
star
76

scrape-url

Scrape URLs with CSS selectors
JavaScript
8
star
77

new-object

Objects that you can subscribe to changes.
JavaScript
8
star
78

new-command

Simplifies creating CLI programs by combining minimist, show-help, show-version modules.
JavaScript
8
star
79

flat-glob

Return glob applied, flattened and duplicate filtered version of the given list of filenames
JavaScript
8
star
80

concat

Concatenate files
JavaScript
7
star
81

right-pad

string right pad
JavaScript
7
star
82

roka

High-level styling library for React
TypeScript
7
star
83

attr

Observable Attributes
JavaScript
7
star
84

title-from-url

Generate a title from given URL
JavaScript
7
star
85

styled

console styling library
JavaScript
7
star
86

domloader

JavaScript
7
star
87

genpkg

Generate NodeJS Packages from JavaScript files
JavaScript
7
star
88

next-time

Returns the nearest date of given time
JavaScript
7
star
89

chessboard

Pure HTML&XSLT Chess Board with FEN Support
6
star
90

logger-slack-hook

Slack hook for logger library
Go
6
star
91

deprecated-roka

[deprecated] A new javascript framework targeting modern web/javascript engines
JavaScript
6
star
92

memoize-async

Async Function Memoizer
JavaScript
6
star
93

anglicize

Anglicize the special characters in given text
JavaScript
6
star
94

urls

URL Library for Kaktüs
JavaScript
6
star
95

delicious-surf

a web browser for better bookmarking
C
6
star
96

duba

CLI tool for managing multiple remote and local workspaces using SSH
JavaScript
5
star
97

elm-ui-styles

UI Library for Elm, inspired by Tachyons.
Elm
5
star
98

anakaynak.com

anakaynak.com source code
JavaScript
5
star
99

flatten-array

Flattens nested arrays.
JavaScript
5
star
100

vimfiles

My VIM Configuration Files
Vim Script
5
star