# phpman > perldoc > Log::Any::Adapter::Development

## NAME
    [Log::Any::Adapter::Development](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ADevelopment/markdown) - Manual for developing new [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown) adapters

## VERSION
    version 1.710

## SYNOPSIS
    The adapter module:

       package [Log::Any::Adapter::YAL](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3AYAL/markdown);
       use strict;
       use warnings;
       use [Log::Any::Adapter::Util](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3AUtil/markdown) ();
       use base qw([Log::Any::Adapter::Base](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ABase/markdown));

       # Optionally initialize object, e.g. for delegation
       #
       sub init {
           my ($self) = @_;

           $self->{attr} = ...;
       }

       # Create logging methods: debug, info, etc.
       #
       foreach my $method ( [Log::Any::Adapter::Util::logging_methods](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3AUtil%3A%3Aloggingmethods/markdown)() ) {
           no strict 'refs';
           *$method = sub { ... };
       }

       # or, support structured logging instead
       sub structured {
           my ($self, $level, $category, @args) = @_;
           # ... process and log all @args
       }


       # Create detection methods: is_debug, is_info, etc.
       #
       foreach my $method ( [Log::Any::Adapter::Util::detection_methods](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3AUtil%3A%3Adetectionmethods/markdown)() ) {
           no strict 'refs';
           *$method = sub { ... };
       }

    and the application:

       [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)->set_adapter('YAL');

## DESCRIPTION
    This document describes how to implement a new [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown) adapter.

    The easiest way to start is to look at the source of existing adapters, such as
    [Log::Any::Adapter::Log4perl](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ALog4perl/markdown) and [Log::Any::Adapter::Dispatch](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ADispatch/markdown).

## NAMING
    If you are going to publicly release your adapter, call it '[Log::Any::Adapter](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter/markdown)::*something*' so
    that users can use it with

        [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)->set_adapter(I<something>);

    If it's an internal driver, you can call it whatever you like and use it like

        [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)->set_adapter('+[My::Log::Adapter](https://www.chedong.com/phpMan.php/perldoc/My%3A%3ALog%3A%3AAdapter/markdown)');

## BASE CLASS
    All adapters must directly or indirectly inherit from [Log::Any::Adapter::Base](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ABase/markdown).

## LOG LEVELS
    [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown) supports the following log levels:

    If the logging mechanism used by your adapter supports different levels, it's your
    responsibility to map them appropriately when you implement the logging and detection methods
    described below. For example, if your mechanism only supports "debug", "normal" and "fatal"
    levels, you might map the levels like this:

## METHODS
### Constructor
    The constructor ("new") is provided by [Log::Any::Adapter::Base](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ABase/markdown). It will:

    At this point, overriding the default constructor is not supported. Hopefully it will not be
    needed.

    The constructor is called whenever a log object is requested. e.g. If the application
    initializes [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown) like so:

        [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown)->set_adapter('[Log::YAL](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AYAL/markdown)', yal_object => $yal, depth => 3);

    and then a class requests a logger like so:

        package Foo;
        use [Log::Any](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny/markdown) qw($log);

    Then $log will be populated with the return value of:

        [Log::Any::Adapter::Yal](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3AYal/markdown)->new(yal_object => $yal, depth => 3, category => 'Foo');

    This is memoized, so if the same category should be requested again (e.g. through a separate
    "get_logger" call, the same object will be returned. Therefore, you should try to avoid anything
    non-deterministic in your "init" function.

### Logging methods
    The following methods have no default implementation, and MUST be defined by your subclass,
    unless your adapter supports "Structured logging":

    These methods must log a message at the specified level.

    To help generate these methods programmatically, you can get a list of the sub names with the
    [Log::Any::Adapter::Util::logging_methods](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3AUtil%3A%3Aloggingmethods/markdown) function.

  Log-level detection methods (required)
    The following methods have no default implementation, and MUST be defined by your subclass:

    These methods must return a boolean indicating whether the specified level is active, i.e.
    whether the adapter is listening for messages of that level.

    To help generate these methods programmatically, you can get a list of the sub names with the
    [Log::Any::Adapter::Util::detection_methods](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3AUtil%3A%3Adetectionmethods/markdown) function.

### Structured logging
    Your adapter can choose to receive structured data instead of a string. In this case, instead of
    implementing all the "Logging methods", you define a single method called "structured". The
    method receives the log level, the category, and all arguments that were passed to the logging
    function, so be prepared to not only handle strings, but also hashrefs, arrayrefs, coderefs,
    etc.

### Aliases
    Aliases (e.g. "err" for "error") are handled by [Log::Any::Proxy](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AProxy/markdown) and will call the corresponding
    real name in your adapter class. You do not need to implement them in your adapter.

### Optional methods
    The following methods have no default implementation but MAY be provided by your subclass:

    init
        This is called after the adapter object is created and blessed into your class. Perform any
        necessary validation or initialization here. For example, you would use "init" to create a
        logging object for delegation, or open a file or socket, etc.

### Support methods
    The following [Log::Any::Adapter::Base](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ABase/markdown) method may be useful for defining adapters via delegation:

    delegate_method_to_slot ($slot, $method, $adapter_method)
        Handle the specified $method by calling $adapter_method on the object contained in
        "$self->{$slot}".

        See [Log::Any::Adapter::Dispatch](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ADispatch/markdown) and [Log::Any::Adapter::Log4perl](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3ALog4perl/markdown) for examples of usage.

    The following [Log::Any::Adapter::Util](https://www.chedong.com/phpMan.php/perldoc/Log%3A%3AAny%3A%3AAdapter%3A%3AUtil/markdown) functions give you a list of methods that you need to
    implement. You can get logging methods, detection methods or both:

## AUTHORS
    *   Jonathan Swartz <<swartz@pobox.com>>

    *   David Golden <<dagolden@cpan.org>>

    *   Doug Bell <<preaction@cpan.org>>

    *   Daniel Pittman <<daniel@rimspace.net>>

    *   Stephen Thirlwall <<sdt@cpan.org>>

## COPYRIGHT AND LICENSE
    This software is copyright (c) 2017 by Jonathan Swartz, David Golden, and Doug Bell.

    This is free software; you can redistribute it and/or modify it under the same terms as the Perl
    5 programming language system itself.

