def decorate_obj(parent, n, o, otype, recurse=True, redecorate=False):
global _decor_count, _decorated_o<EOL>from inspect import isclass, isfunction, ismodule<EOL>pmodule = parent if ismodule(parent) or isclass(parent) else None<EOL>fqdn = _fqdn(o, recheck=True, pmodule=pmodule)<EOL>if fqdn is None:<EOL><INDENT>return<EOL><DEDENT>package = fqdn.split('<STR_LIT:.>')[<NUM_LIT:0>]<EOL>d = _get_stack_depth(package, fqdn)<EOL>if (package in _decorated_o and<EOL>(id(o) not in _decorated_o[package] or redecorate)):<EOL><INDENT>decor = None<EOL>if hasattr(o, "<STR_LIT>") and otype != "<STR_LIT>":<EOL><INDENT>cdecor = CallingDecorator(o)<EOL>if isclass(parent):<EOL><INDENT>clog = cdecor(fqdn, package, parent, d)<EOL><DEDENT>else:<EOL><INDENT>clog = cdecor(fqdn, package, None, d)<EOL><DEDENT>msg.std("<STR_LIT>".format(fqdn), <NUM_LIT:4>)<EOL>_update_attrs(clog, o)<EOL>if ((hasattr(o, "<STR_LIT>") and o.im_self is parent)):<EOL><INDENT>clog = staticmethod(clog)<EOL><DEDENT>setok = _safe_setattr(parent, n, clog)<EOL>if setok:<EOL><INDENT>decor = cdecor<EOL>msg.okay("<STR_LIT>".format(n, fqdn), <NUM_LIT:3>)<EOL><DEDENT>_decor_count[package][<NUM_LIT:0>] += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>setok = _safe_setattr(o, "<STR_LIT>", None)<EOL>_decor_count[package][<NUM_LIT:2>] += <NUM_LIT:1><EOL><DEDENT>if otype == "<STR_LIT>" and setok:<EOL><INDENT>if hasattr(o, "<STR_LIT>"):<EOL><INDENT>setattr(o, "<STR_LIT>", staticmethod(o.__new__))<EOL>crelog = creationlog(o, package, d)<EOL>setok = _safe_setattr(o, "<STR_LIT>", creationlog(o, package, d))<EOL>if setok:<EOL><INDENT>decor = crelog<EOL>msg.gen("<STR_LIT>".format(n, fqdn),<NUM_LIT:3>)<EOL><DEDENT>_decor_count[package][<NUM_LIT:0>] += <NUM_LIT:1><EOL><DEDENT><DEDENT>if setok:<EOL><INDENT>_decorated_o[package][id(o)] = decor<EOL><DEDENT>else:<EOL><INDENT>_decorated_o[package][id(o)] = None<EOL><DEDENT>if setok and otype in ["<STR_LIT>", "<STR_LIT>"]:<EOL><INDENT>splits = _split_object(o, package)<EOL>for ot, ol in splits.items():<EOL><INDENT>for nobj, obj in ol:<EOL><INDENT>decorate_obj(o, nobj, obj, ot)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>elif otype != "<STR_LIT>" and package in _decorated_o:<EOL><INDENT>target = _decorated_o[package][id(o)]<EOL>child = getattr(parent, n)<EOL>if target is not None:<EOL><INDENT>clog = target(fqdn, package, parent)<EOL>_safe_setattr(clog, "<STR_LIT>", o)<EOL>_update_attrs(clog, o)<EOL>setok = _safe_setattr(parent, n, clog)<EOL>msg.okay("<STR_LIT>".format(n,fqdn), <NUM_LIT:4>)<EOL><DEDENT><DEDENT>
Adds the decoration for automated logging to the specified object, if it
    hasn't already been done.

    Args:
        parent: object that `o` belongs to.
        n (str): name in the parent's dictionary.
        o (type): instance of the object's type.
        otype (str): one of ['classes', 'functions', 'methods', 'modules'];
          specifies which group the object belongs to.
        recurse (bool): when True, the objects methods and functions are also
          decorated recursively.

    Examples:
        Decorate the function `mymod.myfunc` to log automatically to the
        database.

    >>> from acorn.logging.decoration import decorate_obj
    >>> import mymod
    >>> decorate_obj(mymod, "myfunc", mymod.myfunc, "functions")