Coder Social home page Coder Social logo

filelog's Introduction

filelog

Functions to write logs in file disk for V.

Summary

About

I created this library to log behavior oriented data when my user browse my web app for debug purposes.

Features

  • Can log in a single file, or file per days (daily)
  • Prefix logs with the date and time (with microseconds) and the log severity (see Wikipedia Severity levels)

Installation

v install khalyomede.filelog

Examples

1. Log in a single file

In this example, we will log a debug message.

import khalyomede.filelog { FileLog, LogSaveMode }

fn main() {
  log := FileLog{
    folder: "logs",
    file_name: "app",
    save_mode: LogSaveMode.single,
  }

  log.debug("user accessed product #12")
}

If you open the file "logs/app.log", this is what you will see:

[2021-05-24 22:12:00.635101] [DBUG] user accessed product 12

2. Log in a daily file

In this example, we will log in a file that will be "rotate" per day.

import khalyomede.filelog { FileLog, LogSaveMode }

fn main() {
  log := FileLog{
    folder: "logs",
    file_name: "app",
    save_mode: LogSaveMode.daily,
  }

  log.debug("user 12 disconnected")
}

If you open the file logs/app-2021-05-24.log, this is what you will see:

[2021-05-24 22:12:00.635101] [DBUG] user 12 disconnected

The log will automatically append logs in a file prefixed by the date of the writting.

3. Log using a specific severity

In this example, we will log a message using a given severity.

import khalyomede.filelog { FileLog, LogSaveMode, LogSeverity }

fn main() {
  log := FileLog{
    folder: "logs",
    file_name: "app",
    save_mode: LogSaveMode.single,
  }

  log.log("session started", LogSeverity.notice)
}

If you open the file logs/app.log, this is what you will see:

[2021-05-24 22:12:00.635101] [NTCE] session started

Here is all the available severities:

LogSeverity.debug
LogSeverity.info
LogSeverity.notice
LogSeverity.warning
LogSeverity.error
LogSeverity.critical
LogSeverity.alert
LogSeverity.emergency

If you don't want to pass them manually, use the shorthand functions instead:

import khalyomede.filelog { FileLog, LogSaveMode }

fn main() {
  log := FileLog{
    folder: "logs",
    file_name: "app",
    save_mode: LogSaveMode.single,
  }

  log.debug("some message")
  log.info("some message")
  log.notice("some message")
  log.warning("some message")
  log.error("some message")
  log.critical("some message")
  log.alert("some message")
  log.emergency("some message")
}

Test

v test .

filelog's People

Contributors

khalyomede avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

irwin1985

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.