Code Monkey home page Code Monkey logo

Comments (4)

Cj-bc avatar Cj-bc commented on May 8, 2024

Hello, @nicutor
Based on my codereading, I think what you have to do is just to redirect stderr to file you want.
so,

$ ./your-script.sh 2>log-file.txt

Because all log methods(defined in lib/util/logs.sh) seems to cat all messages to stderr

my test success(test.sh is example code at README.md, Using Basic Logging, Colors and Powerline Emoji):

<X_X>:bash-oo-framework$ ./test.sh
I'm blue...
[DEBUG] [test.sh:19] Play me some Jazz, will ya? 🎷
Something bad happened.
This will be printed to STDERR, no matter what.
0is0[feature/japanese-docs]
<X_X>:bash-oo-framework$ ./test.sh 2>log.txt
I'm blue...
0is0[feature/japanese-docs]
<X_X>:bash-oo-framework$ cat log.txt
[DEBUG] [test.sh:19] Play me some Jazz, will ya? 🎷
Something bad happened.
This will be printed to STDERR, no matter what.

++ I'm not a member of maintainer, not good at this framework, so this might be wrong.
Please remember this is just my opinion...

I'm happy if this helps you.

from bash-oo-framework.

nicutor avatar nicutor commented on May 8, 2024

@Cj-bc Thank you for your help, but I am trying to avoid that way.

Based on documentation, I've already find a way, but, if there is any better example of how to log to file, syslog or email, please let me know.

#!/usr/bin/env bash
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"

import util/log

namespace myApp
myLoggingDelegate() {
    echo "$(date +'%F %T %Z') [${subject}]: $*"
    echo "$(date +'%F %T %Z') [${subject}]: $*" >> test.log
}
Log::RegisterLogger MYLOGGER myLoggingDelegate
Log::AddOutput myApp MYLOGGER

subject="WARNING" Log "Something"

from bash-oo-framework.

Cj-bc avatar Cj-bc commented on May 8, 2024

@nicutor oh, I see.
I think the way you showed(declaring Logger) is only the way to do that.
If I find any solution, I'll let you know.

from bash-oo-framework.

niieani avatar niieani commented on May 8, 2024

@nicutor's answer is correct. In the current version logging is a bit over-engineered. I'd like to simplify it in the next version that we're brainstorming in #45, feel free to join.

from bash-oo-framework.

Related Issues (20)

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.