Giter Site home page Giter Site logo

tinyhiker / basic_logger Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 57 KB

I made a logger that logs object info to toyotas.log whenever a ToyotaCar object is created. Open logger_diagram.png to view a diagram that shows the components of a non-root logger and some of the commands used to make them.

License: MIT License

Python 100.00%
git logging logging-framework object-oriented-programming python

basic_logger's Introduction

ToyotaCar Logger Example

Summary of Skills and Concepts

  • Use of Python's logging module
  • Creation and configuration of loggers in Python
  • Creation and utilization of Python classes (ToyotaCar class)
  • Python file handling and manipulation

Introduction

This repository contains a Python code example that showcases the creation and usage of a logger using the Python logging module. The focus of this example is the implementation of logging within the context of a ToyotaCar class.

Usage

To run the code and see the logger in action:

  1. Ensure you have Python installed on your system.
  2. Clone this repository or download the code files.
  3. Open a terminal or command prompt and navigate to the directory where the code files are located.
  4. Execute the following command to run the code:
python main.py

This will execute the code and demonstrate the logging functionality.

Description

The code defines a ToyotaCar class that represents a Toyota car. It demonstrates how to initialize a logger, set its level, define a formatter, and add a file handler. The logger is used to log information about the creation of a ToyotaCar instance.

The ToyotaCar class includes various methods to interact with the car, such as starting and stopping the engine, accelerating, braking, and displaying car information.

Logging Details

Logger Creation Diagram

  • The logger is initialized using logging.getLogger(__name__), where __name__ represents the module name.
  • The logger's level is set to logging.INFO, which means it will capture log messages with an informational level or above.
  • The logger uses a Formatter object with the format '%(levelname)s:%(name)s:%(message)s', which specifies how the log messages should be formatted.
  • A FileHandler is added to the logger, which directs the log messages to a file named toyotas.log.
  • When a new ToyotaCar instance is created, an informational log message is recorded using the logger.info() method.

The code also demonstrates the usage of the ToyotaCar class by creating an instance, displaying its information, starting the engine, accelerating, braking, and stopping the engine.

Feel free to explore the code and experiment with different logging configurations to further understand the logging functionality in Python.

Note

Remember to configure the logger as per your application's requirements and modify the code accordingly.

Requirements

  • Python 3.x
  • logging module (included in the Python standard library)

basic_logger's People

Contributors

tinyhiker avatar

Watchers

 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.