GithubHelp home page GithubHelp logo

rails-4's Introduction

Rails gem for logging to LogDNA


This library is deprecated and will be removed on March 01 2020. Please use our Ruby library for Rails logging - instructions at https://github.com/logdna/ruby#rails-setup

Installation

Add this line to your application's Gemfile:

gem 'logdna-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install logdna-rails

Quick Setup

After installation, call

logger = Logdna::RailsLogger.new(your_api_key, options)
=> #<Logdna::Ruby:0x00000000000000>

to set up the logger.

Options are optional variables that may contain hostname, app name, mac address, ip address, log level specified.

options = {
    :hostname => myHostName,
    :ip =>  myIpAddress,
    :mac => myMacAddress,
    :app => myAppName,
    :level => "INFO",    # LOG_LEVELS = ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'] or your customized log level
    :env => "PRODUCTION",
    :meta => {:once => {:first => "nested1", :another => "nested2"}}
}

To send logs, use "log" method. Default log level is "INFO"

logger.log('This is my first log')
=> "Saved"  # Saved to buffer. Ready to be flushed automatically

Log a message with particular metadata, level, appname, environment (one-time)

logger.log('This is warn message', {:meta => {:meta => "data"}, :level => "WARN", :app => "awesome", :env => "DEVELOPMENT"})

Log a message with lasting metadata, level, appname, environment (lasting)

logger.meta = {:once => {:first => "nested1", :another => "nested2"}}
logger.level = 'FATAL'  or  logger.level = Logger::FATAL
logger.app = 'NEW APP NAME'
logger.env = 'PRODUCTION'
logger.log('This messages and messages afterwards all have the above values')

Clear current metadata, level, appname, environment

logger.clear

Check current log level:

logger.info? => true
logger.warn? => false

Log a message with a particular level easily

logger.warn('This is a warning message')
logger.fatal('This is a fatal message')

Hostname and app name cannot be more than 80 characters.

Important Notes

  1. This logger assumes that you pass in json formatted data
  2. This logger is a singleton (do not create mutiple instances of the logger) even though the singleton structure is not strongly enforced.

API

Logdna::RailsLogger.new(ingestion_key, options = {})

Instantiates a new instance of the class it is called on. ingestion_key is required.

Options Default
{ :hostname => Host name } Device's default hostname
{ :mac => MAC address } Nil
{ :ip => IP address } Nil
{ :app => App name } 'default'
{ :level => Log level } 'INFO'
{ :env => STAGING, PRODUCTION .. etc} Nil
{ :meta => metadata} Nil
{ :flushtime => Log flush interval in seconds } 0.25 seconds
{ :flushbyte => Log flush upper limit in bytes } 500000 bytes ~= 0.5 megabytes

Different log level displays log messages in different colors as well.

  • TRACE DEBUG INFO Colors "Trace" "Debug" "Info"
  • WARN Color "Warn"
  • ERROR Fatal Colors "Error" "Fatal"

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/logdna/rails.

License

The gem is available as open source under the terms of the MIT License.

rails-4's People

Contributors

cellvinchung avatar mattchoi1 avatar respectus avatar smusali avatar vilyapilya 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.