kandi background
Explore Kits

log-courier | Log Courier , a lightweight log shipper

 by   driskell Go Version: v2.6.2 License: Apache-2.0

 by   driskell Go Version: v2.6.2 License: Apache-2.0

Download this library from

kandi X-RAY | log-courier Summary

log-courier is a Go library typically used in Logging applications. log-courier has no bugs, it has no vulnerabilities, it has a Permissive License and it has low support. You can download it from GitHub.
The Log Courier Suite is a set of lightweight tools created to ship and process log files speedily and securely, with low resource usage, to Elasticsearch or Logstash instances.
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • log-courier has a low active ecosystem.
  • It has 408 star(s) with 112 fork(s). There are 24 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 10 open issues and 318 have been closed. On average issues are closed in 516 days. There are no pull requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of log-courier is v2.6.2
log-courier Support
Best in #Go
Average in #Go
log-courier Support
Best in #Go
Average in #Go

quality kandi Quality

  • log-courier has no bugs reported.
log-courier Quality
Best in #Go
Average in #Go
log-courier Quality
Best in #Go
Average in #Go

securitySecurity

  • log-courier has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
log-courier Security
Best in #Go
Average in #Go
log-courier Security
Best in #Go
Average in #Go

license License

  • log-courier is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
log-courier License
Best in #Go
Average in #Go
log-courier License
Best in #Go
Average in #Go

buildReuse

  • log-courier releases are available to install and integrate.
  • Installation instructions are available. Examples and code snippets are not available.
log-courier Reuse
Best in #Go
Average in #Go
log-courier Reuse
Best in #Go
Average in #Go
Top functions reviewed by kandi - BETA

kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here

Get all kandi verified functions for this library.

Get all kandi verified functions for this library.

log-courier Key Features

Log Courier Suite Log Courier Compatible Logstash Versions Log Carver Philosophy Documentation Installation Reference Upgrading from 1.x to 2.x

Community Discussions

Trending Discussions on Logging
  • How to dynamically pass variable to class __init__ method in a custom python logging class
  • MySql 5.5; possible to exclude a table from logging?
  • Exclude Logs from Datadog Ingestion
  • How can I add CSV logging mechanism in case of Multivariable Linear Regression using TensorFlow?
  • Implementing an interface with a generic parameter on a F# record
  • How to get message from logging function?
  • Python disabled logging slowing script
  • Xcode log "Writing analzed variants"
  • Was slf4j affected with vulnerability issue in log4j
  • Simple Logger erroring on init
Trending Discussions on Logging

QUESTION

How to dynamically pass variable to class __init__ method in a custom python logging class

Asked 2022-Apr-01 at 15:20

It is difficult to put what I need in a sentence but the code below pretty much explains it:

I have my logging class in a separate file (log_file) as below, and a logger object defined there:

from io import StringIO
import logging

class NetddLog():
   def __init__(self, name, format="%(asctime)s %(levelname)s %(message)s", level=logging.INFO):
      self.name = name
      self.level = level
      self.format = format

      #Logger configuration.
      self.formatter = logging.Formatter(self.format)
      self.logger = logging.getLogger(name)#name
      self.logger.setLevel(self.level)
      #Logging to memory
      self.log_capture_string = StringIO()
      self.ch_logger = logging.StreamHandler(self.log_capture_string)
      self.ch_logger.setFormatter(self.formatter)
      self.logger.addHandler(self.ch_logger)

   def debug(self, msg, extra=None):
      self.logger.debug(msg, extra=extra)

ip_logger = NetddLog("IP_LOG")

In another file (ip_file), I have my ping function as below:

from log_file import ip_logger
from icmplib import ping

def ping_ip(ip_num, ip):
    try: 
        ip_logger.info(f"{ip_num}: Pinging {ip} started")

        host = ping(ip, count=4, interval=1, timeout=2, payload_size=64, privileged=True)
        if host.is_alive:
            ip_logger.info(f"{ip_num}: Pinging {ip} succeded")
        else:
            raise Exception 

    except Exception as err:
        ip_logger.error(f"{ip_num}: Pinging {ip} failed {err}")

The ip_num is the number of the IP address(ip) in a IP addr list, in another file (main_file), from which I call ping_ip(ip_num, ip)

The log messages prints just fine, but I'm putting ip_num inside the actual log message, each time. What I want to do is, having included in the format of the logger when the logger is created in the class, and probably just call the function with ping_ip(ip)

So the format in the init class method will look something like this: format=f"%(asctime)s %(levelname)s {ip_num}: %(message)s" , this way I don't have to include ip_num inside every log message I create. Is there a way to achieve this within the current class configuration or an alternative way? (I want to keep things separated as much as possible and not put everything in the main_file)

Update: Based on a previous answer I just redefined the logging methods inside the class to add an extra parameter in the format. For instance info function would change like below, and %(ip_num)s can be added to the format.

   def info(self, ip_num, msg):
      self.d = {'ip_num': f"{ip_num}"}
      self.logger.info(msg, extra=self.d)

ANSWER

Answered 2022-Mar-31 at 21:12

Yes, you can achieve what you want, actually is well documented under: https://docs.python.org/3/howto/logging.html

There is a parameter where you can provide a dictionary with additional values to your log format.

Below you can find the snippet which does the job:

import logging


def config_log(FORMAT = '%(asctime)s %(levelname)s IP:%(ip_num)s %(message)s'):
    logging.basicConfig(filename='example.log', encoding='utf-8',format=FORMAT, level=logging.INFO)
    
def log_something(ipnum, mymessage):
    d = {'ip_num': f"{ipnum}"}
    logging.info(mymessage, extra=d)

if __name__ == "__main__":       
    config_log() 
    log_something("127.0.0.1",'Here is your message log')

Source https://stackoverflow.com/questions/71698579

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install log-courier

Public Repositories
Building from Source

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

Explore Related Topics

Share this Page

share link
Reuse Pre-built Kits with log-courier
Consider Popular Go Libraries
Try Top Libraries by driskell
Compare Go Libraries with Highest Support
Compare Go Libraries with Highest Quality
Compare Go Libraries with Highest Security
Compare Go Libraries with Permissive License
Compare Go Libraries with Highest Reuse
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases
Explore Kits

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.