Coder Social home page Coder Social logo

logit's Introduction

Logit

Logger created in Golang. Runs as a separate goroutine.

Usage

Create a Loggit Object in your code, this will need to be a global variable so all functions can access it

var ThisLog *Logit.Logger

Logit accepts items that implement the "io.WriteCloser" to be valid Loggers. Included are funtions to Log to a File and the Terminal.

FileLog, err := Logit.OpenFile("/path/to/log/file")
TermLog := Logit.TermLog()

Somewhere in your code, you need to Start the Logging goroutine.

ThisLog, err = Logit.StartLogger(FileLog)
ThatLog, err = Logit.StartLogger(TermLog)

This will start a goroutine that has the file open.

Logit then uses Channels to push strings into this goroutine, writing them to the Log. Format a string to your liking, and simply pass it into the Log object that you created.

ThisLog.Log("string!")

Using the above will produce the following example output in the log:

09:15:15.918788110:  string!

On shutdown of your application, you will want to run the "Quit" function on your Logit Object to ensure all is closed and the goroutines are stopped.

ThisLog.Quit()
ThatLog.Quit()

Features

Able to handle concurrency. As long as your goroutine has access to a valid Logit Object, you are able to use the Log function safely. By pushing a string onto the channel, Logit will append it to the log when it can.

TODO

As of now if the log file is removed during runtime Logit will not complain, and all will continue to work without a hitch except logging. This is not ideal of course.

logit's People

Contributors

djhert avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.