112334Sgabeblack@google.com/*
212334Sgabeblack@google.com * Copyright (c) 2014, 2017 ARM Limited
312334Sgabeblack@google.com * All rights reserved
412334Sgabeblack@google.com *
512334Sgabeblack@google.com * The license below extends only to copyright in the software and shall
612334Sgabeblack@google.com * not be construed as granting a license to any other intellectual
712334Sgabeblack@google.com * property including but not limited to intellectual property relating
812334Sgabeblack@google.com * to a hardware implementation of the functionality of the software
912334Sgabeblack@google.com * licensed hereunder.  You may use the software subject to the license
1012334Sgabeblack@google.com * terms below provided that you ensure that this notice is replicated
1112334Sgabeblack@google.com * unmodified and in its entirety in all distributions of the software,
1212334Sgabeblack@google.com * modified or unmodified, in source code or in binary form.
1312334Sgabeblack@google.com *
1412334Sgabeblack@google.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
1512334Sgabeblack@google.com * All rights reserved.
1612334Sgabeblack@google.com *
1712334Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
1812334Sgabeblack@google.com * modification, are permitted provided that the following conditions are
1912334Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
2012334Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
2112334Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
2212334Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
2312334Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
2412334Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
2512334Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
2612334Sgabeblack@google.com * this software without specific prior written permission.
2712334Sgabeblack@google.com *
2812334Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2912334Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3012334Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3112334Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3212334Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3312334Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3412334Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3512334Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3612334Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3712334Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3812334Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3912334Sgabeblack@google.com *
4012334Sgabeblack@google.com * Authors: Nathan Binkert
4112334Sgabeblack@google.com *          Andreas Sandberg
4212334Sgabeblack@google.com */
4312334Sgabeblack@google.com
4412334Sgabeblack@google.com#include "base/logging.hh"
4512334Sgabeblack@google.com
4612375Sgabeblack@google.com#include <sstream>
4712334Sgabeblack@google.com
4812334Sgabeblack@google.com#include "base/hostinfo.hh"
4912334Sgabeblack@google.com
5012375Sgabeblack@google.comnamespace {
5112334Sgabeblack@google.com
5212375Sgabeblack@google.comclass NormalLogger : public Logger
5312334Sgabeblack@google.com{
5412334Sgabeblack@google.com  public:
5512334Sgabeblack@google.com    using Logger::Logger;
5612334Sgabeblack@google.com
5712375Sgabeblack@google.com  protected:
5812375Sgabeblack@google.com    void log(const Loc &loc, std::string s) override { std::cerr << s; }
5912334Sgabeblack@google.com};
6012334Sgabeblack@google.com
6112375Sgabeblack@google.comclass ExitLogger : public NormalLogger
6212334Sgabeblack@google.com{
6312375Sgabeblack@google.com  public:
6412375Sgabeblack@google.com    using NormalLogger::NormalLogger;
6512334Sgabeblack@google.com
6612375Sgabeblack@google.com  protected:
6712375Sgabeblack@google.com    void
6812375Sgabeblack@google.com    log(const Loc &loc, std::string s) override
6912375Sgabeblack@google.com    {
7012375Sgabeblack@google.com        std::stringstream ss;
7112375Sgabeblack@google.com        ccprintf(ss, "Memory Usage: %ld KBytes\n", memUsage());
7212375Sgabeblack@google.com        NormalLogger::log(loc, s + ss.str());
7312375Sgabeblack@google.com    }
7412375Sgabeblack@google.com};
7512334Sgabeblack@google.com
7612375Sgabeblack@google.comclass FatalLogger : public ExitLogger
7712334Sgabeblack@google.com{
7812375Sgabeblack@google.com  public:
7912375Sgabeblack@google.com    using ExitLogger::ExitLogger;
8012334Sgabeblack@google.com
8112375Sgabeblack@google.com  protected:
8212375Sgabeblack@google.com    void exit() override { ::exit(1); }
8312375Sgabeblack@google.com};
8412375Sgabeblack@google.com
8512375Sgabeblack@google.comExitLogger panicLogger("panic: ");
8612375Sgabeblack@google.comFatalLogger fatalLogger("fatal: ");
8712375Sgabeblack@google.comNormalLogger warnLogger("warn: ");
8812375Sgabeblack@google.comNormalLogger infoLogger("info: ");
8912375Sgabeblack@google.comNormalLogger hackLogger("hack: ");
9012375Sgabeblack@google.com
9112375Sgabeblack@google.com} // anonymous namespace
9212375Sgabeblack@google.com
9312375Sgabeblack@google.comLogger &Logger::getPanic() { return panicLogger; }
9412375Sgabeblack@google.comLogger &Logger::getFatal() { return fatalLogger; }
9512375Sgabeblack@google.comLogger &Logger::getWarn() { return warnLogger; }
9612375Sgabeblack@google.comLogger &Logger::getInfo() { return infoLogger; }
9712375Sgabeblack@google.comLogger &Logger::getHack() { return hackLogger; }
98