Code Monkey home page Code Monkey logo

file_only_logger's Introduction

FileOnly Logger

A simple logger that writes messages to log files only (not to the console). Elixir's Logger Backends were abandoned in favor of Erlang's Logger handlers.

Installation

Add file_only_logger to your list of dependencies in mix.exs:

def deps do
  [
    {:file_only_logger, "~> 0.2.0"}
  ]
end

Proper configuration must be set via config files. See files config/config.exs and config/config_logger.exs as an example (including log file rotation).

Usage

Trying to log any message with severity less than the configured level will simply cause the message to be ignored.

The configuration values for log level are:

You may use file config/runtime.exs to configure the above log level:

import Config

config :file_only_logger, level: :info

Example

defmodule Log do
  use File.Only.Logger

  warning :error_occurred, {reason, file, env} do
    """
    \n'error' occurred...
    Reason => '#{:file.format_error(reason)}'
    File => #{Path.expand(file) |> inspect() |> maybe_break(8)}
    #{from(env, __MODULE__)}\
    """
  end
end

defmodule Check do
  def log_warning(file) do
    Log.warning(:error_occurred, {:enoent, file, __ENV__})
  end
end

Check.log_warning(__ENV__.file)
Check.log_warning("generate-line-break")
# will respectively log these lines in the configured log file(s):

2023-12-20 11:37:17.011 [warning]
'error' occurred...
Reason => 'no such file or directory'
File => "c:/Users/Ray/Documents/ex_dev/projects/file_only_logger/iex"App: file_only_loggerLibrary: file_only_loggerModule: LogFunction: Check.log_warning/1

2023-12-20 11:45:13.274 [warning]
'error' occurred...
Reason => 'no such file or directory'
File =>
  "c:/Users/Ray/Documents/ex_dev/projects/file_only_logger/generate-line-break"App: file_only_loggerLibrary: file_only_loggerModule: LogFunction: Check.log_warning/1

file_only_logger's People

Contributors

raymondloranger avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  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.