Coder Social home page Coder Social logo

logd's Introduction

logd

A simple delphi logger util. Can log to file and directly to windows if the application is a service, viewable via the Event viwer.

TOC

Usage

A sample:

uses 
    Ulog;

procedure someFunc();
begin
    // log is a global, acessible to every file that includes Ulog
    log := Tlog.Create(
        'myApplication',
        nil,
        TlogLevel.logLevelWarning,
        true,
        TlogFilePeriod.periodDaily
    );

    log.debug('This is some debug info');
    log.info('This is some info');
    log.warning('This is a warning');
    log.error('CRITICAL');
end;

The result:

[25/01/2023 17:16:41 174ms] [       ]: ---------------------------- BEGIN LOG ----------------------------
[25/01/2023 17:16:41 293ms] [WARNING]: This is a warning
[25/01/2023 17:16:41 294ms] [ERROR  ]: CRITICAL

Documentation

Log level

The log level can be set by the class member Tlog.logLevel or on the Tlog.Create method.

The higher the level the more verbose ethe log will be, use TlogLevel.logLevelAll to see all levels. Available ones are:

  • TlogLevel.logLevelError
  • TlogLevel.logLevelWarning
  • TlogLevel.logLevelInfo
  • TlogLevel.logLevelDebug
  • TlogLevel.logLevelAll

Log file period

The log file period can be set by the class member Tlog.logFilePeriod or on the Tlog.Create method.

Dictates if a new log file should be created on a time period basis, see the options:

  • TlogFilePeriod.periodHourly: New log file every hour
  • TlogFilePeriod.periodDaily: New log file everyday
  • TlogFilePeriod.periodWeekly: New log file every week
  • TlogFilePeriod.periodMonthly: New log file every month
  • TlogFilePeriod.periodYearly: New log file every year
  • TlogFilePeriod.periodAlltime: Just one log file to everything

Services and the event viewer

Sometimes its conveninent to log to the windows machine instead of a file, or both!, because sometimes a service wont even be able to create a log file before crashing, for that you can always log to windows by passing a TService instance to the Tlog.Create call.

Logs can then be viewed under the Event Viewer, just hit the Windows key and search for the event viewer, then go to Windows Logs > Applications, then you should be able to see the logs for your service, as the Source column will have it's name.

Sample config file

[log]
# level 4 = Debug. See "TlogLevel" enum
level=4
# boolean to log to a file or not
logfile=true
# boolean to log to windows or not
logToWindows=false

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.